Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing linodeApitoken and region as secretRef #134

Merged
merged 3 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +7 to +12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Are we passing in the values when we install the helm chart? If yes, why is this part commented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these values can be passed in when installing. This is commented to keep backwards compatibility. Existing users of the chart can continue to pass in the token and region, new users can choose to use the secretRef. Didn't want to break usersa

nodeSelector:
# The CCM will only run on a Node labelled as a master, you may want to change this
Expand Down
Loading