From 2b489cbbdb969fbd5ceeed04eb06f9d0bf502fe4 Mon Sep 17 00:00:00 2001 From: xiaoweim Date: Tue, 4 Feb 2025 02:10:10 +0000 Subject: [PATCH] Add a workflow to automate config connector release bundle creation --- .github/workflows/release-automation.yaml | 35 +++++++++ Makefile | 24 ++----- .../autopilot/kustomization.yaml | 6 +- .../standard/kustomization.yaml | 6 +- dev/tasks/deploy-release-manifest | 72 +++++++++++++++++++ .../github-actions/create-release-bundle.sh | 26 +++++++ 6 files changed, 144 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/release-automation.yaml create mode 100755 dev/tasks/deploy-release-manifest create mode 100644 scripts/github-actions/create-release-bundle.sh diff --git a/.github/workflows/release-automation.yaml b/.github/workflows/release-automation.yaml new file mode 100644 index 0000000000..b1fb1c9922 --- /dev/null +++ b/.github/workflows/release-automation.yaml @@ -0,0 +1,35 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Config Connector Release Automation + +on: + push: + tags: + - 'v*' + +jobs: + create-and-push-release-bundle: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v1 + + - name: Run the create-relese-bundle script + run: | + chmod +x ./scripts/github-actions/create-release-bundle.sh + ./scripts/github-actions/create-release-bundle.sh diff --git a/Makefile b/Makefile index c2667b53be..ec00ebd340 100644 --- a/Makefile +++ b/Makefile @@ -323,32 +323,18 @@ all-manifests: crd-manifests rbac-manifests build-operator-manifests # Build kcc manifests for standard GKE clusters .PHONY: config-connector-manifests-standard -config-connector-manifests-standard: build-crd-manifests build-rbac-manifests build-operator-manifests - cp config/installbundle/release-manifests/crds.yaml config/installbundle/release-manifests/standard/crds.yaml - cp config/installbundle/release-manifests/rbac.yaml config/installbundle/release-manifests/standard/rbac.yaml - kustomize build config/installbundle/release-manifests/standard -o config/installbundle/release-manifests/standard/manifests.yaml +config-connector-manifests-standard: build-operator-manifests + kustomize build config/installbundle/release-manifests/standard # Build kcc manifests for autopilot clusters .PHONY: config-connector-manifests-autopilot -config-connector-manifests-autopilot: build-crd-manifests build-rbac-manifests build-operator-manifests - cp config/installbundle/release-manifests/crds.yaml config/installbundle/release-manifests/autopilot/crds.yaml - cp config/installbundle/release-manifests/rbac.yaml config/installbundle/release-manifests/autopilot/rbac.yaml - kustomize build config/installbundle/release-manifests/autopilot -o config/installbundle/release-manifests/autopilot/manifests.yaml - -.PHONY: build-crd-manifests -build-crd-manifests: - go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.14.0 crd paths="./operator/pkg/apis/..." output:crd:artifacts:config=operator/config/crd/bases - kustomize build operator/config/crd -o config/installbundle/release-manifests/crds.yaml - -.PHONY: build-rbac-manifests -build-rbac-manifests: - kustomize build operator/config/rbac -o config/installbundle/release-manifests/rbac.yaml +config-connector-manifests-autopilot: build-operator-manifests + kustomize build config/installbundle/release-manifests/autopilot .PHONY: build-operator-manifests build-operator-manifests: + go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.14.0 crd paths="./operator/pkg/apis/..." output:crd:artifacts:config=operator/config/crd/bases make -C operator docker-build - kustomize build operator/config/autopilot-manager -o config/installbundle/release-manifests/autopilot/manager.yaml - kustomize build operator/config/manager -o config/installbundle/release-manifests/standard/manager.yaml .PHONY: push-operator-manifest push-operator-manifest: diff --git a/config/installbundle/release-manifests/autopilot/kustomization.yaml b/config/installbundle/release-manifests/autopilot/kustomization.yaml index 284da3c470..fdd2be4d32 100644 --- a/config/installbundle/release-manifests/autopilot/kustomization.yaml +++ b/config/installbundle/release-manifests/autopilot/kustomization.yaml @@ -18,6 +18,6 @@ commonLabels: commonAnnotations: cnrm.cloud.google.com/operator-version: "1.128.0" resources: - - crds.yaml - - rbac.yaml - - manager.yaml + - ../../../../operator/config/rbac + - ../../../../operator/config/crd + - ../../../../operator/config/manager diff --git a/config/installbundle/release-manifests/standard/kustomization.yaml b/config/installbundle/release-manifests/standard/kustomization.yaml index 284da3c470..fdd2be4d32 100644 --- a/config/installbundle/release-manifests/standard/kustomization.yaml +++ b/config/installbundle/release-manifests/standard/kustomization.yaml @@ -18,6 +18,6 @@ commonLabels: commonAnnotations: cnrm.cloud.google.com/operator-version: "1.128.0" resources: - - crds.yaml - - rbac.yaml - - manager.yaml + - ../../../../operator/config/rbac + - ../../../../operator/config/crd + - ../../../../operator/config/manager diff --git a/dev/tasks/deploy-release-manifest b/dev/tasks/deploy-release-manifest new file mode 100755 index 0000000000..241d7351fc --- /dev/null +++ b/dev/tasks/deploy-release-manifest @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail + +# runs the config-connector build across all desired systems and architectures and creates a release tarball +REPO_ROOT="$(git rev-parse --show-toplevel)" +cd ${REPO_ROOT} + + +BUILD_DIR="${REPO_ROOT}/.build" +mkdir -p "${BUILD_DIR}" + + +MANUAL_DIR="${BUILD_DIR}/manual-release" +mkdir -p "${MANUAL_DIR}/operator-system" + +# Find the version of the operator image +FOLDER_PATH="${REPO_ROOT}/operator/channels/packages/configconnector" + +if [ ! -d "$FOLDER_PATH" ]; then + echo "Error: Directory $FOLDER_PATH does not exist" + exit 1 +fi + +# List all directories in the specified path and store them in an array +VERSIONS=($(ls -d "$FOLDER_PATH"/*/ 2>/dev/null | xargs -n 1 basename | sort -V)) + +if [ ${#VERSIONS[@]} -eq 0 ]; then + echo "Error: No version directories found in $FOLDER_PATH" + exit 1 +fi + +LATEST_VERSION="${VERSIONS[-1]}" +OPERATOR_IMG=gcr.io/gke-release/cnrm/operator:${LATEST_VERSION} + +echo "Updating kustomize image patch file for manager." +cp ${REPO_ROOT}/operator/config/manager/manager_image_patch_template.yaml ${REPO_ROOT}/operator/config/manager/manager_image_patch.yaml +sed -i'' -e 's@image: .*@image: '"${OPERATOR_IMG}"'@' ${REPO_ROOT}/operator/config/manager/manager_image_patch.yaml +cp -f ${REPO_ROOT}/operator/config/autopilot-manager/manager_image_patch_template.yaml ${REPO_ROOT}/operator/config/autopilot-manager/manager_image_patch.yaml +sed -i'' -e 's@image: .*@image: '"${OPERATOR_IMG}"'@' ${REPO_ROOT}/operator/config/autopilot-manager/manager_image_patch.yaml + +kustomize build ${REPO_ROOT}/config/installbundle/release-manifests/standard -o ${MANUAL_DIR}/operator-system/configconnector-operator.yaml +echo "Added standard release manifest to ${MANUAL_DIR}/operator-system/configconnector-operator.yaml" + +kustomize build ${REPO_ROOT}/config/installbundle/release-manifests/autopilot -o ${MANUAL_DIR}/operator-system/autopilot-configconnector-operator.yaml +echo "Added autopilot release manifest to ${MANUAL_DIR}/operator-system/autopilot-configconnector-operator.yaml" + +cp -rf operator/config/samples ${MANUAL_DIR}/ + +tar -czvf ${BUILD_DIR}/release-bundle.tar.gz -C ${MANUAL_DIR}/ . + +echo "Generated ${BUILD_DIR}/release-bundle.tar.gz for manual installation." + +gsutil cp ${REPO_ROOT}/.build/release-bundle.tar.gz gs://configconnector-operator/${LATEST_VERSION}/ +gsutil cp ${REPO_ROOT}/.build/release-bundle.tar.gz gs://configconnector-operator/latest + +echo "Pushed the latest release-bundle." diff --git a/scripts/github-actions/create-release-bundle.sh b/scripts/github-actions/create-release-bundle.sh new file mode 100644 index 0000000000..1f2a1006d9 --- /dev/null +++ b/scripts/github-actions/create-release-bundle.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail + +echo "Start creating the release bundle" + +REPO_ROOT="$(git rev-parse --show-toplevel)" + +# build release manifest +source ${REPO_ROOT}/dev/tasks/deploy-release-manifest +