Skip to content

Commit f4c26ea

Browse files
committed
SCALRCORE-35910 rework agent-job template; update documentation
1 parent 6af669e commit f4c26ea

23 files changed

+1436
-827
lines changed

charts/agent-docker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ the same Kubernetes cluster to increase overall capacity.
8080
| tolerations | list | `[]` | Tolerations for the Scalr Agent pods, allowing them to run on tainted nodes |
8181

8282
----------------------------------------------
83-
Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0)
83+
Autogenerated from chart metadata using [helm-docs v1.14.2](https://github.com/norwoodj/helm-docs/releases/v1.14.2)

charts/agent-job/Chart.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ apiVersion: v2
22
name: agent-job
33
description: |
44
A Helm chart for deploying the Scalr Agent on a Kubernetes cluster.
5-
Uses a controller/worker model. Each run stage is isolated
6-
in Kubernetes containers with specified resource limits.
5+
It uses a job-based model, where each Scalr Run is isolated
6+
in its own Kubernetes Job.
77
type: application
8+
icon: https://raw.githubusercontent.com/Scalr/agent-helm/master/charts/agent-job/assets/icon.ico
89
version: 0.5.62
910
appVersion: 0.55.2
1011
home: https://github.com/Scalr/agent-helm/tree/master/charts/agent-job
1112
maintainers:
1213
- name: scalr
1314
15+
sources: ["https://github.com/Scalr/agent-helm/tree/master/charts/agent-job"]

charts/agent-job/README.md

Lines changed: 289 additions & 222 deletions
Large diffs are not rendered by default.

charts/agent-job/README.md.gotmpl

Lines changed: 146 additions & 123 deletions
Large diffs are not rendered by default.

charts/agent-job/assets/icon.ico

4.19 KB
Binary file not shown.

charts/agent-job/templates/_helpers.tpl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,53 @@ Create the name of the service account to use
6060
{{- default "default" .Values.serviceAccount.name }}
6161
{{- end }}
6262
{{- end }}
63+
64+
{{/*
65+
Generate a stable, release-scoped name for chart sub-components.
66+
*/}}
67+
{{- define "agent-job.componentName" -}}
68+
{{- printf "%s-%s" (include "agent-job.fullname" .context) .component | trunc 63 | trimSuffix "-" }}
69+
{{- end }}
70+
71+
{{/*
72+
Resolve the data PVC name, falling back to the chart-managed default.
73+
*/}}
74+
{{- define "agent-job.dataPVCName" -}}
75+
{{- if .Values.persistence.data.persistentVolumeClaim.claimName }}
76+
{{- .Values.persistence.data.persistentVolumeClaim.claimName -}}
77+
{{- else }}
78+
{{- printf "%s-data" (include "agent-job.fullname" .) -}}
79+
{{- end }}
80+
{{- end }}
81+
82+
{{/*
83+
Resolve the cache PVC name, falling back to the chart-managed default.
84+
*/}}
85+
{{- define "agent-job.cachePVCName" -}}
86+
{{- if .Values.persistence.cache.persistentVolumeClaim.claimName }}
87+
{{- .Values.persistence.cache.persistentVolumeClaim.claimName -}}
88+
{{- else }}
89+
{{- printf "%s-cache" (include "agent-job.fullname" .) -}}
90+
{{- end }}
91+
{{- end }}
92+
93+
{{/*
94+
Convert Kubernetes quantity to megabytes
95+
Supports: Gi, Mi, G, M
96+
*/}}
97+
{{- define "agent-job.sizeToMB" -}}
98+
{{- $size := . -}}
99+
{{- if hasSuffix "Gi" $size -}}
100+
{{- $val := trimSuffix "Gi" $size | float64 -}}
101+
{{- $val | mul 1024 | int -}}
102+
{{- else if hasSuffix "Mi" $size -}}
103+
{{- trimSuffix "Mi" $size | int -}}
104+
{{- else if hasSuffix "G" $size -}}
105+
{{- $val := trimSuffix "G" $size | float64 -}}
106+
{{- $val | mul 1000 | int -}}
107+
{{- else if hasSuffix "M" $size -}}
108+
{{- trimSuffix "M" $size | int -}}
109+
{{- else -}}
110+
{{- fail (printf "Unsupported size format: %s. Use Gi, Mi, G, or M" $size) -}}
111+
{{- end -}}
112+
{{- end -}}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: scalr-agent
5+
namespace: {{ .Release.Namespace | quote }}
6+
labels:
7+
{{- include "agent-job.labels" . | nindent 4 }}
8+
app.kubernetes.io/component: agent
9+
spec:
10+
replicas: {{ .Values.agent.replicaCount }}
11+
selector:
12+
matchLabels:
13+
{{- include "agent-job.selectorLabels" . | nindent 6 }}
14+
app.kubernetes.io/component: agent
15+
template:
16+
metadata:
17+
annotations:
18+
{{- with (merge (deepCopy .Values.global.podAnnotations) .Values.agent.podAnnotations) }}
19+
{{- toYaml . | nindent 8 }}
20+
{{- end }}
21+
{{- if not .Values.agent.tokenExistingSecret.name }}
22+
checksum/secrets: {{ include (print $.Template.BasePath "/secrets.yaml") . | sha256sum }}
23+
{{- end }}
24+
labels:
25+
{{- with .Values.global.podLabels }}
26+
{{- toYaml . | nindent 12 }}
27+
{{- end }}
28+
{{- with .Values.agent.podLabels }}
29+
{{- toYaml . | nindent 12 }}
30+
{{- end }}
31+
{{- include "agent-job.selectorLabels" . | nindent 8 }}
32+
app.kubernetes.io/component: agent
33+
spec:
34+
{{- with .Values.global.imagePullSecrets }}
35+
imagePullSecrets:
36+
{{- toYaml . | nindent 8 }}
37+
{{- end }}
38+
serviceAccountName: {{ include "agent-job.serviceAccountName" . }}
39+
automountServiceAccountToken: {{ .Values.serviceAccount.automountToken }}
40+
{{- $controllerPodSecurityContext := merge (deepCopy (default (dict) .Values.global.podSecurityContext)) (default (dict) .Values.agent.podSecurityContext) }}
41+
{{- if not (empty $controllerPodSecurityContext) }}
42+
securityContext:
43+
{{- toYaml $controllerPodSecurityContext | nindent 8 }}
44+
{{- end }}
45+
containers:
46+
- name: controller
47+
{{- $registry := .Values.global.imageRegistry }}
48+
{{- $image := .Values.agent.image }}
49+
{{- if $registry }}
50+
image: "{{ $registry }}/{{ $image.repository }}:{{ $image.tag | default .Chart.AppVersion }}"
51+
{{- else }}
52+
image: "{{ $image.repository }}:{{ $image.tag | default .Chart.AppVersion }}"
53+
{{- end }}
54+
imagePullPolicy: {{ $image.pullPolicy }}
55+
command: ["python", "-m", "tacoagent.cmd"]
56+
{{- with .Values.agent.controller.securityContext }}
57+
securityContext:
58+
{{- toYaml . | nindent 12 }}
59+
{{- end }}
60+
env:
61+
- name: SCALR_URL
62+
value: {{ .Values.agent.url | quote }}
63+
- name: SCALR_AGENT_TOKEN
64+
valueFrom:
65+
secretKeyRef:
66+
name: {{ .Values.agent.tokenExistingSecret.name | default (include "agent-job.fullname" .) }}
67+
key: {{ .Values.agent.tokenExistingSecret.key }}
68+
optional: false
69+
- name: SCALR_AGENT_NAME
70+
valueFrom:
71+
fieldRef:
72+
fieldPath: metadata.name
73+
- name: SCALR_AGENT_DEBUG
74+
value: {{ .Values.agent.debug | quote }}
75+
- name: SCALR_AGENT_LOG_FORMAT
76+
value: {{ .Values.agent.logFormat | quote }}
77+
- name: SCALR_AGENT_DATA_DIR
78+
value: {{ .Values.agent.dataDir | quote }}
79+
- name: SCALR_AGENT_CACHE_DIR
80+
value: {{ .Values.agent.cacheDir | quote }}
81+
- name: SCALR_AGENT_DRIVER
82+
value: "kubernetes-job"
83+
- name: SCALR_AGENT_KUBERNETES_JOB_TEMPLATE
84+
value: "scalr-agent-task"
85+
{{- $telemetry := .Values.otel -}}
86+
{{- if and $telemetry.enabled $telemetry.endpoint }}
87+
- name: SCALR_AGENT_OTLP_ENDPOINT
88+
value: {{ $telemetry.endpoint | quote }}
89+
{{- if $telemetry.metricsEnabled }}
90+
- name: SCALR_AGENT_OTLP_METRICS_ENABLED
91+
value: "true"
92+
{{- end }}
93+
{{- if $telemetry.tracesEnabled }}
94+
- name: SCALR_AGENT_OTLP_TRACES_ENABLED
95+
value: "true"
96+
{{- end }}
97+
{{- end }}
98+
{{- range $key, $value := .Values.agent.extraEnv }}
99+
- name: {{ $key }}
100+
value: {{ $value | quote }}
101+
{{- end }}
102+
{{- with .Values.agent.controller.extraEnv }}
103+
{{- toYaml . | nindent 12 }}
104+
{{- end }}
105+
{{- with .Values.agent.controller.extraEnvFrom }}
106+
envFrom:
107+
{{- toYaml . | nindent 12 }}
108+
{{- end }}
109+
resources:
110+
{{- toYaml .Values.agent.resources | nindent 12 }}
111+
volumeMounts:
112+
- name: data-dir
113+
mountPath: {{ .Values.agent.dataDir | quote }}
114+
- name: cache-dir
115+
mountPath: {{ .Values.agent.cacheDir | quote }}
116+
- name: tmp-dir
117+
mountPath: /tmp
118+
{{- with .Values.agent.nodeSelector }}
119+
nodeSelector:
120+
{{- toYaml . | nindent 8 }}
121+
{{- end }}
122+
{{- with .Values.agent.tolerations }}
123+
tolerations:
124+
{{- toYaml . | nindent 8 }}
125+
{{- end }}
126+
{{- with .Values.agent.affinity }}
127+
affinity:
128+
{{- toYaml . | nindent 8 }}
129+
{{- end }}
130+
volumes:
131+
# Note: Controllers have ephemeral data/cache volumes. They are not intended for real use, as agents
132+
# in controller mode do not perform actual workloads.
133+
- name: data-dir
134+
emptyDir: {}
135+
- name: cache-dir
136+
emptyDir: {}
137+
# Note: Default pod's /tmp may not be writable depending on securityContext settings.
138+
# It is more robust to mount a dedicated volume.
139+
- name: tmp-dir
140+
emptyDir: {}
141+
terminationGracePeriodSeconds: {{ .Values.agent.terminationGracePeriodSeconds }}

charts/agent-job/templates/controller.yaml

Lines changed: 0 additions & 101 deletions
This file was deleted.
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
{{- if .Values.restrictMetadataService }}
1+
{{- if not .Values.task.allowMetadataService }}
22
apiVersion: networking.k8s.io/v1
33
kind: NetworkPolicy
44
metadata:
5-
name: agent-job-network-policy
5+
name: {{ include "agent-job.fullname" . }}-task-network-policy
66
namespace: {{ .Release.Namespace | quote }}
7+
labels:
8+
{{- include "agent-job.labels" . | nindent 4 }}
9+
app.kubernetes.io/component: task
710
spec:
811
podSelector:
912
matchLabels:
1013
{{- include "agent-job.selectorLabels" . | nindent 6 }}
14+
app.kubernetes.io/component: task
1115
policyTypes:
1216
- Egress
1317
egress:
@@ -16,6 +20,6 @@ spec:
1620
# Allow all egress traffic by default
1721
cidr: 0.0.0.0/0
1822
except:
19-
# Deny access to IMDS
23+
# Deny access to VM metadata service (IMDS)
2024
- 169.254.169.254/32
2125
{{- end }}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{{- if and (gt (int .Values.agent.replicaCount) 1) .Values.agent.podDisruptionBudget.enabled }}
2+
apiVersion: policy/v1
3+
kind: PodDisruptionBudget
4+
metadata:
5+
name: {{ include "agent-job.fullname" . }}-agent
6+
namespace: {{ .Release.Namespace | quote }}
7+
labels:
8+
{{- include "agent-job.labels" . | nindent 4 }}
9+
app.kubernetes.io/component: agent
10+
spec:
11+
{{- if .Values.agent.podDisruptionBudget.minAvailable }}
12+
minAvailable: {{ .Values.agent.podDisruptionBudget.minAvailable }}
13+
{{- end }}
14+
{{- if .Values.agent.podDisruptionBudget.maxUnavailable }}
15+
maxUnavailable: {{ .Values.agent.podDisruptionBudget.maxUnavailable }}
16+
{{- end }}
17+
selector:
18+
matchLabels:
19+
{{- include "agent-job.selectorLabels" . | nindent 6 }}
20+
app.kubernetes.io/component: agent
21+
{{- end }}

0 commit comments

Comments
 (0)