From afecff02722e48bb6e30116a00d2b6a5d0389de6 Mon Sep 17 00:00:00 2001 From: Joe McCormick <31295332+iamjoemccormick@users.noreply.github.com> Date: Thu, 29 Feb 2024 18:34:48 +0000 Subject: [PATCH] Add version annotation for OpenShift --- operator/Makefile | 17 +++++++++++++++++ operator/bundle.Dockerfile | 3 +++ operator/bundle/metadata/annotations.yaml | 3 +++ operator/hack/set_openshift_min_version.sh | 12 ++++++++++++ 4 files changed, 35 insertions(+) create mode 100755 operator/hack/set_openshift_min_version.sh diff --git a/operator/Makefile b/operator/Makefile index d940e509..16fce52b 100644 --- a/operator/Makefile +++ b/operator/Makefile @@ -203,6 +203,23 @@ bundle: manifests kustomize ## Generate bundle manifests and metadata, then vali operator-sdk generate kustomize manifests --interactive=false -q cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS) + # OpenShift started requiring bundles to specify what versions of OpenShift are supported and + # the fact we did not specify this was caught when submitting the bundle for v1.6.0. Since + # v1.5.0 we don't officially test or support OpenShift anymore, but we still publish bundles as + # a convenience for anyone using OpenShift that wants to run the operator "at their own risk" + # because there is no technical reason it shouldn't work. Here we just require a minimum of + # v4.11 as that was the last version of OpenShift tested with the driver. + # https://redhat-connect.gitbook.io/certified-operator-guide/ocp-deployment/operator-metadata/bundle-directory/managing-openshift-versions + # https://connect.redhat.com/en/blog/updating-your-operators-openshift-when-kubernetes-changes-apis + # + # Further complicating matters, our bundle is generated by operator-sdk so we cannot simply + # modify bundle/metadata/annotations.yaml and bundle.Dockerfile as they will be overwritten. + # Thus far I have not found any documentation on the "correct" way to tell operator-sdk to add + # this. Searching GitHub for how other have solved this shows projects either appear to not be + # maintaining bundles using operator-sdk, or are using some varient of a hack script to set the + # versions after generating the bundle. Our solution is "inspired" by: + # https://github.com/open-telemetry/opentelemetry-operator/pull/2562/files. + ./hack/set_openshift_min_version.sh operator-sdk bundle validate ./bundle --select-optional suite=operatorframework .PHONY: bundle-build diff --git a/operator/bundle.Dockerfile b/operator/bundle.Dockerfile index 3d002933..522efcd7 100644 --- a/operator/bundle.Dockerfile +++ b/operator/bundle.Dockerfile @@ -19,3 +19,6 @@ LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/ COPY bundle/manifests /manifests/ COPY bundle/metadata /metadata/ COPY bundle/tests/scorecard /tests/scorecard/ + +# Set minimum OpenShift version +LABEL com.redhat.openshift.versions="v4.11" diff --git a/operator/bundle/metadata/annotations.yaml b/operator/bundle/metadata/annotations.yaml index 0cd4498e..413e38d5 100644 --- a/operator/bundle/metadata/annotations.yaml +++ b/operator/bundle/metadata/annotations.yaml @@ -13,3 +13,6 @@ annotations: # Annotations for testing. operators.operatorframework.io.test.mediatype.v1: scorecard+v1 operators.operatorframework.io.test.config.v1: tests/scorecard/ + + # Set minimum OpenShift version + com.redhat.openshift.versions: "v4.11" diff --git a/operator/hack/set_openshift_min_version.sh b/operator/hack/set_openshift_min_version.sh new file mode 100755 index 00000000..137ca051 --- /dev/null +++ b/operator/hack/set_openshift_min_version.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +OPENSHIFT_VERSIONS="\"v4.11\"" + +{ + echo "" + echo " # Set minimum OpenShift version" + echo " com.redhat.openshift.versions: $OPENSHIFT_VERSIONS" +} >> bundle/metadata/annotations.yaml + +echo "\n# Set minimum OpenShift version" >> bundle.Dockerfile +echo "LABEL com.redhat.openshift.versions=$OPENSHIFT_VERSIONS" >> bundle.Dockerfile \ No newline at end of file