From 534d95045bd03686b8af5dcdbdd9295188671ed0 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Fri, 4 Aug 2023 15:55:58 -0400 Subject: [PATCH] Support disconnected network environments This PR adds support for installing the operator in disconnected network environments. To build with image-digests set USE_IMAGE_DIGESTS=true before running make bundle. For Prow jobs we are enabling this via .prow-ci.env This drops the old logic from create_bundle.sh which has been broken with operator-sdk's make bundle for some time. (NOTE: this currently requires a secure registry) --- .github/create_bundle.sh | 52 +------------------ .prow_ci.env | 1 + api/v1beta1/common.go | 2 +- config/default/manager_default_images.yaml | 2 +- ...glance-operator.clusterserviceversion.yaml | 1 + tests/functional/glance_controller_test.go | 4 +- 6 files changed, 7 insertions(+), 55 deletions(-) create mode 100644 .prow_ci.env diff --git a/.github/create_bundle.sh b/.github/create_bundle.sh index 79c1cee6..84e112cf 100755 --- a/.github/create_bundle.sh +++ b/.github/create_bundle.sh @@ -1,63 +1,13 @@ #!/bin/bash set -e -CLUSTER_BUNDLE_FILE="bundle/manifests/glance-operator.clusterserviceversion.yaml" - echo "Creating glance operator bundle" cd .. echo "${GITHUB_SHA}" echo "${BASE_IMAGE}" -skopeo --version - -echo "Calculating image digest for docker://${REGISTRY}/${BASE_IMAGE}:${GITHUB_SHA}" -DIGEST=$(skopeo inspect docker://${REGISTRY}/${BASE_IMAGE}:${GITHUB_SHA} | jq '.Digest' -r) -# Output: -# Calculating image digest for docker://quay.io/openstack-k8s-operators/glance-operator:d03f2c1c362c04fc5ef819f92a218f9ea59bbd0c -# Digest: sha256:1d5b578fd212f8dbd03c0235f1913ef738721766f8c94236af5efecc6d8d8cb1 -echo "Digest: ${DIGEST}" RELEASE_VERSION=$(grep "^VERSION" Makefile | awk -F'?= ' '{ print $2 }') -OPERATOR_IMG_WITH_DIGEST="${REGISTRY}/${BASE_IMAGE}@${DIGEST}" - -echo "New Operator Image with Digest: $OPERATOR_IMG_WITH_DIGEST" echo "Release Version: $RELEASE_VERSION" echo "Creating bundle image..." -VERSION=$RELEASE_VERSION IMG=$OPERATOR_IMG_WITH_DIGEST make bundle - -echo "Bundle file images:" -cat "${CLUSTER_BUNDLE_FILE}" | grep "image:" -# FIXME: display any ENV variables once we have offline support implemented -#grep -A1 IMAGE_URL_DEFAULT "${CLUSTER_BUNDLE_FILE}" - -# We do not want to exit here. Some images are in different registries, so -# error will be reported to the console. -set +e -for csv_image in $(cat "${CLUSTER_BUNDLE_FILE}" | grep "image:" | sed -e "s|.*image:||" | sort -u); do - digest_image="" - echo "CSV line: ${csv_image}" - - # case where @ is in the csv_image image - if [[ "$csv_image" =~ .*"@".* ]]; then - delimeter='@' - else - delimeter=':' - fi - - base_image=$(echo $csv_image | cut -f 1 -d${delimeter}) - tag_image=$(echo $csv_image | cut -f 2 -d${delimeter}) - digest_image=$(skopeo inspect docker://${base_image}${delimeter}${tag_image} | jq '.Digest' -r) - echo "Base image: $base_image" - if [ -n "$digest_image" ]; then - echo "$base_image${delimeter}$tag_image becomes $base_image@$digest_image" - sed -i "s|$base_image$delimeter$tag_image|$base_image@$digest_image|g" "${CLUSTER_BUNDLE_FILE}" - else - echo "$base_image${delimeter}$tag_image not changed" - fi -done - -echo "Resulting bundle file images:" -cat "${CLUSTER_BUNDLE_FILE}" | grep "image:" - -# FIXME: display any ENV variables once we have offline support implemented -#grep -A1 IMAGE_URL_DEFAULT "${CLUSTER_BUNDLE_FILE}" +USE_IMAGE_DIGESTS=true VERSION=$RELEASE_VERSION IMG=${REGISTRY}/${BASE_IMAGE}:${GITHUB_SHA} make bundle diff --git a/.prow_ci.env b/.prow_ci.env new file mode 100644 index 00000000..2606e6b6 --- /dev/null +++ b/.prow_ci.env @@ -0,0 +1 @@ +export USE_IMAGE_DIGESTS=true diff --git a/api/v1beta1/common.go b/api/v1beta1/common.go index 121a69f6..7a8a4c54 100644 --- a/api/v1beta1/common.go +++ b/api/v1beta1/common.go @@ -129,7 +129,7 @@ type MetalLBConfig struct { func SetupDefaults() { // Acquire environmental defaults and initialize Glance defaults with them glanceDefaults := GlanceDefaults{ - ContainerImageURL: util.GetEnvVar("GLANCE_API_IMAGE_URL_DEFAULT", GlanceAPIContainerImage), + ContainerImageURL: util.GetEnvVar("RELATED_IMAGE_GLANCE_API_IMAGE_URL_DEFAULT", GlanceAPIContainerImage), } SetupGlanceDefaults(glanceDefaults) diff --git a/config/default/manager_default_images.yaml b/config/default/manager_default_images.yaml index 65811413..c9acad77 100644 --- a/config/default/manager_default_images.yaml +++ b/config/default/manager_default_images.yaml @@ -11,5 +11,5 @@ spec: containers: - name: manager env: - - name: GLANCE_API_IMAGE_URL_DEFAULT + - name: RELATED_IMAGE_GLANCE_API_IMAGE_URL_DEFAULT value: quay.io/podified-antelope-centos9/openstack-glance-api:current-podified diff --git a/config/manifests/bases/glance-operator.clusterserviceversion.yaml b/config/manifests/bases/glance-operator.clusterserviceversion.yaml index c56d2512..27add993 100644 --- a/config/manifests/bases/glance-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/glance-operator.clusterserviceversion.yaml @@ -4,6 +4,7 @@ metadata: annotations: alm-examples: '[]' capabilities: Basic Install + operators.openshift.io/infrastructure-features: '["disconnected"]' operators.operatorframework.io/operator-type: non-standalone name: glance-operator.v0.0.0 namespace: placeholder diff --git a/tests/functional/glance_controller_test.go b/tests/functional/glance_controller_test.go index a3c0c5e3..fa7733fd 100644 --- a/tests/functional/glance_controller_test.go +++ b/tests/functional/glance_controller_test.go @@ -221,8 +221,8 @@ var _ = Describe("Glance controller", func() { }) It("has the expected container image defaults", func() { glanceDefault := GetGlance(glanceTest.Instance) - Expect(glanceDefault.Spec.GlanceAPIInternal.ContainerImage).To(Equal(util.GetEnvVar("GLANCE_API_IMAGE_URL_DEFAULT", glancev1.GlanceAPIContainerImage))) - Expect(glanceDefault.Spec.GlanceAPIInternal.ContainerImage).To(Equal(util.GetEnvVar("GLANCE_API_IMAGE_URL_DEFAULT", glancev1.GlanceAPIContainerImage))) + Expect(glanceDefault.Spec.GlanceAPIInternal.ContainerImage).To(Equal(util.GetEnvVar("RELATED_IMAGE_GLANCE_API_IMAGE_URL_DEFAULT", glancev1.GlanceAPIContainerImage))) + Expect(glanceDefault.Spec.GlanceAPIInternal.ContainerImage).To(Equal(util.GetEnvVar("RELATED_IMAGE_GLANCE_API_IMAGE_URL_DEFAULT", glancev1.GlanceAPIContainerImage))) }) }) When("All the Resources are ready", func() {