From 497dd2b4fbb382d192c8af6ddcffefdffe9b46d0 Mon Sep 17 00:00:00 2001 From: Andrea Stacchiotti Date: Sat, 11 Jan 2025 08:47:19 +0100 Subject: [PATCH] Allow static agents to be deployed as a StatefulSet 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. --- ...oyment.yaml => gocd-agent-controller.yaml} | 26 +++++++++++--- gocd/templates/gocd-agent-homego-pvc.yaml | 4 +-- gocd/templates/gocd-agent-service.yaml | 22 ++++++++++++ gocd/values.yaml | 36 ++++++++++++++----- 4 files changed, 73 insertions(+), 15 deletions(-) rename gocd/templates/{gocd-agent-deployment.yaml => gocd-agent-controller.yaml} (89%) create mode 100644 gocd/templates/gocd-agent-service.yaml diff --git a/gocd/templates/gocd-agent-deployment.yaml b/gocd/templates/gocd-agent-controller.yaml similarity index 89% rename from gocd/templates/gocd-agent-deployment.yaml rename to gocd/templates/gocd-agent-controller.yaml index e13dcc6..7b2e25d 100644 --- a/gocd/templates/gocd-agent-deployment.yaml +++ b/gocd/templates/gocd-agent-controller.yaml @@ -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: @@ -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: @@ -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: @@ -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 -}} diff --git a/gocd/templates/gocd-agent-homego-pvc.yaml b/gocd/templates/gocd-agent-homego-pvc.yaml index 1a3133f..a885315 100644 --- a/gocd/templates/gocd-agent-homego-pvc.yaml +++ b/gocd/templates/gocd-agent-homego-pvc.yaml @@ -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: diff --git a/gocd/templates/gocd-agent-service.yaml b/gocd/templates/gocd-agent-service.yaml new file mode 100644 index 0000000..8a56866 --- /dev/null +++ b/gocd/templates/gocd-agent-service.yaml @@ -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 }} diff --git a/gocd/values.yaml b/gocd/values.yaml index 4cefc48..48fedee 100644 --- a/gocd/values.yaml +++ b/gocd/values.yaml @@ -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 @@ -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 @@ -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