diff --git a/.github/workflows/helm.yml b/.github/workflows/helm.yml index 2d10804a..e46e677f 100644 --- a/.github/workflows/helm.yml +++ b/.github/workflows/helm.yml @@ -40,6 +40,9 @@ jobs: - name: Set up chart-testing uses: helm/chart-testing-action@6ec842c01de15ebb84c8627d2744a0c2f2755c9f # v2.8.0 + - name: Test numeric ID arguments + run: bash hack/test-helm-id-args.sh + - name: Run chart-testing (lint) run: ct lint --check-version-increment=false --chart-dirs deploy --target-branch ${{ github.event.repository.default_branch }} diff --git a/deploy/chart/templates/_helpers.tpl b/deploy/chart/templates/_helpers.tpl index 7ba5edc2..f9e7e5b8 100644 --- a/deploy/chart/templates/_helpers.tpl +++ b/deploy/chart/templates/_helpers.tpl @@ -60,3 +60,12 @@ Create the name of the service account to use {{- default "default" .Values.serviceAccount.name }} {{- end }} {{- end }} + +{{/* Format numeric IDs as decimal while preserving comma-separated string values. */}} +{{- define "ccm-linode.idArg" -}} +{{- if kindIs "string" .value -}} +{{ printf "%s=%s" .flag .value | quote }} +{{- else -}} +{{ printf "%s=%d" .flag (int64 .value) | quote }} +{{- end -}} +{{- end -}} diff --git a/deploy/chart/templates/daemonset.yaml b/deploy/chart/templates/daemonset.yaml index 2c7e217a..8095ebfa 100644 --- a/deploy/chart/templates/daemonset.yaml +++ b/deploy/chart/templates/daemonset.yaml @@ -119,7 +119,7 @@ spec: - --nodebalancer-backend-ipv4-subnet-name={{ $nbvpcBackendIpv4SubnetName }} {{- end }} {{- if $nbvpcBackendIpv4SubnetID }} - - --nodebalancer-backend-ipv4-subnet-id={{ $nbvpcBackendIpv4SubnetID }} + - {{ include "ccm-linode.idArg" (dict "flag" "--nodebalancer-backend-ipv4-subnet-id" "value" $nbvpcBackendIpv4SubnetID) }} {{- end }} {{- if .Values.routeController }} - --enable-route-controller=true @@ -151,10 +151,10 @@ spec: - --subnet-names={{ . }} {{- end }} {{- with $vpcIDs }} - - --vpc-ids={{ . }} + - {{ include "ccm-linode.idArg" (dict "flag" "--vpc-ids" "value" .) }} {{- end }} {{- with $subnetIDs }} - - --subnet-ids={{ . }} + - {{ include "ccm-linode.idArg" (dict "flag" "--subnet-ids" "value" .) }} {{- end }} {{- with $clusterCIDR }} - --cluster-cidr={{ . }} diff --git a/hack/test-helm-id-args.sh b/hack/test-helm-id-args.sh new file mode 100644 index 00000000..da0e29ed --- /dev/null +++ b/hack/test-helm-id-args.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +set -euo pipefail + +assert_contains() { + case "$rendered" in + *"$1"*) ;; + *) printf 'expected rendered chart to contain: %s\n' "$1" >&2; exit 1 ;; + esac +} + +assert_no_scientific_ids() { + case "$rendered" in + *'1.054213e+06'*|*'1.054214e+06'*|*'1.054215e+06'*) + printf 'rendered chart contains a scientific-notation ID\n' >&2 + exit 1 + ;; + esac +} + +rendered=$(helm template ccm-linode deploy/chart \ + --set-json 'vpcIDs=1.054213e+06' \ + --set-json 'subnetIDs=1.054214e+06' \ + --set-json 'nodeBalancerBackendIpv4SubnetID=1.054215e+06') +assert_contains '"--vpc-ids=1054213"' +assert_contains '"--subnet-ids=1054214"' +assert_contains '"--nodebalancer-backend-ipv4-subnet-id=1054215"' +assert_no_scientific_ids + +rendered=$(helm template ccm-linode deploy/chart \ + --set-json 'routeController.vpcIDs=1.054213e+06' \ + --set-json 'routeController.subnetIDs=1.054214e+06' \ + --set 'routeController.clusterCIDR=10.192.0.0/10') +assert_contains '"--vpc-ids=1054213"' +assert_contains '"--subnet-ids=1054214"' +assert_no_scientific_ids + +rendered=$(helm template ccm-linode deploy/chart \ + --set-string 'vpcIDs=1054213\,1054214' \ + --set-string 'subnetIDs=1054215\,1054216') +assert_contains '"--vpc-ids=1054213,1054214"' +assert_contains '"--subnet-ids=1054215,1054216"'