Skip to content

Commit

Permalink
Allow static agents to be deployed as a StatefulSet
Browse files Browse the repository at this point in the history
And as a DaemonSet.
Support specifying volumeClaimTemplates, which allow static agents to keep their identity at restart

Some value keys have been renamed for consistency.
  • Loading branch information
12345ieee committed Jan 11, 2025
1 parent d1a96f8 commit 497dd2b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{- if .Values.agent.enabled -}}
apiVersion: apps/v1
kind: Deployment
kind: {{ .Values.agent.controller.kind }}
metadata:
name: {{ template "gocd.fullname" . }}-agent
labels:
Expand All @@ -8,18 +9,30 @@ metadata:
release: {{ .Release.Name | quote }}
heritage: {{ .Release.Service | quote }}
component: agent
{{- with .Values.agent.deployment.labels }}
{{- with .Values.agent.controller.labels }}
{{ toYaml . | indent 4 }}
{{- end }}
annotations:
{{- range $key, $value := .Values.agent.annotations.deployment }}
{{- range $key, $value := .Values.agent.controller.annotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
spec:
{{- if (eq .Values.agent.controller.kind "StatefulSet") }}
serviceName: {{ template "gocd.fullname" . }}-agent
{{- end }}
{{- if not (eq .Values.agent.controller.kind "DaemonSet") }}
replicas: {{ .Values.agent.replicaCount }}
{{- end }}
{{- if .Values.agent.deployStrategy }}
{{- if (eq .Values.agent.controller.kind "Deployment") }}
strategy:
{{- else }}
updateStrategy:
{{- end }}
{{ toYaml .Values.agent.deployStrategy | indent 4 }}
{{- end }}
{{- if (eq .Values.agent.controller.kind "StatefulSet") }}
podManagementPolicy: Parallel
{{- end }}
selector:
matchLabels:
Expand All @@ -36,7 +49,7 @@ spec:
{{ toYaml . | indent 8 }}
{{- end }}
annotations:
{{- range $key, $value := .Values.agent.annotations.pod }}
{{- range $key, $value := .Values.agent.pod.annotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
spec:
Expand Down Expand Up @@ -190,3 +203,8 @@ spec:
hostAliases:
{{ toYaml .Values.agent.hostAliases | indent 8 }}
{{- end }}
{{- if and (eq .Values.agent.controller.kind "StatefulSet") .Values.agent.persistence.claimTemplates }}
volumeClaimTemplates:
{{ toYaml .Values.agent.persistence.claimTemplates | indent 4 }}
{{- end }}
{{- end -}}
4 changes: 2 additions & 2 deletions gocd/templates/gocd-agent-homego-pvc.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- if and .Values.agent.persistence.enabled (not .Values.agent.persistence.existingClaim) -}}
kind: PersistentVolumeClaim
{{- if and .Values.agent.enabled .Values.agent.persistence.enabled (not .Values.agent.persistence.existingClaim) -}}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ template "gocd.fullname" . }}-agent
labels:
Expand Down
22 changes: 22 additions & 0 deletions gocd/templates/gocd-agent-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{- if and .Values.agent.enabled (eq .Values.agent.controller.kind "StatefulSet") -}}
apiVersion: v1
kind: Service
metadata:
name: {{ template "gocd.fullname" . }}-agent
labels:
app: {{ template "gocd.name" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: {{ .Release.Name | quote }}
heritage: {{ .Release.Service | quote }}
component: agent
spec:
clusterIP: None
ports:
- protocol: TCP
port: 8152
targetPort: 8152
selector:
app: {{ template "gocd.name" . }}
release: {{ .Release.Name | quote }}
component: agent
{{- end }}
36 changes: 27 additions & 9 deletions gocd/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ server:
defaultMode:

agent:
# agent.enabled is the toggle to deploy static GoCD Agents. Change to false for Server Only Deployment.
enabled: true

# specifies overrides for agent specific service account creation
serviceAccount:
# specifies whether the top level service account (also used by the server) should be reused as the service account for gocd agents
Expand All @@ -264,18 +267,20 @@ agent:
name:
automountServiceAccountToken: false

# agent.deployment.labels is the labels for the GoCD Agent Deployment
deployment:
controller:
# agent.controller.kind is the type of controller used to deploy Agents. Use either Deployment (default), StatefulSet or DaemonSet
kind: "Deployment"
# agent.controller.labels is the labels for the GoCD Agent controller
labels: {}
# agent.pod.labels is the labels for the GoCD Agent Pods
# agent.controller.annotations is the annotations for the GoCD Agent controller
annotations:
# iam.amazonaws.com/role: arn:aws:iam::xxx:role/my-custom-role

pod:
# agent.pod.labels is the labels for the GoCD Agent Pods
labels: {}

# agent.annotations is the annotations for the GoCD Agent Deployment and Pod Spec
annotations:
deployment:
# iam.amazonaws.com/role: arn:aws:iam::xxx:role/my-custom-role
pod:
# agent.pod.annotations is the annotations for the GoCD Agent Pods
annotations:
# iam.amazonaws.com/role: arn:aws:iam::xxx:role/my-custom-role

# Specify security settings for GoCD Agent Pod
Expand Down Expand Up @@ -370,8 +375,21 @@ agent:
# secretName: github-key
# defaultMode: 0744

# agent.persistence.claimTemplates additional volumes dedicated to each replica
claimTemplates: []
# - metadata:
# name: godata
# spec:
# accessModes: ["ReadWriteOnce"]
# resources:
# requests:
# storage: 1Gi
# storageClassName: storageClassName

# agent.persistence.extraVolumeMounts additional agent volumeMounts
extraVolumeMounts: []
# - name: godata
# mountPath: /godata
# - name: github-key
# mountPath: /etc/config/keys/
# readOnly: true
Expand Down

0 comments on commit 497dd2b

Please sign in to comment.