Skip to content

Commit

Permalink
feat(controller): allow endpoint to be specified through secret (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaspin authored Dec 4, 2024
1 parent e2b2aaa commit 364a48f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion charts/controller/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.2.0
version: 0.2.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
24 changes: 24 additions & 0 deletions charts/controller/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,27 @@ Expand the name of the default pod spec config map.
{{- end }}
{{- join " " $startupParameters }}
{{- end }}

{{/*
The name of the secret containing the endpoint URL.
By default, this is the secret created by the chart.
*/}}
{{- define "controller.endpoint.secretName" -}}
{{- if ne .Values.endpointSecret.name "" }}
{{- .Values.endpointSecret.name }}
{{- else }}
{{- include "controller.fullname" . }}
{{- end }}
{{- end }}

{{/*
The key of the secret containing the endpoint URL.
By default, this is "endpoint".
*/}}
{{- define "controller.endpoint.secretKey" -}}
{{- if ne .Values.endpointSecret.name "" }}
{{- .Values.endpointSecret.key }}
{{- else }}
{{- "endpoint" }}
{{- end }}
{{- end }}
4 changes: 2 additions & 2 deletions charts/controller/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ spec:
- name: SEMAPHORE_ENDPOINT
valueFrom:
secretKeyRef:
name: {{ include "controller.fullname" . }}
key: endpoint
name: {{ include "controller.endpoint.secretName" . }}
key: {{ include "controller.endpoint.secretKey" . }}
- name: SEMAPHORE_AGENT_IMAGE
value: "{{ .Values.agent.image }}:{{ .Values.agent.version }}"
- name: SEMAPHORE_AGENT_STARTUP_PARAMETERS
Expand Down
8 changes: 6 additions & 2 deletions charts/controller/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{- $endpoint := .Values.endpoint | required ".Values.endpoint is required." -}}
{{- if and (eq .Values.endpointSecret.name "") (eq .Values.endpoint "") }}
{{- fail "Either .Values.endpoint or .Values.endpointSecret.name must be set" }}
{{- end }}

apiVersion: v1
kind: Secret
Expand All @@ -7,7 +9,9 @@ metadata:
labels:
{{- include "controller.labels" . | nindent 4 }}
stringData:
endpoint: {{ $endpoint }}
{{- if ne .Values.endpoint "" }}
endpoint: {{ .Values.endpoint }}
{{- end }}
{{- if and .Values.agent.defaultPodSpec.preJobHook.enabled .Values.agent.defaultPodSpec.preJobHook.customScript }}
pre-job-hook: |
{{ .Values.agent.defaultPodSpec.preJobHook.customScript | b64dec | indent 4 }}
Expand Down
5 changes: 5 additions & 0 deletions charts/controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

# The Semaphore endpoint used by the controller to look into the job queue.
# This is the only required value for this chart.
# It can be specified as a raw value with .Values.endpoint,
# or as a secret with .Values.endpointSecret.name and .Values.endpointSecret.key
endpoint: ""
endpointSecret:
name: ""
key: "endpoint"

image: semaphoreci/controller
imageTag: ""
Expand Down

0 comments on commit 364a48f

Please sign in to comment.