From f2e95b5827b035cb89b63c38a6f37ad005b44147 Mon Sep 17 00:00:00 2001 From: Jan <157487559+JTaeuber@users.noreply.github.com> Date: Tue, 22 Oct 2024 11:37:53 +0200 Subject: [PATCH] Fix/serviceaccount creation (#65) * fix: corrected serviceaccount creation * chore: automatically push pre-commit changes * chore: changed urls * revert to 1.1.1 * feat: add dev build workflow * refactored code * fix: typo * fix errors * add option for latest tag to be empty --------- Co-authored-by: github-actions --- ...or-release.yaml => check_for_release.yaml} | 0 .github/workflows/check_version.yaml | 36 +++++++++---------- .github/workflows/create_dev_build.yaml | 28 +++++++++++++++ .github/workflows/docker_build.yaml | 4 +-- .github/workflows/helm_build.yaml | 4 +-- deployments/chart/Chart.yaml | 4 +-- .../chart/templates/serviceaccount.yaml | 2 ++ 7 files changed, 52 insertions(+), 26 deletions(-) rename .github/workflows/{check-for-release.yaml => check_for_release.yaml} (100%) create mode 100644 .github/workflows/create_dev_build.yaml diff --git a/.github/workflows/check-for-release.yaml b/.github/workflows/check_for_release.yaml similarity index 100% rename from .github/workflows/check-for-release.yaml rename to .github/workflows/check_for_release.yaml diff --git a/.github/workflows/check_version.yaml b/.github/workflows/check_version.yaml index 718f58a..486fbfc 100644 --- a/.github/workflows/check_version.yaml +++ b/.github/workflows/check_version.yaml @@ -13,6 +13,8 @@ jobs: outputs: version_change: ${{ steps.check_for_version_change.outputs.version_change }} app_version_change: ${{ steps.check_for_appVersion_change.outputs.app_version_change }} + version: ${{ steps.chart_version.outputs.version }} + app_version: ${{ steps.app_version.outputs.app_version }} steps: - name: Checkout code @@ -32,6 +34,18 @@ jobs: version_change=$(git diff main HEAD~1 -- deployments/chart/Chart.yaml | grep -qe "^[+-]version: " && echo "version changed" || echo "version didn't change") echo "version_change=$version_change" >> $GITHUB_OUTPUT + - name: Extract Chart Version + id: chart_version + run: | + version=$(yq e '.version' ./deployments/chart/Chart.yaml) + echo "version=$version" >> $GITHUB_OUTPUT + + - name: Extract App Version + id: app_version + run: | + app_version=$(yq e '.appVersion' ./deployments/chart/Chart.yaml) + echo "app_version=$app_version" >> $GITHUB_OUTPUT + build_new_chart: runs-on: ubuntu-latest needs: check_versions @@ -40,22 +54,13 @@ jobs: contents: write steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Extract Chart Version - id: chart_version - run: | - version=$(yq e '.version' ./deployments/chart/Chart.yaml) - echo "version=$version" >> $GITHUB_ENV - - name: Dispatch Event to build new helm chart uses: peter-evans/repository-dispatch@v3 with: token: ${{ secrets.GITHUB_TOKEN }} repository: caas-team/GoKubeDownscaler event-type: build-new-chart - client-payload: '{"version": "${{ env.version }}"}' + client-payload: '{"version": "${{ needs.check_versions.outputs.version }}", "appVersion": "${{ needs.check_versions.outputs.app_version }}"}' release_new_version: runs-on: ubuntu-latest @@ -65,19 +70,10 @@ jobs: contents: write steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Extract App Version - id: app_version - run: | - app_version=$(yq e '.appVersion' ./deployments/chart/Chart.yaml) - echo "app_version=$app_version" >> $GITHUB_ENV - - name: Dispatch Event to create new release uses: peter-evans/repository-dispatch@v3 with: token: ${{ secrets.GITHUB_TOKEN }} repository: caas-team/GoKubeDownscaler event-type: release-new-version - client-payload: '{"appVersion": "${{ env.app_version }}"}' + client-payload: '{"appVersion": "${{ needs.check_versions.outputs.app_version }}", "setLatest": true}' diff --git a/.github/workflows/create_dev_build.yaml b/.github/workflows/create_dev_build.yaml new file mode 100644 index 0000000..81520ee --- /dev/null +++ b/.github/workflows/create_dev_build.yaml @@ -0,0 +1,28 @@ +name: Create dev build + +on: + workflow_dispatch: + +jobs: + create_dev_build: + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Extract Chart Version + id: chart_version + run: | + version=$(yq e '.version' ./test-chart/Chart.yaml) + echo "version=$version" >> $GITHUB_ENV + + - name: Dispatch event to create dev build + uses: peter-evans/repository-dispatch@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + repository: caas-team/GoKubeDownscaler + event-type: create-dev-build + client-payload: '{"version": "${{ env.version }}-dev","appVersion": "dev", "setLatest": false}' diff --git a/.github/workflows/docker_build.yaml b/.github/workflows/docker_build.yaml index 2004390..cd478e1 100644 --- a/.github/workflows/docker_build.yaml +++ b/.github/workflows/docker_build.yaml @@ -2,7 +2,7 @@ name: Build and push Image on: repository_dispatch: - types: [release-new-version] + types: [release-new-version, create-dev-build] jobs: build: @@ -19,7 +19,7 @@ jobs: mtr.devops.telekom.de/caas/go-kube-downscaler ghcr.io/caas-team/gokubedownscaler tags: | - latest + ${{ github.event.client_payload.setLatest && 'latest' || '' }} ${{ github.event.client_payload.appVersion }} - name: Install Cosign diff --git a/.github/workflows/helm_build.yaml b/.github/workflows/helm_build.yaml index 03177a3..b1dc5d1 100644 --- a/.github/workflows/helm_build.yaml +++ b/.github/workflows/helm_build.yaml @@ -2,7 +2,7 @@ name: Build and push helm chart on: repository_dispatch: - types: [build-new-chart] + types: [build-new-chart, create-dev-build] jobs: build_and_push: @@ -29,7 +29,7 @@ jobs: run: | cd deployments/chart helm lint . - helm package . + helm package . --version ${{ github.event.client_payload.version }} --app-version ${{ github.event.client_payload.appVersion }} helm push $(ls *.tgz | head -1) oci://ghcr.io/caas-team/charts helm push $(ls *.tgz | head -1) oci://${MTR}/${REPO}/charts env: diff --git a/deployments/chart/Chart.yaml b/deployments/chart/Chart.yaml index a1540a0..e58d274 100644 --- a/deployments/chart/Chart.yaml +++ b/deployments/chart/Chart.yaml @@ -14,7 +14,7 @@ sources: maintainers: - name: jonathan-mayer email: jonathan.mayer@telekom.de - url: https://www.telekom.com + url: https://github.com/jonathan-mayer - name: JTaeuber email: jan.taeuber@telekom.de - url: https://www.telekom.com + url: https://github.com/JTaeuber diff --git a/deployments/chart/templates/serviceaccount.yaml b/deployments/chart/templates/serviceaccount.yaml index 726dc7c..24459f9 100644 --- a/deployments/chart/templates/serviceaccount.yaml +++ b/deployments/chart/templates/serviceaccount.yaml @@ -1,4 +1,6 @@ +{{- if .Values.serviceAccount.create -}} apiVersion: v1 kind: ServiceAccount metadata: name: {{ include "go-kube-downscaler.serviceAccountName" . }} +{{- end }}