diff --git a/.github/actions/chart/action.yaml b/.github/actions/chart/action.yaml new file mode 100644 index 000000000..92a85845f --- /dev/null +++ b/.github/actions/chart/action.yaml @@ -0,0 +1,66 @@ +name: Build and publish charts + +inputs: + build_env: + required: true + keep_previous: + required: false + default: no + ibs_release: + required: false + default: no + +runs: + using: composite + steps: + - name: Install yq + uses: mikefarah/yq@v4.28.2 + - name: Set image repositories + id: set_repo + shell: bash + env: + B_ENV: ${{ inputs.build_env }} + IBS_RELEASE: ${{ inputs.ibs_release }} + run: | + if [ "${IBS_RELEASE}" == "yes" ]; then + echo "B_REPO=registry.suse.com" >> $GITHUB_OUTPUT + else + echo "B_REPO=registry.opensuse.org/isv/rancher/elemental/${B_ENV}/containers" >> $GITHUB_OUTPUT + fi + - name: Build chart for release + env: + B_REPO: ${{ steps.set_repo.outputs.B_REPO }} + OPERATOR_REPO: rancher/elemental-operator + SEEDIMAGE_REPO: rancher/seedimage-builder + CHANNEL_REPO: rancher/elemental-teal-channel + shell: bash + run: | + REGISTRY_URL=${B_REPO} \ + REPO=${OPERATOR_REPO} \ + REPO_SEEDIMAGE=${SEEDIMAGE_REPO} \ + REPO_CHANNEL=${CHANNEL_REPO} \ + make chart + - name: Build and push index + env: + B_ENV: ${{ inputs.build_env }} + KEEP_PREV: ${{ inputs.keep_previous }} + IBS_RELEASE: ${{ inputs.ibs_release }} + shell: bash + run: | + COMMIT=$(git rev-parse HEAD) + git config --global user.email "${{ github.actor }}@users.noreply.github.com" + git config --global user.name "${{ github.actor }}" + git checkout gh-pages + if [ "${IBS_RELEASE}" == "yes" ]; then + B_ENV="release" + fi + if [ "${KEEP_PREV}" == "no" ]; then + rm -rf ${B_ENV} + fi + mkdir -p ${B_ENV}/build + cp -v build/* ${B_ENV}/build + helm repo index --url https://rancher.github.io/elemental-operator ./${B_ENV} + git add ${B_ENV}/index.yaml ${B_ENV}/build/ -f + git commit -m "Updating helm dev repo to main commit ${{ github.sha }}" + git push --set-upstream origin gh-pages + git checkout ${COMMIT} diff --git a/.github/workflows/chart.yaml b/.github/workflows/chart.yaml index 9e42b9fdc..0319de671 100644 --- a/.github/workflows/chart.yaml +++ b/.github/workflows/chart.yaml @@ -1,90 +1,20 @@ -name: Build and publish chart +name: Build and publish development charts on: - pull_request: push: branches: - main tags: - - 'v*' + - "v*" + jobs: - chart: + dev-charts: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Install yq - uses: mikefarah/yq@v4.28.2 - - name: Build chart for CI - if: ${{ !startsWith(github.ref, 'refs/tags/') }} - run: | - make chart - - name: Build chart for release - if: startsWith(github.ref, 'refs/tags/') - run: | - REGISTRY_URL=quay.io/costoolkit REPO=elemental-operator REPO_SEEDIMAGE=elemental-seedimage TAG=${GITHUB_REF##*/} make chart - - name: Publish chart to release - uses: fnkr/github-action-ghr@v1 - if: startsWith(github.ref, 'refs/tags/') - env: - GHR_COMPRESS: tgz - GHR_PATH: build/ - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GHR_REPLACE: true - - name: Install Helm - if: startsWith(github.ref, 'refs/tags/') - uses: azure/setup-helm@v1 + - name: Build and publish OBS dev charts + uses: "./.github/actions/chart" with: - version: v3.7.1 - - name: Set chart output - id: chart - run: | - CHART=$(find . -type f -name "elemental-operator-[1-9]*.tgz" -print) - echo "chart_name=$CHART" >> $GITHUB_OUTPUT - - name: Test chart values - if: ${{ !startsWith(github.ref, 'refs/tags/') }} - run: | - REGISTRY_URL=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .registry_url) - REPO=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .image.repository) - if [ "$REGISTRY_URL" != "quay.io/coostoolkit" ]; then - echo "registry_url on the built chart is not the expected value" - echo "Expected quay.io/coostoolkit but got $REGISTRY_URL" - fi - if [ "$REPO" != "elemental-operator-ci" ];then - echo "REPO on the built chart is not the expected value" - echo "Expected elemental-operator-ci but got $REPO" - exit 1 - fi - - name: Test release chart values - if: startsWith(github.ref, 'refs/tags/') - run: | - REGISTRY_URL=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .registry_url)) - REPO=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .image.repository) - TAG=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .image.tag) - if [ "$REGISTRY_URL" != "quay.io/coostoolkit" ]; then - echo "registry_url on the built chart is not the expected value" - echo "Expected quay.io/coostoolkit but got $REGISTRY_URL" - fi - if [ "$REPO" != "elemental-operator" ];then - echo "REPO on the built chart is not the expected value" - echo "Expected elemental-operator but got $REPO" - exit 1 - fi - if [ "$TAG" != "${GITHUB_REF##*/}" ];then - echo "TAG on the built chart is not the expected value" - echo "Expected ${GITHUB_REF##*/} but got $TAG" - exit 1 - fi - - name: Build and push index - if: startsWith(github.ref, 'refs/tags/') - run: | - git config --global user.email "${{ github.actor }}@users.noreply.github.com" - git config --global user.name "${{ github.actor }}" - git checkout gh-pages - rm index.yaml - helm repo index --url https://rancher.github.io/elemental-operator . - git add index.yaml build/ -f - git commit -m "Updating helm repo to main commit ${{ github.sha }}" - git push --set-upstream origin gh-pages - + build_env: dev diff --git a/.github/workflows/gorelease.yaml b/.github/workflows/gorelease.yaml deleted file mode 100644 index 8956c18dd..000000000 --- a/.github/workflows/gorelease.yaml +++ /dev/null @@ -1,42 +0,0 @@ -name: goreleaser - -on: - push: - tags: - - 'v*' - -jobs: - goreleaser: - runs-on: ubuntu-latest - permissions: - contents: write - id-token: write - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version-file: go.mod - - name: Install cosign - uses: sigstore/cosign-installer@v2.8.0 - - name: Install syft - uses: anchore/sbom-action/download-syft@v0 - - uses: actions/cache@v3.0.11 - with: - path: | - ~/go/pkg/mod - ~/.cache/go-build - key: ${{ runner.os }}-release-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-release-go-${{ hashFiles('**/go.sum') }} - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v3.2.0 - with: - version: latest - args: release --rm-dist - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - COSIGN_EXPERIMENTAL: 1 diff --git a/.github/workflows/release-chart.yaml b/.github/workflows/release-chart.yaml new file mode 100644 index 000000000..40df82a33 --- /dev/null +++ b/.github/workflows/release-chart.yaml @@ -0,0 +1,61 @@ +name: Build and publish staging or stable charts +on: + workflow_dispatch: + inputs: + tag: + description: "Tag to build" + required: true + type: string + release: + description: "Release stable versions, staging otherwise" + type: boolean + default: false + +jobs: + stable-charts: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Log inputs + run: echo "${{ toJSON(github.event.inputs) }}" + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: ${{ inputs.tag }} + - name: Build and publish OBS staging charts + if: inputs.release == false + uses: "./.github/actions/chart" + with: + build_env: staging + - name: Build and publish OBS stable charts + if: inputs.release == true + uses: "./.github/actions/chart" + with: + build_env: stable + keep_previous: yes + - name: Clear built artifacts + if: inputs.release == true + shell: bash + run: | + rm -rf build/* + - name: Build and publish IBS charts + if: inputs.release == true + uses: "./.github/actions/chart" + with: + build_env: stable + keep_previous: yes + ibs_release: yes + - name: create release + if: inputs.release == true + uses: ncipollo/release-action@v1 + id: create_release + with: + tag: ${{ inputs.tag }} + draft: false + prerelease: true + generateReleaseNotes: true + artifacts: "build/*" + updateOnlyUnreleased: true + allowUpdates: true diff --git a/Makefile b/Makefile index fe8e62490..43c0144e1 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,15 @@ GIT_COMMIT?=$(shell git rev-parse HEAD) GIT_COMMIT_SHORT?=$(shell git rev-parse --short HEAD) GIT_TAG?=$(shell git describe --abbrev=0 --tags 2>/dev/null || echo "v0.0.0" ) -TAG?=${GIT_TAG}-${GIT_COMMIT_SHORT} -REPO?=elemental-operator-ci -REPO_REGISTER?=elemental-register-ci -REPO_SEEDIMAGE?=seedimage-builder-ci -REGISTRY_URL?=quay.io/coostoolkit -#REGISTRY_URL?=registry.opensuse.org/isv/rancher/elemental/dev/containers +CHART_VERSION?=$(subst v,,$(GIT_TAG)) +TAG?=${GIT_TAG} +REPO?=rancher/elemental-operator +REPO_REGISTER?=rancher/elemental-register +TAG_SEEDIMAGE?=${CHART_VERSION} +REPO_SEEDIMAGE?=rancher/seedimage-builder +TAG_CHANNEL?=${CHART_VERSION} +REPO_CHANNEL?=rancher/elemental-teal-channel +REGISTRY_URL?=registry.opensuse.org/isv/rancher/elemental/dev/containers ifneq ($(REGISTRY_URL),) REGISTRY_HEADER := $(REGISTRY_URL)/ else @@ -14,7 +17,6 @@ else endif export ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) -CHART_VERSION?=$(subst v,,$(GIT_TAG)) CHART?=$(shell find $(ROOT_DIR) -type f -name "elemental-operator-$(CHART_VERSION).tgz" -print) KUBE_VERSION?="v1.24.6" CLUSTER_NAME?="operator-e2e" @@ -98,7 +100,7 @@ build-docker-operator: --build-arg "TAG=${GIT_TAG}" \ --build-arg "COMMIT=${GIT_COMMIT}" \ --build-arg "COMMITDATE=${COMMITDATE}" \ - -t ${REGISTRY_HEADER}${REPO}:${TAG} . + -t ${REGISTRY_HEADER}${REPO}:${CHART_VERSION} . .PHONY: build-docker-register build-docker-register: @@ -108,25 +110,25 @@ build-docker-register: --build-arg "TAG=${GIT_TAG}" \ --build-arg "COMMIT=${GIT_COMMIT}" \ --build-arg "COMMITDATE=${COMMITDATE}" \ - -t ${REGISTRY_HEADER}${REPO_REGISTER}:${TAG} . + -t ${REGISTRY_HEADER}${REPO_REGISTER}:${CHART_VERSION} . .PHONY: build-docker-seedimage-builder build-docker-seedimage-builder: DOCKER_BUILDKIT=1 docker build \ -f Dockerfile.seedimage \ - -t ${REGISTRY_HEADER}${REPO_SEEDIMAGE}:${TAG} . + -t ${REGISTRY_HEADER}${REPO_SEEDIMAGE}:${TAG_SEEDIMAGE} . .PHONY: build-docker-push-operator build-docker-push-operator: build-docker-operator - docker push ${REGISTRY_HEADER}${REPO}:${TAG} + docker push ${REGISTRY_HEADER}${REPO}:${CHART_VERSION} .PHONY: build-docker-push-register build-docker-push-register: build-docker-register - docker push ${REGISTRY_HEADER}${REPO_REGISTER}:${TAG} + docker push ${REGISTRY_HEADER}${REPO_REGISTER}:${CHART_VERSION} .PHONY: build-docker-push-seedimage-builder build-docker-push-seedimage-builder: build-docker-seedimage-builder - docker push ${REGISTRY_HEADER}${REPO_SEEDIMAGE}:${TAG} + docker push ${REGISTRY_HEADER}${REPO_SEEDIMAGE}:${TAG_SEEDIMAGE} .PHONY: chart chart: @@ -135,12 +137,14 @@ chart: helm package --version ${CHART_VERSION} --app-version ${GIT_TAG} -d $(ROOT_DIR)/build/ $(ROOT_DIR)/build/crds rm -Rf $(ROOT_DIR)/build/crds cp -rf $(ROOT_DIR)/charts/operator $(ROOT_DIR)/build/operator - yq -i '.image.tag = "${TAG}"' $(ROOT_DIR)/build/operator/values.yaml + yq -i '.image.tag = "${CHART_VERSION}"' $(ROOT_DIR)/build/operator/values.yaml yq -i '.image.repository = "${REPO}"' $(ROOT_DIR)/build/operator/values.yaml - yq -i '.seedImage.tag = "${TAG}"' $(ROOT_DIR)/build/operator/values.yaml + yq -i '.seedImage.tag = "${TAG_SEEDIMAGE}"' $(ROOT_DIR)/build/operator/values.yaml yq -i '.seedImage.repository = "${REPO_SEEDIMAGE}"' $(ROOT_DIR)/build/operator/values.yaml + yq -i '.channel.tag = "${TAG_CHANNEL}"' $(ROOT_DIR)/build/operator/values.yaml + yq -i '.channel.repository = "${REPO_CHANNEL}"' $(ROOT_DIR)/build/operator/values.yaml yq -i '.registry_url = "${REGISTRY_URL}"' $(ROOT_DIR)/build/operator/values.yaml - helm package --version ${CHART_VERSION} --app-version ${GIT_TAG} -d $(ROOT_DIR)/build/ $(ROOT_DIR)/build/operator + helm package --version ${CHART_VERSION} --app-version ${CHART_VERSION} -d $(ROOT_DIR)/build/ $(ROOT_DIR)/build/operator rm -Rf $(ROOT_DIR)/build/operator .PHONY: migration-chart @@ -178,20 +182,20 @@ setup-full-cluster: build-docker-operator build-docker-seedimage-builder chart s export BRIDGE_IP="172.18.0.1" && \ export CHART=$(CHART) && \ export CONFIG_PATH=$(E2E_CONF_FILE) && \ - kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO}:${TAG} && \ - kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO_SEEDIMAGE}:${TAG} && \ + kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO}:${CHART_VERSION} && \ + kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO_SEEDIMAGE}:${TAG_SEEDIMAGE} && \ cd $(ROOT_DIR)/tests && $(GINKGO) -r -v --label-filter="do-nothing" ./e2e kind-e2e-tests: build-docker-operator chart setup-kind export CONFIG_PATH=$(E2E_CONF_FILE) && \ - kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO}:${TAG} + kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO}:${CHART_VERSION} $(MAKE) e2e-tests # This builds the docker image, generates the chart, loads the image into the kind cluster and upgrades the chart to latest # useful to test changes into the operator with a running system, without clearing the operator namespace # thus losing any registration/inventories/os CRDs already created reload-operator: build-docker-operator chart - kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO}:${TAG} + kind load docker-image --name $(CLUSTER_NAME) ${REGISTRY_HEADER}${REPO}:${CHART_VERSION} helm upgrade -n cattle-elemental-system elemental-operator $(CHART) .PHONY: vendor diff --git a/charts/crds-migration/Chart.yaml b/charts/crds-migration/Chart.yaml deleted file mode 100644 index be3170916..000000000 --- a/charts/crds-migration/Chart.yaml +++ /dev/null @@ -1,4 +0,0 @@ -apiVersion: v2 -name: elemental-operator-crds-migration -decription: A Helm chart for enabling the upgrade from Elemental Operator releases < 1.2.4 -version: 0.0.1 \ No newline at end of file diff --git a/charts/crds-migration/templates/pre-install-hook.yaml b/charts/crds-migration/templates/pre-install-hook.yaml deleted file mode 100644 index 71e58d074..000000000 --- a/charts/crds-migration/templates/pre-install-hook.yaml +++ /dev/null @@ -1,63 +0,0 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - name: {{ .Release.Name }}-helm-hook - namespace: {{ .Release.Namespace }} - annotations: - "helm.sh/hook": pre-install - "helm.sh/hook-weight": "0" - "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: {{ .Release.Name }}-helm-hook - annotations: - "helm.sh/hook": pre-install - "helm.sh/hook-weight": "0" - "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: cattle-globalrole-admin -subjects: - - apiGroup: rbac.authorization.k8s.io - kind: User - name: system:serviceaccount:{{ .Release.Namespace }}:{{ .Release.Name }}-helm-hook ---- -apiVersion: batch/v1 -kind: Job -metadata: - name: {{ .Release.Name }}-helm-hook - namespace: {{ .Release.Namespace }} - annotations: - "helm.sh/hook": pre-install - "helm.sh/hook-weight": "1" - "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded -spec: - template: - metadata: - name: {{ .Release.Name }}-helm-hook - spec: - serviceAccountName: {{ .Release.Name }}-helm-hook - containers: - - name: crd-keep-policy - image: rancher/kubectl:v1.24.13 - command: - - "kubectl" - - "annotate" - - "crds" - - "--selector=release-name={{ .Values.legacyReleaseName }}" - - "helm.sh/resource-policy=keep" - - "--overwrite=true" - - name: crd-release-name - image: rancher/kubectl:v1.24.13 - command: - - "kubectl" - - "annotate" - - "crds" - - "--selector=release-name={{ .Values.legacyReleaseName }}" - - "meta.helm.sh/release-name={{ .Values.newCRDsReleaseName }}" - - "--overwrite=true" - restartPolicy: Never - backoffLimit: 2 diff --git a/charts/crds-migration/values.yaml b/charts/crds-migration/values.yaml deleted file mode 100644 index f06d2b31a..000000000 --- a/charts/crds-migration/values.yaml +++ /dev/null @@ -1,2 +0,0 @@ -legacyReleaseName: "elemental-operator" -newCRDsReleaseName: "elemental-operator-crds" diff --git a/charts/crds/Chart.yaml b/charts/crds/Chart.yaml index bc21371b0..c8385a452 100644 --- a/charts/crds/Chart.yaml +++ b/charts/crds/Chart.yaml @@ -1,3 +1,4 @@ +# SPDX-License-Identifier: Apache-2.0 apiVersion: v2 name: elemental-operator-crds description: A Helm chart for deploying Rancher Elemental Operator CRDs diff --git a/charts/operator/Chart.yaml b/charts/operator/Chart.yaml index d1d3ceb41..64a92e203 100644 --- a/charts/operator/Chart.yaml +++ b/charts/operator/Chart.yaml @@ -1,3 +1,4 @@ +# SPDX-License-Identifier: Apache-2.0 apiVersion: v2 name: elemental-operator description: Rancher Elemental Operator diff --git a/charts/operator/values.yaml b/charts/operator/values.yaml index 291645f2c..259e157de 100644 --- a/charts/operator/values.yaml +++ b/charts/operator/values.yaml @@ -9,9 +9,9 @@ seedImage: tag: latest imagePullPolicy: IfNotPresent -#channel: -# repository: rancher/elemental-teal-channel -# tag: latest +channel: + repository: "rancher/elemental-teal-channel" + tag: latest # number of operator replicas to deploy replicas: 1