diff --git a/.gitignore b/.gitignore index e80e6f6fe5f..3805eecc234 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,10 @@ kuttl-test.json *.swo *~ +# Generated file-based catalog artifacts +catalog/ +catalog.Dockerfile + # ignore vendor vendor/ .vscode/ diff --git a/Containerfile.plugin b/Containerfile.plugin index 70fecc1d2b6..e6221fee42f 100644 --- a/Containerfile.plugin +++ b/Containerfile.plugin @@ -19,7 +19,7 @@ FROM registry.redhat.io/rhel8/go-toolset:1.22.7-5.1731464728 AS builder ENV LANG=en_US.utf8 ENV GIT_COMMITTER_NAME devtools ENV GIT_COMMITTER_EMAIL devtools@redhat.com -LABEL com.redhat.delivery.appregistry=true +LABEL com.redhat.delivery.appregistry=false WORKDIR /gitops-operator diff --git a/Makefile b/Makefile index fb09513d378..3364a525e17 100644 --- a/Makefile +++ b/Makefile @@ -267,15 +267,17 @@ rm -rf $$TMP_DIR ;\ endef .PHONY: bundle -bundle: operator-sdk manifests kustomize ## Generate bundle manifests and metadata, then validate generated files. +bundle: operator-sdk opm manifests kustomize ## Generate bundle manifests and metadata, then validate generated files. $(OPERATOR_SDK) generate kustomize manifests -q cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) $(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS) $(OPERATOR_SDK) bundle validate ./bundle + $(OPM) render ./bundle -o yaml | grep -E 'schema: olm.bundle' # Fail if using v0 format .PHONY: bundle-build bundle-build: ## Build the bundle image. $(CONTAINER_RUNTIME) build -f bundle.Dockerfile -t $(BUNDLE_IMG) . + $(CONTAINER_RUNTIME) image inspect $(BUNDLE_IMG) --format '{{json .Config.Labels}}' | grep '"operators.operatorframework.io.bundle.mediatype.v1":"registry+v1"' # Fail if using v0 format .PHONY: bundle-push bundle-push: ## Push the bundle image. @@ -300,7 +302,7 @@ ifeq (,$(shell which opm 2>/dev/null)) set -e ;\ mkdir -p $(dir $(OPM)) ;\ OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \ - curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\ + curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.72.0/$${OS}-$${ARCH}-opm ;\ chmod +x $(OPM) ;\ } else @@ -309,31 +311,45 @@ endif endif -# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0). -# These images MUST exist in a registry and be pull-able. -BUNDLE_IMGS ?= $(BUNDLE_IMG) - # The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0). CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION) -# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image. -ifneq ($(origin CATALOG_BASE_IMG), undefined) -FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG) -endif +# File-based catalog (FBC) output directory. Dockerfile is generated beside it as $(CATALOG_DIR).Dockerfile. +CATALOG_DIR = catalog -# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'. -# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see: -# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator +# Build a file-based catalog image from the local registry+v1 bundle (./bundle). +# BUNDLE_IMG is stamped into the olm.bundle entry so OLM can pull the published bundle. .PHONY: catalog-build -catalog-build: opm ## Build a catalog image. - $(OPM) index add --container-tool $(shell basename $(CONTAINER_RUNTIME)) --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) +catalog-build: opm bundle ## Build a file-based catalog image. + rm -rf $(CATALOG_DIR) $(CATALOG_DIR).Dockerfile + mkdir -p $(CATALOG_DIR) + $(OPM) init gitops-operator --default-channel=$(shell echo $(DEFAULT_CHANNEL) | tr -d '"') -o yaml > $(CATALOG_DIR)/index.yaml + $(OPM) render ./bundle -o yaml --alpha-image-ref-template '$(BUNDLE_IMG)' --migrate-level=bundle-object-to-csv-metadata >> $(CATALOG_DIR)/index.yaml + @bundle_name="gitops-operator.v$(VERSION)"; \ + for ch in $$(echo $(CHANNELS) | tr -d '"' | tr ',' ' '); do \ + printf '%s\n' '---' 'schema: olm.channel' "package: gitops-operator" "name: $${ch}" 'entries:' " - name: $${bundle_name}" >> $(CATALOG_DIR)/index.yaml; \ + done + $(OPM) validate $(CATALOG_DIR) + $(OPM) generate dockerfile $(CATALOG_DIR) + $(CONTAINER_RUNTIME) build -f $(CATALOG_DIR).Dockerfile -t $(CATALOG_IMG) . + + # Validate that the catalog image is using the v1 format + @grep -q 'type: olm.csv.metadata' $(CATALOG_DIR)/index.yaml # Fail if using v0 format + @! grep -q 'type: olm.bundle.object' $(CATALOG_DIR)/index.yaml # Fail if using v0 format + @cid=$$($(CONTAINER_RUNTIME) create $(CATALOG_IMG)); \ + if $(CONTAINER_RUNTIME) cp $$cid:/database/index.db /tmp/gitops-catalog-index.db 2>/dev/null; then \ + $(CONTAINER_RUNTIME) rm $$cid >/dev/null; rm -f /tmp/gitops-catalog-index.db; \ + echo "ERROR: $(CATALOG_IMG) uses SQLite index.db (deprecated/v0 catalog format)"; \ + exit 1; \ + fi; \ + $(CONTAINER_RUNTIME) rm $$cid >/dev/null + $(OPM) render $(CATALOG_DIR) -o yaml | grep -E 'schema: olm\.(package|channel|bundle)' # Fail if using v0 format # Push the catalog image. .PHONY: catalog-push catalog-push: ## Push a catalog image. $(MAKE) docker-push IMG=$(CATALOG_IMG) - .PHONY: gosec gosec: go_sec $(GO_SEC) --exclude-dir "hack/upgrade-rollouts-manager" ./... diff --git a/bundle/bundle.Dockerfile b/bundle/bundle.Dockerfile index ad5b28cb1d0..c973eff2b58 100644 --- a/bundle/bundle.Dockerfile +++ b/bundle/bundle.Dockerfile @@ -1,24 +1,24 @@ +# TODO: Remove this and use the bundle.Dockerfile in the root of the project. +# To be dropped after the openshift-ci have started reding the other one. + FROM scratch +# Core bundle labels. LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ -LABEL operators.operatorframework.io.bundle.package.v1=openshift-gitops-operator -LABEL operators.operatorframework.io.bundle.channels.v1=latest +LABEL operators.operatorframework.io.bundle.package.v1=gitops-operator +LABEL operators.operatorframework.io.bundle.channels.v1=latest,gitops-1.8 LABEL operators.operatorframework.io.bundle.channel.default.v1=latest +LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.35.0 +LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1 +LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v4 -COPY manifests /manifests/ -COPY metadata/annotations.yaml /metadata/annotations.yaml +# Labels for testing. +LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1 +LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/ -# These are three labels needed to control how the pipeline should handle this container image -# This first label tells the pipeline that this is a bundle image and should be -# delivered via an index image -LABEL com.redhat.delivery.operator.bundle=true -# This second label tells the pipeline which versions of OpenShift the operator supports. -# This is used to control which index images should include this operator. -LABEL com.redhat.openshift.versions="v4.8" -# This third label tells the pipeline that this operator should *also* be supported on OCP 4.4 and -# earlier. It is used to control whether or not the pipeline should attempt to automatically -# backport this content into the old appregistry format and upload it to the quay.io application -# registry endpoints. -LABEL com.redhat.delivery.backport=true \ No newline at end of file +# Copy files to locations specified by labels. +COPY manifests /manifests/ +COPY metadata /metadata/ +COPY tests/scorecard /tests/scorecard/