From a3ee6060eb1cbec2d4d93f91ba8e20d49b6c2fbb Mon Sep 17 00:00:00 2001 From: Nikola Jokic Date: Sat, 2 May 2026 17:46:57 +0200 Subject: [PATCH] Fix helm chart validation workflow --- .github/workflows/gha-validate-chart.yaml | 103 +++++++----------- charts/.ci/ct-config-gha.yaml | 2 + .../tests/template_test.go | 52 --------- .../tests/template_test.go | 61 ----------- 4 files changed, 44 insertions(+), 174 deletions(-) delete mode 100644 charts/gha-runner-scale-set-controller-experimental/tests/template_test.go delete mode 100644 charts/gha-runner-scale-set-experimental/tests/template_test.go diff --git a/.github/workflows/gha-validate-chart.yaml b/.github/workflows/gha-validate-chart.yaml index 46d7b065..a8fcf4d2 100644 --- a/.github/workflows/gha-validate-chart.yaml +++ b/.github/workflows/gha-validate-chart.yaml @@ -65,82 +65,63 @@ jobs: echo "$changed" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT - - name: Install helm-unittest - if: | - contains(steps.list-changed.outputs.changed_charts, 'charts/gha-runner-scale-set-controller-experimental') || - contains(steps.list-changed.outputs.changed_charts, 'charts/gha-runner-scale-set-experimental') - run: | - helm plugin install https://github.com/helm-unittest/helm-unittest.git - - - name: Run helm-unittest (gha-runner-scale-set-controller-experimental) - if: contains(steps.list-changed.outputs.changed_charts, 'charts/gha-runner-scale-set-controller-experimental') - run: | - helm unittest ./charts/gha-runner-scale-set-controller-experimental/ - - - name: Run helm-unittest (gha-runner-scale-set-experimental) - if: contains(steps.list-changed.outputs.changed_charts, 'charts/gha-runner-scale-set-experimental') - run: | - helm unittest ./charts/gha-runner-scale-set-experimental/ - - name: Run chart-testing (lint) run: | ct lint --config charts/.ci/ct-config-gha.yaml - - name: Set up docker buildx - uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd - if: steps.list-changed.outputs.changed == 'true' - with: - version: latest - - - name: Build controller image - uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 - if: steps.list-changed.outputs.changed == 'true' - with: - file: Dockerfile - platforms: linux/amd64 - load: true - build-args: | - DOCKER_IMAGE_NAME=test-arc - VERSION=dev - tags: | - test-arc:dev - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Create kind cluster - uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc - if: steps.list-changed.outputs.changed == 'true' - with: - cluster_name: chart-testing - - - name: Load image into cluster - if: steps.list-changed.outputs.changed == 'true' - run: | - export DOCKER_IMAGE_NAME=test-arc - export VERSION=dev - export IMG_RESULT=load - make docker-buildx - kind load docker-image test-arc:dev --name chart-testing - - - name: Run chart-testing (install) - if: steps.list-changed.outputs.changed == 'true' - run: | - ct install --config charts/.ci/ct-config-gha.yaml test-chart: name: Test Chart runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Set up Helm + uses: azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4 + with: + version: ${{ env.HELM_VERSION }} + + # python is a requirement for the chart-testing action below (supports yamllint among other tests) + - uses: actions/setup-python@v6 + with: + python-version: "3.11" + + - name: Set up chart-testing + uses: helm/chart-testing-action@6ec842c01de15ebb84c8627d2744a0c2f2755c9f + + - name: Run chart-testing (list-changed) + id: list-changed + run: | + ct version + changed=$(ct list-changed --config charts/.ci/ct-config-gha.yaml) + if [[ -n "$changed" ]]; then + echo "changed=true" >> $GITHUB_OUTPUT + fi + echo "changed_charts<> $GITHUB_OUTPUT + echo "$changed" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Install helm-unittest + run: | + helm plugin install https://github.com/helm-unittest/helm-unittest.git + + - name: Run helm-unittest (gha-runner-scale-set-controller-experimental) + run: | + helm unittest ./charts/gha-runner-scale-set-controller-experimental/ + + - name: Run helm-unittest (gha-runner-scale-set-experimental) + run: | + helm unittest ./charts/gha-runner-scale-set-experimental/ + - uses: actions/setup-go@v6 with: go-version-file: "go.mod" cache: false + - name: Test gha-runner-scale-set run: go test ./charts/gha-runner-scale-set/... + - name: Test gha-runner-scale-set-controller run: go test ./charts/gha-runner-scale-set-controller/... - - name: Test gha-runner-scale-set-experimental - run: go test ./charts/gha-runner-scale-set-experimental/... - - name: Test gha-runner-scale-set-controller-experimental - run: go test ./charts/gha-runner-scale-set-controller-experimental/... diff --git a/charts/.ci/ct-config-gha.yaml b/charts/.ci/ct-config-gha.yaml index b0a15a37..095e6573 100644 --- a/charts/.ci/ct-config-gha.yaml +++ b/charts/.ci/ct-config-gha.yaml @@ -8,4 +8,6 @@ check-version-increment: false # Disable checking that the chart version has bee charts: - charts/gha-runner-scale-set-controller - charts/gha-runner-scale-set + - charts/gha-runner-scale-set-controller-experimental + - charts/gha-runner-scale-set-experimental skip-clean-up: true diff --git a/charts/gha-runner-scale-set-controller-experimental/tests/template_test.go b/charts/gha-runner-scale-set-controller-experimental/tests/template_test.go deleted file mode 100644 index 80870ec3..00000000 --- a/charts/gha-runner-scale-set-controller-experimental/tests/template_test.go +++ /dev/null @@ -1,52 +0,0 @@ -package tests - -import ( - "os" - "path/filepath" - "strings" - "testing" - - "github.com/gruntwork-io/terratest/modules/helm" - "github.com/gruntwork-io/terratest/modules/k8s" - "github.com/gruntwork-io/terratest/modules/logger" - "github.com/gruntwork-io/terratest/modules/random" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "gopkg.in/yaml.v2" - appsv1 "k8s.io/api/apps/v1" -) - -type Chart struct { - Version string `yaml:"version"` - AppVersion string `yaml:"appVersion"` -} - -func TestTemplate_RenderedDeployment_UsesChartMetadataLabels(t *testing.T) { - t.Parallel() - - helmChartPath, err := filepath.Abs("../../gha-runner-scale-set-controller-experimental") - require.NoError(t, err) - - chartContent, err := os.ReadFile(filepath.Join(helmChartPath, "Chart.yaml")) - require.NoError(t, err) - - chart := new(Chart) - err = yaml.Unmarshal(chartContent, chart) - require.NoError(t, err) - - releaseName := "test-arc" - namespaceName := "test-" + strings.ToLower(random.UniqueId()) - - options := &helm.Options{ - Logger: logger.Discard, - KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), - } - - output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/deployment.yaml"}) - - var deployment appsv1.Deployment - helm.UnmarshalK8SYaml(t, output, &deployment) - - assert.Equal(t, "gha-rs-controller-"+chart.Version, deployment.Labels["helm.sh/chart"]) - assert.Equal(t, chart.AppVersion, deployment.Labels["app.kubernetes.io/version"]) -} diff --git a/charts/gha-runner-scale-set-experimental/tests/template_test.go b/charts/gha-runner-scale-set-experimental/tests/template_test.go deleted file mode 100644 index 2a1aa615..00000000 --- a/charts/gha-runner-scale-set-experimental/tests/template_test.go +++ /dev/null @@ -1,61 +0,0 @@ -package tests - -import ( - "os" - "path/filepath" - "strings" - "testing" - - v1alpha1 "github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1" - "github.com/gruntwork-io/terratest/modules/helm" - "github.com/gruntwork-io/terratest/modules/k8s" - "github.com/gruntwork-io/terratest/modules/logger" - "github.com/gruntwork-io/terratest/modules/random" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "gopkg.in/yaml.v2" -) - -type Chart struct { - Version string `yaml:"version"` - AppVersion string `yaml:"appVersion"` -} - -func TestTemplate_RenderedAutoscalingRunnerSet_UsesChartMetadataLabels(t *testing.T) { - t.Parallel() - - helmChartPath, err := filepath.Abs("../../gha-runner-scale-set-experimental") - require.NoError(t, err) - - chartContent, err := os.ReadFile(filepath.Join(helmChartPath, "Chart.yaml")) - require.NoError(t, err) - - chart := new(Chart) - err = yaml.Unmarshal(chartContent, chart) - require.NoError(t, err) - - releaseName := "test-runners" - namespaceName := "test-" + strings.ToLower(random.UniqueId()) - - options := &helm.Options{ - Logger: logger.Discard, - SetValues: map[string]string{ - "scaleset.name": "test", - "auth.url": "https://github.com/actions", - "auth.githubToken": "gh_token12345", - "controllerServiceAccount.name": "arc", - "controllerServiceAccount.namespace": "arc-system", - }, - KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), - } - - output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/autoscalingrunnserset.yaml"}) - - var autoscalingRunnerSet v1alpha1.AutoscalingRunnerSet - helm.UnmarshalK8SYaml(t, output, &autoscalingRunnerSet) - - assert.Equal(t, "gha-rs-"+chart.Version, autoscalingRunnerSet.Labels["helm.sh/chart"]) - assert.Equal(t, chart.AppVersion, autoscalingRunnerSet.Labels["app.kubernetes.io/version"]) - assert.Equal(t, "gha-rs-"+chart.Version, autoscalingRunnerSet.Spec.Template.Labels["helm.sh/chart"]) - assert.Equal(t, chart.AppVersion, autoscalingRunnerSet.Spec.Template.Labels["app.kubernetes.io/version"]) -}