From 4930728d4997864e582ce3aeb68026cd87342c76 Mon Sep 17 00:00:00 2001 From: Tarun Chinmai Sekar Date: Tue, 29 Aug 2023 15:31:59 -0700 Subject: [PATCH 1/3] Allow passing linodeApitoken and region as secretRef --- deploy/chart/templates/ccm-linode.yaml | 2 ++ deploy/chart/templates/daemonset.yaml | 8 ++++---- deploy/chart/values.yaml | 10 ++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/deploy/chart/templates/ccm-linode.yaml b/deploy/chart/templates/ccm-linode.yaml index 69941a50..d879ef73 100644 --- a/deploy/chart/templates/ccm-linode.yaml +++ b/deploy/chart/templates/ccm-linode.yaml @@ -1,3 +1,4 @@ +{{- if not .Values.secretRef }} apiVersion: v1 kind: Secret metadata: @@ -7,3 +8,4 @@ stringData: apiToken: {{ required ".Values.apiToken required" .Values.apiToken }} region: {{ required ".Values.region required" .Values.region }} type: Opaque +{{- end }} \ No newline at end of file diff --git a/deploy/chart/templates/daemonset.yaml b/deploy/chart/templates/daemonset.yaml index 5d1511ca..86335521 100644 --- a/deploy/chart/templates/daemonset.yaml +++ b/deploy/chart/templates/daemonset.yaml @@ -40,13 +40,13 @@ spec: - name: LINODE_API_TOKEN valueFrom: secretKeyRef: - name: ccm-linode - key: apiToken + name: {{ .Values.secretRef.name | default "ccm-linode"}} + key: {{ .Values.secretRef.apiTokenRef | default "apiToken"}} - name: LINODE_REGION valueFrom: secretKeyRef: - name: ccm-linode - key: region + name: {{ .Values.secretRef.name | default "ccm-linode"}} + key: {{ .Values.secretRef.regionRef | default "region"}} {{- toYaml .Values.env | nindent 12 }} volumes: - name: k8s diff --git a/deploy/chart/values.yaml b/deploy/chart/values.yaml index 44e5635a..790458df 100644 --- a/deploy/chart/values.yaml +++ b/deploy/chart/values.yaml @@ -1,9 +1,15 @@ -# apiToken [Required] - Must be a Linode APIv4 Personal Access Token with all permissions. (https://cloud.linode.com/profile/tokens) +# apiToken [Required if secretRef is not set] - Must be a Linode APIv4 Personal Access Token with all permissions. (https://cloud.linode.com/profile/tokens) apiToken: "" -# region [Required] - Must be a Linode region. (https://api.linode.com/v4/regions) +# region [Required if secretRef is not set] - Must be a Linode region. (https://api.linode.com/v4/regions) region: "" +# Set these values if your APIToken and region are already present in a k8s secret. +# secretRef: +# name: "linode-ccm" +# apiTokenRef: "apiToken" +# regionRef: "region" + # node-role.kubernetes.io/master - if set true, it deploys the svc on the master node nodeSelector: # The CCM will only run on a Node labelled as a master, you may want to change this From b6badd4d6a99ad431f54d94773ad278d0c7472f1 Mon Sep 17 00:00:00 2001 From: Tarun Chinmai Sekar Date: Wed, 30 Aug 2023 14:59:00 -0700 Subject: [PATCH 2/3] Allow passing linodeApitoken and region as secretRef --- deploy/chart/templates/ccm-linode.yaml | 3 ++- deploy/chart/templates/daemonset.yaml | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/deploy/chart/templates/ccm-linode.yaml b/deploy/chart/templates/ccm-linode.yaml index d879ef73..c9d83c94 100644 --- a/deploy/chart/templates/ccm-linode.yaml +++ b/deploy/chart/templates/ccm-linode.yaml @@ -8,4 +8,5 @@ stringData: apiToken: {{ required ".Values.apiToken required" .Values.apiToken }} region: {{ required ".Values.region required" .Values.region }} type: Opaque -{{- end }} \ No newline at end of file +{{- end }} + diff --git a/deploy/chart/templates/daemonset.yaml b/deploy/chart/templates/daemonset.yaml index 86335521..86d45dd5 100644 --- a/deploy/chart/templates/daemonset.yaml +++ b/deploy/chart/templates/daemonset.yaml @@ -40,15 +40,17 @@ spec: - name: LINODE_API_TOKEN valueFrom: secretKeyRef: - name: {{ .Values.secretRef.name | default "ccm-linode"}} - key: {{ .Values.secretRef.apiTokenRef | default "apiToken"}} + name: {{ if .Values.secretRef }}{{ .Values.secretRef.name | default "ccm-linode" }}{{ else }}"ccm-linode"{{ end }} + key: {{ if .Values.secretRef }}{{ .Values.secretRef.apiTokenRef | default "apiToken" }}{{ else }}"apiToken"{{ end }} - name: LINODE_REGION valueFrom: secretKeyRef: - name: {{ .Values.secretRef.name | default "ccm-linode"}} - key: {{ .Values.secretRef.regionRef | default "region"}} + name: {{ if .Values.secretRef }}{{ .Values.secretRef.name | default "ccm-linode" }}{{ else }}"ccm-linode"{{ end }} + key: {{ if .Values.secretRef }}{{ .Values.secretRef.regionRef | default "region" }}{{ else }}"region"{{ end }} + {{if .Values.env}} {{- toYaml .Values.env | nindent 12 }} + {{end}} volumes: - name: k8s hostPath: - path: /etc/kubernetes + path: /etc/kubernetes \ No newline at end of file From c0ef7a69f5e937b600d6038a2e62066b7f2d5cb5 Mon Sep 17 00:00:00 2001 From: Tarun Chinmai Sekar Date: Thu, 31 Aug 2023 12:32:10 -0700 Subject: [PATCH 3/3] Add a unit-test --- .github/workflows/test.yml | 4 ++++ Makefile | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 47df478e..fe60f0a4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,3 +16,7 @@ jobs: run: make docker-build - name: unit test run: make test + - name: helm lint + run: make helm-lint + - name: helm template + run: make helm-template \ No newline at end of file diff --git a/Makefile b/Makefile index 5bf19fff..126a0a2d 100644 --- a/Makefile +++ b/Makefile @@ -74,5 +74,33 @@ run-debug: build --stderrthreshold=INFO \ --kubeconfig=${KUBECONFIG} \ --linodego-debug - - +# Set the host's OS. Only linux and darwin supported for now +HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]') +ifeq ($(filter darwin linux,$(HOSTOS)),) +$(error build only supported on linux and darwin host currently) +endif + +HELM_VERSION ?= v3.9.1 +TOOLS_HOST_DIR ?= .tmp/tools +HELM := $(TOOLS_HOST_DIR)/helm-$(HELM_VERSION) + +.PHONY: $(HELM) +$(HELM): + @echo installing helm $(HELM_VERSION) + @mkdir -p $(TOOLS_HOST_DIR)/tmp-helm + @curl -fsSL https://get.helm.sh/helm-$(HELM_VERSION)-$(HOSTOS)-amd64.tar.gz | tar -xz -C $(TOOLS_HOST_DIR)/tmp-helm + @mv $(TOOLS_HOST_DIR)/tmp-helm/$(HOSTOS)-amd64/helm $(HELM) + @rm -fr $(TOOLS_HOST_DIR)/tmp-helm + @echo installing helm $(HELM_VERSION) + +.PHONY: helm-lint +helm-lint: $(HELM) +#Verify lint works when region and apiToken are passed, and when it is passed as reference. + @$(HELM) lint deploy/chart --set apiToken="apiToken",region="us-east" + @$(HELM) lint deploy/chart --set secretRef.apiTokenRef="apiToken",secretRef.name="api",secretRef.regionRef="us-east" + +.PHONY: helm-template +helm-template: $(HELM) +#Verify template works when region and apiToken are passed, and when it is passed as reference. + @$(HELM) template foo deploy/chart --set apiToken="apiToken",region="us-east" > /dev/null + @$(HELM) template foo deploy/chart --set secretRef.apiTokenRef="apiToken",secretRef.name="api",secretRef.regionRef="us-east" > /dev/null