diff --git a/.github/actions/make-bundle/action.yml b/.github/actions/make-bundle/action.yml index e987a142..f3647f45 100644 --- a/.github/actions/make-bundle/action.yml +++ b/.github/actions/make-bundle/action.yml @@ -41,25 +41,36 @@ inputs: description: "image uri for analyzer addon (ie. quay.io//:)" required: false default: "" + version: + description: "operator version" + required: false + default: "" + channels: + description: "comma separated channel(s) this operator should be available on" + required: false + default: "" runs: using: "composite" steps: - # TODO(djzager): Need to figure out overriding operator image - # or maybe just installing manager via kustomize. - name: Make bundle + env: + CHANNELS: ${{ inputs.channels }} + BUNDLE_IMAGE: ${{ inputs.operator_bundle }} + VERSION: ${{ inputs.version }} run: | + [ -n "${VERSION}" ] && export VERSION="${VERSION:1}" OPTS="" [ -n "${{ inputs.operator }}" ] && OPTS+=" --set images.operator=${{ inputs.operator }}" [ -n "${{ inputs.oauth_proxy }}" ] && OPTS+=" --set images.oauth_proxy=${{ inputs.oauth_proxy }}" [ -n "${{ inputs.tackle_hub }}" ] && OPTS+=" --set images.tackle_hub=${{ inputs.tackle_hub }}" [ -n "${{ inputs.tackle_postgres }}" ] && OPTS+=" --set images.tackle_postgres=${{ inputs.tackle_postgres }}" - [ -n "${{ inputs.keycloack_sso }}" ] && OPTS+=" --set images.keycloack_sso=${{ inputs.keycloack_sso }}" - [ -n "${{ inputs.keycloack_init }}" ] && OPTS+=" --set images.keycloack_init=${{ inputs.keycloack_init }}" + [ -n "${{ inputs.keycloak_sso }}" ] && OPTS+=" --set images.keycloak_sso=${{ inputs.keycloak_sso }}" + [ -n "${{ inputs.keycloak_init }}" ] && OPTS+=" --set images.keycloak_init=${{ inputs.keycloak_init }}" [ -n "${{ inputs.tackle_ui }}" ] && OPTS+=" --set images.tackle_ui=${{ inputs.tackle_ui }}" [ -n "${{ inputs.addon_admin }}" ] && OPTS+=" --set images.addon_admin=${{ inputs.addon_admin }}" [ -n "${{ inputs.addon_analyzer }}" ] && OPTS+=" --set images.addon_analyzer=${{ inputs.addon_analyzer }}" HELM_TEMPLATE_OPTS="${OPTS}" make bundle cat ./bundle/manifests/konveyor-operator.clusterserviceversion.yaml - BUNDLE_IMG="${{ inputs.operator_bundle }}" make bundle-build + make bundle-build working-directory: ${{ github.action_path }}/../../.. shell: bash diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index bed59032..445d6878 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -6,34 +6,18 @@ on: version: description: 'The semantic version of the release (e.g. v1.2.3)' required: true - previous_version: - description: 'The semantic version of the previous release (e.g. v1.2.2)' - required: false - type: string branch: description: 'The branch to create the release from (defaults to main)' required: false default: 'main' - operator_channel: - description: 'Channel to publish the new operator to' - required: true - type: string - github_name: - description: 'Your full name' - required: true - type: string - github_email: - description: 'Your e-mail address' + operator_channels: + description: | + Channel(s), comma separated, to which this operator version belongs. + First in list is assumed default channel. required: true type: string jobs: - # TODO(djzager): This is where we would want to do some integration testing - # test: - # ... - # might consider creating "rc" releases, building and testing those before - # publishing a release. - release-bases: runs-on: ubuntu-20.04 strategy: @@ -131,27 +115,197 @@ jobs: done docker image inspect quay.io/${{ matrix.projects.image }}:${{ inputs.version }} + test: + name: Test Konveyor + needs: release-components + uses: konveyor/ci/.github/workflows/global-ci-bundle.yml@main + with: + operator: quay.io/konveyor/tackle2-operator:${{ inputs.version }} + tackle_hub: quay.io/konveyor/tackle2-hub:${{ inputs.version }} + keycloack_init: quay.io/konveyor/tackle-keycloak-init:${{ inputs.version }} + tackle_ui: quay.io/konveyor/tackle2-ui:${{ inputs.version }} + addon_admin: quay.io/konveyor/tackle2-addon:${{ inputs.version }} + addon_analyzer: quay.io/konveyor/tackle2-addon-analyzer:${{ inputs.version }} + publish: name: Build and Push Manifest - needs: release-components + needs: test runs-on: ubuntu-20.04 strategy: fail-fast: false steps: - name: Checkout Push to Registry action - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: + path: operator ref: ${{ inputs.branch }} - - name: Run migrations - run: bash ./tools/konveyor-operator-publish-commands.sh - env: - GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} - GITHUB_USER: ${{ secrets.GH_USER }} - QUAY_ROBOT: ${{ secrets.QUAY_PUBLISH_ROBOT }} - QUAY_TOKEN: ${{ secrets.QUAY_PUBLISH_TOKEN }} - OPERATOR_SEMVER: ${{ inputs.version }} - OPERATOR_CHANNEL: ${{ inputs.operator_channel }} - PREV_OPERATOR_SEMVER: ${{ inputs.previous_version }} - GITHUB_NAME: ${{ inputs.github_name }} - GITHUB_EMAIL: ${{ inputs.github_email }} + - name: Mirror non-konveyor images + working-directory: ./operator + run: | + make yq openshift-client + + IMAGE_ORG="quay.io/konveyor" + VERSION="${{ inputs.version }}" + CSV="./bundle/manifests/konveyor-operator.clusterserviceversion.yaml" + + for full_image in $(yq eval '.spec.relatedImages[] | .image' "${CSV}"); do + image="${full_image%:*}" + full_image_name="${image#*/}" + image_name="${full_image_name#*/}" + mirror_image_name="${IMAGE_ORG}/${image_name}:${VERSION}" + + if ! [[ "${full_image}" =~ "${IMAGE_ORG}"/.* ]]; then + set -x + oc image mirror "${full_image}" "${mirror_image_name}" || { + echo "ERROR unable to mirror image" + exit 1 + } + fi + done + + - name: Build bundle + uses: ./operator/.github/actions/make-bundle + with: + operator_bundle: ttl.sh/konveyor-operator-bundle-${github.sha}:3h + operator: quay.io/konveyor/tackle2-operator:${{ inputs.version }} + tackle_hub: quay.io/konveyor/tackle2-hub:${{ inputs.version }} + keycloak_init: quay.io/konveyor/tackle-keycloak-init:${{ inputs.version }} + tackle_ui: quay.io/konveyor/tackle2-ui:${{ inputs.version }} + addon_admin: quay.io/konveyor/tackle2-addon:${{ inputs.version }} + addon_analyzer: quay.io/konveyor/tackle2-addon-analyzer:${{ inputs.version }} + # The ones we don't own + oauth_proxy: quay.io/konveyor/origin-oauth-proxy:${{ inputs.version }} + tackle_postgres: quay.io/konveyor/postgresql-12-centos7:${{ inputs.version }} + keycloak_sso: quay.io/konveyor/keycloak:${{ inputs.version }} + # Bundle specific args + version: ${{ inputs.version }} + channels: ${{ inputs.operator_channel }} + use_image_digest: "true" + + - name: Replace with digest + working-directory: ./operator + run: | + CSV="./bundle/manifests/konveyor-operator.clusterserviceversion.yaml" + + # Handle operator image + operator_full_image=$(yq eval '.metadata.annotations.containerImage' "${CSV}") + operator_image="${operator_full_image%:*}" + podman pull "${operator_full_image}" + operator_image_sha=$(podman inspect "${operator_full_image}" --format '{{ .Digest }}') + sed -i "s,${operator_full_image},${operator_image}@${operator_image_sha},g" "${CSV}" + + # Handle related images + for full_image in $(yq eval '.spec.relatedImages[] | .image' "${CSV}"); do + image="${full_image%:*}" + + podman pull "${full_image}" + image_sha=$(podman inspect "${full_image}" --format '{{ .Digest }}') + + sed -i "s,${full_image},${image}@${image_sha},g" "${CSV}" + done + + - name: Update bundle annotations + working-directory: ./operator + run: | + ANNOTATIONS="./bundle/metadata/annotations.yaml" + + yq eval --inplace 'del(.annotations["operators.operatorframework.io.test.mediatype.v1"])' ${ANNOTATIONS} + yq eval --inplace 'del(.annotations["operators.operatorframework.io.test.config.v1"])' ${ANNOTATIONS} + yq eval --inplace '.annotations["com.redhat.openshift.versions"] = "v4.9" | .annotations["com.redhat.openshift.versions"] style="double"' ${ANNOTATIONS} + + - name: Checkout community operators + uses: actions/checkout@v4 + with: + repository: k8s-operatorhub/community-operators + path: community-operators + ref: main + fetch-depth: 0 + + - name: Update community operators + working-directory: ./community-operators + run: | + version="${{ inputs.version }}" + co_version="${version:1}" + operator_path="./operators/konveyor-operator/${co_version}" + mkdir -p "${operator_path}" + cp -r "${GITHUB_WORKSPACE}/operator/bundle/metadata" "${GITHUB_WORKSPACE}/operator/bundle/manifests" "${operator_path}" + git diff + + - name: Checkout redhat community operators + uses: actions/checkout@v4 + with: + repository: redhat-openshift-ecosystem/community-operators-prod + path: redhat-community-operators + ref: main + fetch-depth: 0 + + - name: Update redhat community operators + working-directory: ./redhat-community-operators + run: | + version="${{ inputs.version }}" + co_version="${version:1}" + operator_path="./operators/konveyor-operator/${co_version}" + mkdir -p "${operator_path}" + cp -r "${GITHUB_WORKSPACE}/operator/bundle/metadata" "${GITHUB_WORKSPACE}/operator/bundle/manifests" "${operator_path}" + git diff + + - name: Make unified changelog + run: | + repositories=( + "konveyor/tackle2-ui" + "konveyor/tackle2-hub" + "konveyor/analyzer-lsp" + "konveyor/java-analyzer-bundle" + "konveyor/windup-shim" + "konveyor/tackle2-addon-analyzer" + "konveyor/tackle2-addon" + "konveyor/operator" + ) + + echo "Konveyor Operator ${{ inputs.version }}" > changelog.md + echo "=======================================" > changelog.md + echo "" >> changelog.md + + for repo in "${repositories[@]}"; do + echo "# ${repo}" + echo "" >> changelog.md + gh release view "${{ inputs.version }}" --repo "${repo}" --json body --jq .body >> changelog.md + echo "" >> changelog.md + done + + + - name: Create Pull Request - Community Operators + uses: peter-evans/create-pull-request@v5 + id: co-cpr + with: + token: ${{ secrets.GH_TOKEN }} + path: ./community-operators + commit-message: "konveyor-operator-${{ inputs.version }}" + committer: "${{ secrets.GH_USER }} " + author: "${{ secrets.GH_USER }} <${{ secrets.GH_USER }}@users.noreply.github.com>" + signoff: true + branch: ${{ inputs.version }} + push-to-fork: konveyor-release-bot/community-operators + title: "konveyor-operator-${{ inputs.version }}" + body-path: ./changelog.md + + - name: Create Pull Request - Red Hat Community Operators + uses: peter-evans/create-pull-request@v5 + id: rhco-cpr + with: + token: ${{ secrets.GH_TOKEN }} + path: ./redhat-community-operators + commit-message: "konveyor-operator-${{ inputs.version }}" + committer: "${{ secrets.GH_USER }} " + author: "${{ secrets.GH_USER }} <${{ secrets.GH_USER }}@users.noreply.github.com>" + signoff: true + branch: ${{ inputs.version }} + push-to-fork: konveyor-release-bot/community-operators-prod + title: "konveyor-operator-${{ inputs.version }}" + body-path: ./changelog.md + + - name: PR Notifications + run: | + echo "::notice:: Community Operators Pull Request URL - ${{ steps.co-cpr.outputs.pull-request-url }}" + echo "::notice:: Red Hat Community Operators Pull Request URL - ${{ steps.rhco-cpr.outputs.pull-request-url }}" diff --git a/Makefile b/Makefile index 503c684a..ce6efbf8 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ CONTAINER_RUNTIME ?= docker TARGET_ARCH ?= amd64 # CHANNELS define the bundle channels used in the bundle. -CHANNELS = "development" +CHANNELS ?= "development" # Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable") # To re-generate a bundle for other specific channels without changing the standard setup, you can: # - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable) @@ -29,18 +29,23 @@ endif # To re-generate a bundle for any other default channel without changing the default setup, you can: # - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable) # - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable") -DEFAULT_CHANNEL = "development" +comma := , +space := +space += +DEFAULT_CHANNEL ?= $(word 1,$(subst $(comma), $(space), $(CHANNELS))) ifneq ($(origin DEFAULT_CHANNEL), undefined) BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) endif BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) +IMAGE_ORG ?= quay.io/konveyor + # IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images. # This variable is used to construct full image tags for bundle and catalog images. # # For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both # konveyor.io/tackle-operator-bundle:$VERSION and konveyor.io/tackle-operator-catalog:$VERSION. -IMAGE_TAG_BASE ?= quay.io/konveyor/tackle2-operator +IMAGE_TAG_BASE ?= $(IMAGE_ORG)/tackle2-operator # BUNDLE_IMG defines the image:tag used for the bundle. # You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=/:) @@ -61,7 +66,7 @@ ifeq ($(USE_IMAGE_DIGESTS), true) endif # Image URL to use all building/pushing image targets -IMG ?= quay.io/konveyor/tackle2-operator:latest +IMG ?= $(IMAGE_ORG)/tackle2-operator:latest .PHONY: all all: docker-build @@ -173,18 +178,25 @@ endif OPERATOR_SDK = $(shell pwd)/bin/operator-sdk OPERATOR_SDK_VERSION ?= v1.28.1 .PHONY: operator-sdk -operator-sdk: $(OPERATOR_SDK) - -$(OPERATOR_SDK): - mkdir -p $(dir $(OPERATOR_SDK)) && \ - curl -Lo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$(shell go env GOOS)_$(shell go env GOARCH) && \ - chmod +x $(OPERATOR_SDK); +operator-sdk: +ifeq (,$(wildcard $(OPERATOR_SDK))) +ifeq (,$(shell which operator-sdk 2>/dev/null)) + @{ \ + set -e ;\ + mkdir -p $(dir $(OPERATOR_SDK)) ;\ + curl -Lo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$(shell go env GOOS)_$(shell go env GOARCH) ;\ + chmod +x $(OPERATOR_SDK) ;\ + } +else +OPERATOR_SDK = $(shell which operator-sdk) +endif +endif # HELM_TEMPLATE_OPTS="--set images.operator=quay.io/mine/tackle2-operator:foobar" # putting it last allows the operator image to be overridden .PHONY: bundle bundle: helm operator-sdk ## Generate bundle manifests and metadata, then validate generated files. - helm template --set images.operator=${IMG} --set olm=true $(HELM_TEMPLATE_OPTS) ./helm | $(OPERATOR_SDK) generate bundle -q --overwrite --extra-service-accounts tackle-hub,tackle-ui --version $(VERSION) $(BUNDLE_METADATA_OPTS) + helm template --set images.operator=${IMG} --set version=$(VERSION) --set olm=true $(HELM_TEMPLATE_OPTS) ./helm | $(OPERATOR_SDK) generate bundle -q --overwrite --extra-service-accounts tackle-hub,tackle-ui --version $(VERSION) $(BUNDLE_GEN_FLAGS) $(OPERATOR_SDK) bundle validate ./bundle .PHONY: bundle-sync-check @@ -254,3 +266,36 @@ install-tackle: .PHONY: install-konveyor install-konveyor: $(shell pwd)/hack/install-konveyor.sh + +YQ = $(shell pwd)/bin/yq +.PHONY: yq +yq: +ifeq (,$(wildcard $(YQ))) +ifeq (,$(shell which yq 2>/dev/null)) + @{ \ + set -e ;\ + mkdir -p $(dir $(YQ)) ;\ + curl -L https://github.com/mikefarah/yq/releases/download/v4.13.5/yq_$(OS)_$(ARCH) -o $(YQ) ;\ + chmod +x $(YQ) ;\ + } +else +YQ = $(shell which yq) +endif +endif + +OPENSHIFT_CLIENT = $(shell pwd)/bin/oc +.PHONY: openshift-client +openshift-client: +ifeq (,$(wildcard $(OPENSHIFT_CLIENT))) +ifeq (,$(shell which oc 2>/dev/null)) + @{ \ + set -e ;\ + mkdir -p $(dir $(OPENSHIFT_CLIENT)) ;\ + curl -L https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/stable/openshift-client-$(subst darwin,mac,$(OS))-$(ARCH).tar.gz -o $(dir $(OPENSHIFT_CLIENT))openshift-client.tar.gz ;\ + tar zxf $(dir $(OPENSHIFT_CLIENT))openshift-client.tar.gz -C $(dir $(OPENSHIFT_CLIENT)) ;\ + rm $(dir $(OPENSHIFT_CLIENT))openshift-client.tar.gz ;\ + } +else +OPENSHIFT_CLIENT = $(shell which oc) +endif +endif diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml index 9c8dd387..06549732 100644 --- a/helm/templates/deployment.yaml +++ b/helm/templates/deployment.yaml @@ -34,13 +34,13 @@ spec: - name: PROFILE value: konveyor - name: VERSION - value: 99.0.0 + value: {{ .Values.version }} - name: RELATED_IMAGE_OAUTH_PROXY value: {{ .Values.images.oauth_proxy }} - name: RELATED_IMAGE_TACKLE_HUB value: {{ .Values.images.tackle_hub }} - name: RELATED_IMAGE_TACKLE_POSTGRES - value: quay.io/centos7/postgresql-12-centos7:latest + value: {{ .Values.images.tackle_postgres }} - name: RELATED_IMAGE_KEYCLOAK_SSO value: {{ .Values.images.keycloak_sso }} - name: RELATED_IMAGE_KEYCLOAK_INIT diff --git a/helm/templates/olm/konveyor-operator.clusterserviceversion.yaml b/helm/templates/olm/konveyor-operator.clusterserviceversion.yaml index 81c8124e..95338a6b 100644 --- a/helm/templates/olm/konveyor-operator.clusterserviceversion.yaml +++ b/helm/templates/olm/konveyor-operator.clusterserviceversion.yaml @@ -7,11 +7,11 @@ metadata: capabilities: Seamless Upgrades categories: Modernization & Migration certified: "false" - containerImage: quay.io/konveyor/tackle2-operator:latest + containerImage: {{ .Values.images.operator }} description: Konveyor is an open-source application modernization platform that helps organizations safely and predictably modernize applications to Kubernetes at scale. - olm.skipRange: '>=0.0.0 <{{ substr 1 -1 .Chart.Version }}' + olm.skipRange: '>=0.0.0 <{{ .Values.version }}' operatorframework.io/initialization-resource: |- { "apiVersion": "tackle.konveyor.io/v1alpha1", @@ -27,7 +27,7 @@ metadata: operatorframework.io/suggested-namespace: konveyor-tackle repository: https://github.com/konveyor/tackle2-operator support: https://github.com/konveyor/tackle2-operator/issues - name: konveyor-operator.{{ .Chart.Version }} + name: konveyor-operator.v{{ .Values.version }} namespace: konveyor-tackle spec: apiservicedefinitions: {} @@ -111,7 +111,7 @@ spec: provider: name: Konveyor url: https://www.konveyor.io - version: {{ substr 1 -1 .Chart.Version }} + version: {{ .Values.version }} {{ if .Values.csv.replaces }} replaces: {{ .Values.csv.replaces }} {{ end }} diff --git a/helm/values.yaml b/helm/values.yaml index 326ff6dd..f1005795 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -1,3 +1,5 @@ +version: "99.0.0" + # true in the case we want to render manifests for OLM stuff olm: false csv: diff --git a/tools/konveyor-operator-publish-commands.sh b/tools/konveyor-operator-publish-commands.sh deleted file mode 100755 index 0c9ba7e8..00000000 --- a/tools/konveyor-operator-publish-commands.sh +++ /dev/null @@ -1,222 +0,0 @@ -#!/bin/bash - -set -o nounset -set -o errexit -set -o pipefail - -export OPERATOR_VERSION=$(echo ${OPERATOR_SEMVER} | sed -e 's/^v//g') -export PREV_OPERATOR_VERSION=$(echo ${PREV_OPERATOR_SEMVER} | sed -e 's/^v//g') - -echo "************ konveyor operator publish command ************" - -# Install tools -echo "## Install yq" -curl -L https://github.com/mikefarah/yq/releases/download/v4.13.5/yq_linux_amd64 -o /tmp/yq && chmod +x /tmp/yq -echo " yq installed" - -echo "## Install jq" -curl -L https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 -o /tmp/jq && chmod +x /tmp/jq -echo " jq installed" - -echo "## Install oc" -pushd /tmp -curl -L https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/stable/openshift-client-linux.tar.gz -o openshift-client-linux.tar.gz -tar zxf openshift-client-linux.tar.gz -popd - -REGISTRY_HOST="quay.io" -REGISTRY_ORG="konveyor" -OPERATOR_MANIFESTS="bundle/manifests" -OPERATOR_METADATA="bundle/metadata" -CSV="konveyor-operator.clusterserviceversion.yaml" - -echo ${QUAY_TOKEN} | docker login ${REGISTRY_HOST} -u ${QUAY_ROBOT} --password-stdin - -CO_PROJECT="community-operators-prod" -CO_PROJECT_K8S="community-operators" -CO_REPO="redhat-openshift-ecosystem/${CO_PROJECT}" -CO_REPO_K8S="k8s-operatorhub/${CO_PROJECT_K8S}" -CO_GIT="https://github.com/${CO_REPO}.git" -CO_GIT_K8S="https://github.com/${CO_REPO_K8S}.git" -CO_FORK="https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_USER}/${CO_PROJECT}.git" -CO_FORK_K8S="https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_USER}/${CO_PROJECT_K8S}.git" -CO_DIR=$(mktemp -d) -CO_DIR_K8S=$(mktemp -d) -CO_OPERATOR_DIR="${CO_DIR}/operators/konveyor-operator" -CO_OPERATOR_DIR_K8S="${CO_DIR_K8S}/operators/konveyor-operator" -CO_OPERATOR_ANNOTATIONS="${CO_OPERATOR_DIR}/${OPERATOR_VERSION}/metadata/annotations.yaml" - -if [ -z "${GITHUB_USER}" ] || [ -z "${GITHUB_TOKEN}" ] || [ -z "${GITHUB_NAME}" ] || [ -z "${GITHUB_EMAIL}" ]; then - echo "Must set all of GITHUB_USER, GITHUB_TOKEN, GITHUB_NAME, and GITHUB_EMAIL" - exit 1 -fi - -echo -echo "## Cloning community-operator-prod repo" -git clone "${CO_FORK}" "${CO_DIR}" -pushd "${CO_DIR}" -git remote add upstream "${CO_GIT}" -git fetch upstream main:upstream/main -git checkout upstream/main -git config user.name "${GITHUB_NAME}" -git config user.email "${GITHUB_EMAIL}" -echo " ${CO_PROJECT} cloned" -popd - -echo -echo "## Cloning community-operator repo" -git clone "${CO_FORK_K8S}" "${CO_DIR_K8S}" -pushd "${CO_DIR_K8S}" -git remote add upstream "${CO_GIT_K8S}" -git fetch upstream main:upstream/main -git checkout upstream/main -git config user.name "${GITHUB_NAME}" -git config user.email "${GITHUB_EMAIL}" -echo " ${CO_PROJECT_K8S} cloned" -popd - -echo -echo "## Collecting channels to be updated" -BUNDLE_CHANNELS=$(/tmp/yq eval '.annotations."operators.operatorframework.io.bundle.channels.v1"' "${OPERATOR_METADATA}/annotations.yaml") -echo " channels to be updated are: ${BUNDLE_CHANNELS}" - -PREV_OPERATOR_VERSION=${PREV_OPERATOR_VERSION:-''} -if ! [ -z "${PREV_OPERATOR_VERSION}" ]; then - echo - echo "## Determine operator versions we skip" - echo " use previous version to determine the versions we skip" - OPERATOR_SKIPS=$(/tmp/yq eval ".spec.skips | .[]" "${CO_OPERATOR_DIR}/${PREV_OPERATOR_VERSION}/${CSV}" ||: ) - OPERATOR_SKIPS="${OPERATOR_SKIPS} konveyor-operator.v${PREV_OPERATOR_VERSION}" -echo " skipping these operator versions: " -for version in ${OPERATOR_SKIPS}; do - echo " - ${version}" -done -fi - -echo -echo "## Update operator manifests" -mkdir -p "${CO_OPERATOR_DIR}/${OPERATOR_VERSION}" -cp -r "${OPERATOR_MANIFESTS}" "${CO_OPERATOR_DIR}/${OPERATOR_VERSION}" -cp -r "${OPERATOR_METADATA}" "${CO_OPERATOR_DIR}/${OPERATOR_VERSION}" -pushd "${CO_DIR}" -git checkout -B "${OPERATOR_VERSION}" -CO_CSV="${CO_OPERATOR_DIR}/${OPERATOR_VERSION}/manifests/${CSV}" - -echo " updating operand images to use digest" -# Grab all of the images from the relatedImages and get their digest sha -for full_image in $(/tmp/yq eval '.spec.relatedImages[] | .image' "${CO_CSV}"); do - image=${full_image%:*} - image_name=${image#*/} - - # Mirror image - mirror_image_name="${REGISTRY_ORG}/${image_name#*/}" - if ! [[ "$full_image" =~ "${REGISTRY_HOST}/${REGISTRY_ORG}/".* ]]; then - - full_mirror_image="${REGISTRY_HOST}/${mirror_image_name}:v${OPERATOR_VERSION}" - echo " mirroring image ${full_image} -> ${full_mirror_image}" - /tmp/oc image mirror "${full_image}" "${full_mirror_image}" || { - echo "ERROR Unable to mirror image" - exit 1 - } - fi - - digest=$(curl -G "https://${REGISTRY_HOST}/api/v1/repository/${mirror_image_name}/tag/?specificTag=v${OPERATOR_VERSION}" | \ - /tmp/jq -e -r ' - .tags[] - | select((has("expiration") | not)) - | .manifest_digest') - - # Fail if digest empty - [[ -z ${digest} ]] && false - sed -i "s,${full_image},${REGISTRY_HOST}/${mirror_image_name}@${digest},g" "${CO_CSV}" -done - -echo " updating operator image to use digest" -full_operator_image=$(/tmp/yq eval '.spec.install.spec.deployments[0].spec.template.spec.containers[0] | .image' "${CO_CSV}") -operator_image=${full_operator_image%:*} -operator_image_name=${operator_image#*/} -operator_digest=$(curl -G "https://${REGISTRY_HOST}/api/v1/repository/${operator_image_name}/tag/?specificTag=v${OPERATOR_VERSION}" | \ - /tmp/jq -e -r ' - .tags[] - | select((has("expiration") | not)) - | .manifest_digest') -export operator_digest_fqin=${operator_image}@${operator_digest} -/tmp/yq eval --exit-status --inplace \ - '.spec.install.spec.deployments[0].spec.template.spec.containers[0].image |= strenv(operator_digest_fqin)' "${CO_CSV}" -/tmp/yq eval --exit-status --inplace '.metadata.annotations["containerImage"] |= strenv(operator_digest_fqin)' "${CO_CSV}" - -echo " update createdAt time" -CREATED_AT=$(date +"%Y-%m-%dT%H:%M:%SZ") /tmp/yq eval --exit-status --inplace '.metadata.annotations["createdAt"] |= strenv(CREATED_AT)' "${CO_CSV}" - -echo " update operator version" -/tmp/yq eval --exit-status --inplace \ - '.metadata.name |= "konveyor-operator.v" + strenv(OPERATOR_VERSION)' "${CO_CSV}" - -echo " adding replaces" -if [ -z "${PREV_OPERATOR_VERSION}" ]; then - /tmp/yq eval --exit-status --inplace 'del(.spec.replaces)' "${CO_CSV}" -else -v="konveyor-operator.v${PREV_OPERATOR_VERSION}" \ - /tmp/yq eval --exit-status --inplace \ - '.spec.replaces |= strenv(v)' "${CO_CSV}" -fi - -echo " adding skipRange" - /tmp/yq eval --exit-status --inplace \ - '.metadata.annotations["olm.skipRange"] |= ">=0.0.0 <" + strenv(OPERATOR_VERSION)' "${CO_CSV}" - -if ! [ -z "${PREV_OPERATOR_VERSION}" ]; then - echo " adding spec.skips" - for version in ${OPERATOR_SKIPS}; do - v="${version}" \ - /tmp/yq eval --exit-status --inplace \ - '.spec.skips |= . + [strenv(v)]' "${CO_CSV}" - done -fi - -echo " updating version" - /tmp/yq eval --exit-status --inplace \ - '.spec.version |= strenv(OPERATOR_VERSION)' "${CO_CSV}" - - /tmp/yq eval --exit-status --inplace \ - '.spec.install.spec.deployments[0].spec.template.spec.containers[0].env[] |= select(.name == "VERSION") .value=strenv(OPERATOR_VERSION)' "${CO_CSV}" - -echo " update annotations channel" -for c in ${BUNDLE_CHANNELS//,/ }; do - /tmp/yq eval --inplace '.annotations["operators.operatorframework.io.bundle.channels.v1"] |= strenv(OPERATOR_CHANNEL)' ${CO_OPERATOR_ANNOTATIONS} - /tmp/yq eval --inplace '.annotations["operators.operatorframework.io.bundle.channel.default.v1"] |= strenv(OPERATOR_CHANNEL)' ${CO_OPERATOR_ANNOTATIONS} -done - -echo " remove scorecard annotations" -/tmp/yq eval --inplace 'del(.annotations["operators.operatorframework.io.test.mediatype.v1"])' ${CO_OPERATOR_ANNOTATIONS} -/tmp/yq eval --inplace 'del(.annotations["operators.operatorframework.io.test.config.v1"])' ${CO_OPERATOR_ANNOTATIONS} - -echo " add minimum version to annotations" -/tmp/yq eval --inplace '.annotations["com.redhat.openshift.versions"] = "v4.9" | .annotations["com.redhat.openshift.versions"] style="double"' ${CO_OPERATOR_ANNOTATIONS} - -echo " copy updated operator files to K8s repo and submit PR" -cp -r ${CO_OPERATOR_DIR}/. ${CO_OPERATOR_DIR_K8S} -pushd "${CO_DIR_K8S}" -git checkout -B "${OPERATOR_VERSION}" -git add --all -git commit -s -m "konveyor-operator.v${OPERATOR_VERSION}" -git push --set-upstream --force origin HEAD -# Create PR -curl "https://api.github.com/repos/${CO_REPO_K8S}/pulls" --user "${GITHUB_USER}:${GITHUB_TOKEN}" -X POST \ - --data '{"title": "'"$(git log -1 --format=%s)"'", "base": "main", "body": "An automated PR to update konveyor-operator to v'"${OPERATOR_VERSION}"'", "head": "'"${GITHUB_USER}:${OPERATOR_VERSION}"'"}' -popd - -echo -echo "## Submit PR to community operators" -echo " commit changes" -git add --all -git commit -s -m "konveyor-operator.v${OPERATOR_VERSION}" -git push --set-upstream --force origin HEAD - -echo " submit PR" -# Create PR -curl "https://api.github.com/repos/${CO_REPO}/pulls" --user "${GITHUB_USER}:${GITHUB_TOKEN}" -X POST \ - --data '{"title": "'"$(git log -1 --format=%s)"'", "base": "main", "body": "An automated PR to update konveyor-operator to v'"${OPERATOR_VERSION}"'", "head": "'"${GITHUB_USER}:${OPERATOR_VERSION}"'"}' -popd - -echo "## Done ##"