From e0fc5f52f50907ffc68113b4aa11dbfd94092093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mence=20Lesn=C3=A9?= Date: Thu, 30 Mar 2023 18:34:13 +0200 Subject: [PATCH] Break: Large cache directories Previous hosting was made with Deployment, now with StatefulSet. --- README.md | 2 ++ .../azure-pipelines-agent/templates/hpa.yaml | 1 + .../{deployment.yaml => statefulset.yaml} | 29 +++++++++++++++---- src/helm/azure-pipelines-agent/values.yaml | 4 ++- 4 files changed, 30 insertions(+), 6 deletions(-) rename src/helm/azure-pipelines-agent/templates/{deployment.yaml => statefulset.yaml} (75%) diff --git a/README.md b/README.md index 566e7c07..c34330a8 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ helm upgrade --install agent clemlesne-azure-pipelines-agent/azure-pipelines-age | `initContainers` | InitContainers for the agent pod. | `[]` | | `nameOverride` | Overrides release name | `""` | | `nodeSelector` | Node labels for pod assignment | `{}` | +| `pipelines.cacheSize` | Total cache the pipeline can take during execution, by default [the same amount as the Microsoft Hosted agents](https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml#hardware). | `10Gi` | +| `pipelines.cacheType` | Disk type to attach to the agents, see your cloud provider for mor details ([Azure](https://learn.microsoft.com/en-us/azure/aks/concepts-storage#storage-classes), [AWS](https://docs.aws.amazon.com/eks/latest/userguide/storage-classes.html)). | `managed-csi` (Azure compatible) | | `pipelines.pat` | Personal Access Token (PAT) used by the agent to connect. | *None* | | `pipelines.pool` | Agent pool to which the Agent should register. | *None* | | `pipelines.url` | The Azure base URL for your organization | *None* | diff --git a/src/helm/azure-pipelines-agent/templates/hpa.yaml b/src/helm/azure-pipelines-agent/templates/hpa.yaml index f18eb3fa..baf90102 100644 --- a/src/helm/azure-pipelines-agent/templates/hpa.yaml +++ b/src/helm/azure-pipelines-agent/templates/hpa.yaml @@ -22,6 +22,7 @@ metadata: {{- include "this.labels" . | nindent 4 }} spec: scaleTargetRef: + kind: StatefulSet name: {{ include "this.fullname" . }} maxReplicaCount: {{ .Values.autoscaling.maxReplicas }} minReplicaCount: {{ .Values.autoscaling.minReplicas }} diff --git a/src/helm/azure-pipelines-agent/templates/deployment.yaml b/src/helm/azure-pipelines-agent/templates/statefulset.yaml similarity index 75% rename from src/helm/azure-pipelines-agent/templates/deployment.yaml rename to src/helm/azure-pipelines-agent/templates/statefulset.yaml index 914e73a9..adbe215d 100644 --- a/src/helm/azure-pipelines-agent/templates/deployment.yaml +++ b/src/helm/azure-pipelines-agent/templates/statefulset.yaml @@ -1,16 +1,18 @@ apiVersion: apps/v1 -kind: Deployment +kind: StatefulSet metadata: name: {{ include "this.fullname" . }} labels: {{- include "this.labels" . | nindent 4 }} spec: + podManagementPolicy: Parallel {{- if not (and (.Values.autoscaling.enabled) (.Capabilities.APIVersions.Has "keda.sh/v1alpha1")) }} replicas: {{ .Values.autoscaling.minReplicas }} {{- end }} selector: matchLabels: {{- include "this.selectorLabels" . | nindent 6 }} + serviceName: {{ include "this.fullname" . }} template: metadata: labels: @@ -23,6 +25,12 @@ spec: {{- toYaml . | nindent 8 }} {{- end }} serviceAccountName: {{ include "this.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + {{- with .Values.initContainers }} + initContainers: + {{- toYaml . | nindent 8 }} + {{- end }} terminationGracePeriodSeconds: {{ .Values.autoscaling.cooldown }} containers: - name: {{ .Chart.Name }} @@ -44,7 +52,7 @@ spec: - name: AZP_POOL value: {{ .Values.pipelines.pool | quote | required "A value for .Values.pipelines.pool is required" }} - name: AZP_WORK - value: {{ .Values.pipelines.workDir | quote }} + value: {{ .Values.pipelines.workDir | quote }} - name: AZP_TOKEN valueFrom: secretKeyRef: @@ -55,10 +63,12 @@ spec: {{- end }} resources: {{- toYaml .Values.resources | nindent 12 }} - {{- if .Values.extraVolumeMounts }} volumeMounts: - {{- toYaml .Values.extraVolumeMounts | nindent 12 }} - {{- end }} + - name: workdir + mountPath: {{ .Values.pipelines.workDir | quote }} + {{- with .Values.extraVolumeMounts }} + {{- toYaml . | nindent 12 }} + {{- end }} {{- if .Values.extraVolumes }} volumes: {{- toYaml .Values.extraVolumes | nindent 8 }} @@ -75,3 +85,12 @@ spec: tolerations: {{- toYaml . | nindent 8 }} {{- end }} + volumeClaimTemplates: + - metadata: + name: workdir + spec: + accessModes: [ "ReadWriteOnce" ] + storageClassName: {{ .Values.pipelines.cacheType }} + resources: + requests: + storage: {{ .Values.pipelines.cacheSize }} diff --git a/src/helm/azure-pipelines-agent/values.yaml b/src/helm/azure-pipelines-agent/values.yaml index cd152d27..da5a21b4 100644 --- a/src/helm/azure-pipelines-agent/values.yaml +++ b/src/helm/azure-pipelines-agent/values.yaml @@ -16,9 +16,11 @@ autoscaling: cooldown: 60 pipelines: - url: null + cacheSize: 10Gi + cacheType: managed-csi pat: null pool: null + url: null workDir: _work serviceAccount: