Skip to content

Commit 2a74de8

Browse files
authored
Fix deployment templates (#547)
1 parent d39dbbb commit 2a74de8

File tree

8 files changed

+260
-7
lines changed

8 files changed

+260
-7
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.22-alpine
1+
FROM golang:1.23-alpine
22

33
WORKDIR /draft
44

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: testapp
5+
labels:
6+
app.kubernetes.io/name: testapp
7+
kubernetes.azure.com/generator: draft
8+
namespace: default
9+
spec:
10+
replicas: 1
11+
selector:
12+
matchLabels:
13+
app.kubernetes.io/name: testapp
14+
template:
15+
metadata:
16+
labels:
17+
app.kubernetes.io/name: testapp
18+
azure.workload.identity/use: "true"
19+
spec:
20+
serviceAccountName: testsa
21+
containers:
22+
- name: testapp
23+
image: testimage:latest
24+
imagePullPolicy: Always
25+
ports:
26+
- containerPort: 80
27+
resources:
28+
requests:
29+
cpu: "0.5"
30+
memory: "0.5Gi"
31+
limits:
32+
cpu: "1"
33+
memory: "1Gi"
34+
envFrom:
35+
- configMapRef:
36+
name: testapp-config
37+
- secretRef:
38+
name: secret-ref
39+
optional: true
40+
livenessProbe:
41+
tcpSocket:
42+
port: 80
43+
readinessProbe:
44+
tcpSocket:
45+
port: 80
46+
periodSeconds: 5
47+
timeoutSeconds: 5
48+
failureThreshold: 1
49+
successThreshold: 1
50+
initialDelaySeconds: 3
51+
startupProbe:
52+
tcpSocket:
53+
port: 80
54+
periodSeconds: 10
55+
timeoutSeconds: 1
56+
failureThreshold: 3
57+
successThreshold: 1
58+
initialDelaySeconds: 0
59+
securityContext:
60+
seccompProfile:
61+
type: RuntimeDefault
62+
capabilities:
63+
drop:
64+
- ALL
65+
add:
66+
- SETPCAP
67+
- MKNOD
68+
- AUDIT_WRITE
69+
- CHOWN
70+
- DAC_OVERRIDE
71+
- FOWNER
72+
- FSETID
73+
- KILL
74+
- SETGID
75+
- SETUID
76+
- NET_BIND_SERVICE
77+
- SYS_CHROOT
78+
- SETFCAP
79+
- SYS_PTRACE
80+
affinity:
81+
podAntiAffinity:
82+
preferredDuringSchedulingIgnoredDuringExecution:
83+
- weight: 100
84+
podAffinityTerm:
85+
topologyKey: kubernetes.io/hostname
86+
labelSelector:
87+
matchLabels:
88+
app.kubernetes.io/name: testapp
89+
topologySpreadConstraints:
90+
- maxSkew: 1
91+
topologyKey: kubernetes.io/hostname
92+
whenUnsatisfiable: ScheduleAnyway
93+
labelSelector:
94+
matchLabels:
95+
app.kubernetes.io/name: testapp
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: testapp
5+
labels:
6+
app.kubernetes.io/name: testapp
7+
kubernetes.azure.com/generator: draft
8+
namespace: default
9+
spec:
10+
selector:
11+
matchLabels:
12+
app.kubernetes.io/name: testapp
13+
template:
14+
spec:
15+
containers:
16+
- name: testapp
17+
image: testimage:latest
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: testapp
5+
labels:
6+
app.kubernetes.io/name: testapp
7+
kubernetes.azure.com/generator: draft
8+
namespace: default
9+
spec:
10+
replicas: 1
11+
selector:
12+
matchLabels:
13+
app.kubernetes.io/name: testapp
14+
template:
15+
metadata:
16+
labels:
17+
app.kubernetes.io/name: testapp
18+
azure.workload.identity/use: "true"
19+
spec:
20+
serviceAccountName: testsa
21+
containers:
22+
- name: testapp
23+
image: testimage:latest
24+
imagePullPolicy: Always
25+
ports:
26+
- containerPort: 80
27+
resources:
28+
requests:
29+
cpu: "0.5"
30+
memory: "0.5Gi"
31+
limits:
32+
cpu: "1"
33+
memory: "1Gi"
34+
envFrom:
35+
- configMapRef:
36+
name: testapp-config
37+
- secretRef:
38+
name: secret-ref
39+
optional: true
40+
livenessProbe:
41+
tcpSocket:
42+
port: 80
43+
readinessProbe:
44+
tcpSocket:
45+
port: 80
46+
periodSeconds: 5
47+
timeoutSeconds: 5
48+
failureThreshold: 1
49+
successThreshold: 1
50+
initialDelaySeconds: 3
51+
startupProbe:
52+
tcpSocket:
53+
port: 80
54+
periodSeconds: 10
55+
timeoutSeconds: 1
56+
failureThreshold: 3
57+
successThreshold: 1
58+
initialDelaySeconds: 0
59+
securityContext:
60+
seccompProfile:
61+
type: RuntimeDefault
62+
capabilities:
63+
drop:
64+
- ALL
65+
add:
66+
- SETPCAP
67+
- MKNOD
68+
- AUDIT_WRITE
69+
- CHOWN
70+
- DAC_OVERRIDE
71+
- FOWNER
72+
- FSETID
73+
- KILL
74+
- SETGID
75+
- SETUID
76+
- NET_BIND_SERVICE
77+
- SYS_CHROOT
78+
- SETFCAP
79+
- SYS_PTRACE
80+
affinity:
81+
podAntiAffinity:
82+
preferredDuringSchedulingIgnoredDuringExecution:
83+
- weight: 100
84+
podAffinityTerm:
85+
topologyKey: kubernetes.io/hostname
86+
labelSelector:
87+
matchLabels:
88+
app.kubernetes.io/name: testapp
89+
topologySpreadConstraints:
90+
- maxSkew: 1
91+
topologyKey: kubernetes.io/hostname
92+
whenUnsatisfiable: ScheduleAnyway
93+
labelSelector:
94+
matchLabels:
95+
app.kubernetes.io/name: testapp

pkg/handlers/templatetests/deployment_kustomize_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,28 @@ func TestDeploymentKustomizeTemplates(t *testing.T) {
2525
"SERVICEPORT": "80",
2626
},
2727
},
28+
{
29+
Name: "valid kustomize deployment with workload identity enabled",
30+
TemplateName: "deployment-kustomize",
31+
FixturesBaseDir: "../../fixtures/deployments/kustomize",
32+
Version: "0.0.1",
33+
Dest: ".",
34+
TemplateWriter: &writers.FileMapWriter{},
35+
VarMap: map[string]string{
36+
"APPNAME": "testapp",
37+
"NAMESPACE": "default",
38+
"PORT": "80",
39+
"IMAGENAME": "testimage",
40+
"IMAGETAG": "latest",
41+
"GENERATORLABEL": "draft",
42+
"SERVICEPORT": "80",
43+
"ENABLEWORKLOADIDENTITY": "true",
44+
"SERVICEACCOUNT": "testsa",
45+
},
46+
FileNameOverride: map[string]string{
47+
"deployment.yaml": "deployment-override-workload-identity.yaml",
48+
},
49+
},
2850
}
2951

3052
for _, test := range tests {

pkg/handlers/templatetests/deployment_manifest_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ func TestDeploymentManifestTemplates(t *testing.T) {
2727
"ENVVARS": `{"key1":"value1","key2":"value2"}`,
2828
},
2929
},
30+
{
31+
Name: "valid manifest deployment with workload identity enabled",
32+
TemplateName: "deployment-manifests",
33+
FixturesBaseDir: "../../fixtures/deployments/manifest",
34+
Version: "0.0.1",
35+
Dest: ".",
36+
TemplateWriter: &writers.FileMapWriter{},
37+
VarMap: map[string]string{
38+
"APPNAME": "testapp",
39+
"NAMESPACE": "default",
40+
"PORT": "80",
41+
"IMAGENAME": "testimage",
42+
"IMAGETAG": "latest",
43+
"GENERATORLABEL": "draft",
44+
"SERVICEPORT": "80",
45+
"ENVVARS": `{"key1":"value1","key2":"value2"}`,
46+
"ENABLEWORKLOADIDENTITY": "true",
47+
"SERVICEACCOUNT": "testsa",
48+
},
49+
FileNameOverride: map[string]string{
50+
"deployment.yaml": "deployment-override-workload-identity.yaml",
51+
},
52+
GenerateBaseTemplate: true,
53+
},
3054
{
3155
Name: "valid manifest deployment with filename override",
3256
TemplateName: "deployment-manifests",

template/deployments/kustomize/base/deployment.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ metadata:
55
labels:
66
app.kubernetes.io/name: {{ .Config.GetVariableValue "APPNAME" }}
77
kubernetes.azure.com/generator: {{ .Config.GetVariableValue "GENERATORLABEL" }}
8-
{{- if eq (.Config.GetVariableValue "ENABLEWORKLOADIDENTITY") "true" }}
9-
azure.workload.identity/use: "true"
10-
{{- end}}
118
namespace: {{ .Config.GetVariableValue "NAMESPACE" }}
129
spec:
1310
replicas: 1
@@ -18,6 +15,9 @@ spec:
1815
metadata:
1916
labels:
2017
app.kubernetes.io/name: {{ .Config.GetVariableValue "APPNAME" }}
18+
{{- if eq (.Config.GetVariableValue "ENABLEWORKLOADIDENTITY") "true" }}
19+
azure.workload.identity/use: "true"
20+
{{- end}}
2121
spec:
2222
{{- if eq (.Config.GetVariableValue "ENABLEWORKLOADIDENTITY") "true" }}
2323
serviceAccountName: {{ .Config.GetVariableValue "SERVICEACCOUNT" }}

template/deployments/manifests/manifests/deployment.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ metadata:
55
labels:
66
app.kubernetes.io/name: {{ .Config.GetVariableValue "APPNAME" }}
77
kubernetes.azure.com/generator: {{ .Config.GetVariableValue "GENERATORLABEL" }}
8-
{{- if eq (.Config.GetVariableValue "ENABLEWORKLOADIDENTITY") "true" }}
9-
azure.workload.identity/use: "true"
10-
{{- end}}
118
namespace: {{ .Config.GetVariableValue "NAMESPACE" }}
129
spec:
1310
replicas: 1
@@ -18,6 +15,9 @@ spec:
1815
metadata:
1916
labels:
2017
app.kubernetes.io/name: {{ .Config.GetVariableValue "APPNAME" }}
18+
{{- if eq (.Config.GetVariableValue "ENABLEWORKLOADIDENTITY") "true" }}
19+
azure.workload.identity/use: "true"
20+
{{- end}}
2121
spec:
2222
{{- if eq (.Config.GetVariableValue "ENABLEWORKLOADIDENTITY") "true" }}
2323
serviceAccountName: {{ .Config.GetVariableValue "SERVICEACCOUNT" }}

0 commit comments

Comments
 (0)