Skip to content

Commit

Permalink
Fix: Agents cannot scale
Browse files Browse the repository at this point in the history
See #5.
  • Loading branch information
clemlesne committed Apr 15, 2023
1 parent bf66ab3 commit ec5ab65
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
16 changes: 14 additions & 2 deletions src/helm/azure-pipelines-agent/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ Create the name of the service account to use
{{- end }}
{{- end }}

{{/*
Common definition for Pod object.
Usage example:
{{- $data := dict
"restartPolicy" "Always"
"azpAgentName" (dict "value" (printf "%s-%s" (include "this.fullname" .) "template"))
}}
{{- include "this.podSharedTemplate" (merge (dict "Args" $data) . ) | nindent 6 }}
*/}}
{{- define "this.podSharedTemplate" -}}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
Expand All @@ -76,6 +87,7 @@ initContainers:
{{- toYaml . | nindent 2 }}
{{- end }}
terminationGracePeriodSeconds: {{ .Values.pipelines.timeout | int | required "A value for .Values.pipelines.timeout is required" }}
restartPolicy: {{ .Args.restartPolicy }}
containers:
- name: azp-agent
securityContext:
Expand All @@ -88,12 +100,12 @@ containers:
lifecycle:
preStop:
exec:
command: [bash, -c, "bash ${AZP_HOME}/config.sh remove --auth PAT --token $AZP_TOKEN"]
command: [bash, -c, "bash ${AZP_HOME}/config.sh remove --auth PAT --token ${AZP_TOKEN}"]
env:
- name: VSO_AGENT_IGNORE
value: AZP_TOKEN
- name: AZP_AGENT_NAME
value: {{ include "this.fullname" . }}-template
{{- toYaml .Args.azpAgentName | nindent 8 }}
- name: AZP_URL
valueFrom:
secretKeyRef:
Expand Down
8 changes: 5 additions & 3 deletions src/helm/azure-pipelines-agent/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
# The pod will shut down at each run, we need to restart it
restartPolicy: Always
{{- include "this.podSharedTemplate" . | nindent 6 }}
{{- $data := dict
"restartPolicy" "Always"
"azpAgentName" (dict "valueFrom" (dict "fieldRef" (dict "apiVersion" "v1" "fieldPath" "metadata.name" )))
}}
{{- include "this.podSharedTemplate" (merge (dict "Args" $data) . ) | nindent 6 }}
{{- end }}
8 changes: 5 additions & 3 deletions src/helm/azure-pipelines-agent/templates/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ spec:
{{- toYaml . | nindent 10 }}
{{- end }}
spec:
# The job cannot crash, this is not functionally intended; a shutdown is functionally a pipeline end
restartPolicy: Never
{{- include "this.podSharedTemplate" . | nindent 8 }}
{{- $data := dict
"restartPolicy" "Never"
"azpAgentName" (dict "valueFrom" (dict "fieldRef" (dict "apiVersion" "v1" "fieldPath" "metadata.name" )))
}}
{{- include "this.podSharedTemplate" (merge (dict "Args" $data) . ) | nindent 8 }}
maxReplicaCount: {{ .Values.autoscaling.maxReplicas | int | required "A value for .Values.autoscaling.maxReplicas is required" }}
minReplicaCount: 0
pollingInterval: 15
Expand Down
8 changes: 5 additions & 3 deletions src/helm/azure-pipelines-agent/templates/pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
# This agent is a template, we privilegiate Jobs instead of it, but we need to run it first
restartPolicy: Never
{{- include "this.podSharedTemplate" . | nindent 2 }}
{{- $data := dict
"restartPolicy" "Never"
"azpAgentName" (dict "value" (printf "%s-%s" (include "this.fullname" .) "template"))
}}
{{- include "this.podSharedTemplate" (merge (dict "Args" $data) . ) | nindent 2 }}
{{- end }}

0 comments on commit ec5ab65

Please sign in to comment.