Skip to content

Commit

Permalink
Merge pull request #134 from schinmai-akamai/master
Browse files Browse the repository at this point in the history
Allow passing linodeApitoken and region as secretRef
  • Loading branch information
srust authored Sep 1, 2023
2 parents 0427d17 + c0ef7a6 commit aec305f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 30 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions deploy/chart/templates/ccm-linode.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if not .Values.secretRef }}
apiVersion: v1
kind: Secret
metadata:
Expand All @@ -7,3 +8,5 @@ stringData:
apiToken: {{ required ".Values.apiToken required" .Values.apiToken }}
region: {{ required ".Values.region required" .Values.region }}
type: Opaque
{{- end }}

12 changes: 7 additions & 5 deletions deploy/chart/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ spec:
- name: LINODE_API_TOKEN
valueFrom:
secretKeyRef:
name: ccm-linode
key: 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: ccm-linode
key: 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
10 changes: 8 additions & 2 deletions deploy/chart/values.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit aec305f

Please sign in to comment.