Skip to content

Commit ebd0938

Browse files
committed
support service connector
1 parent 0adbddf commit ebd0938

File tree

11 files changed

+141
-0
lines changed

11 files changed

+141
-0
lines changed

pkg/config/draftconfig.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,24 @@ func (d *DraftConfig) GetVariableValue(name string) (any, error) {
124124
return "", fmt.Errorf("variable %s not found", name)
125125
}
126126

127+
func (d *DraftConfig) IsVariableValid(name string) bool {
128+
for _, variable := range d.Variables {
129+
if variable.Name == name {
130+
if variable.Value == "" {
131+
return false
132+
}
133+
134+
if err := d.GetVariableValidator(variable.Kind)(variable.Value); err != nil {
135+
return false
136+
}
137+
138+
return true
139+
}
140+
}
141+
142+
return false
143+
}
144+
127145
func (d *DraftConfig) SetVariable(name, value string) {
128146
if variable, err := d.GetVariable(name); err != nil {
129147
d.Variables = append(d.Variables, &BuilderVar{

pkg/fixtures/deployments/helm/charts/templates/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ spec:
4949
envFrom:
5050
- configMapRef:
5151
name: {{ include "testapp.fullname" . }}-config
52+
- secretRef:
53+
name: secret-ref
54+
optional: true
5255
{{- with .Values.nodeSelector }}
5356
nodeSelector:
5457
{{- toYaml . | nindent 8 }}

pkg/fixtures/deployments/kustomize/base/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ spec:
3232
envFrom:
3333
- configMapRef:
3434
name: testapp-config
35+
- secretRef:
36+
name: secret-ref
37+
optional: true
3538
livenessProbe:
3639
tcpSocket:
3740
port: 80

pkg/fixtures/deployments/manifest/manifests/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ spec:
3232
envFrom:
3333
- configMapRef:
3434
name: testapp-config
35+
- secretRef:
36+
name: secret-ref
37+
optional: true
3538
livenessProbe:
3639
tcpSocket:
3740
port: 80

template/deployments/helm/charts/templates/deployment.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,21 @@ spec:
2626
` -}}
2727
labels:
2828
{{ .Config.GetVariableValue "APPNAME" | printf "{{- include \"%s.selectorLabels\" . | nindent 8 }}" }}
29+
{{- if eq (.Config.GetVariableValue "ENABLEWORKLOADIDENTITY") "true" }}
30+
azure.workload.identity/use: "true"
31+
{{- end}}
2932
namespace: {{ print "{{ .Values.namespace }}" }}
3033
spec:
3134
{{- `
3235
{{- with .Values.imagePullSecrets }}
3336
imagePullSecrets:
3437
{{- toYaml . | nindent 8 }}
3538
{{- end }}
39+
` -}}
40+
{{- if eq (.Config.GetVariableValue "ENABLEWORKLOADIDENTITY") "true" }}
41+
serviceAccountName: {{ .Config.GetVariableValue "SERVICEACCOUNT" }}
42+
{{- end}}
43+
{{- `
3644
securityContext:
3745
{{- toYaml .Values.podSecurityContext | nindent 8 }}
3846
containers:
@@ -57,6 +65,9 @@ spec:
5765
envFrom:
5866
- configMapRef:
5967
name: {{ .Config.GetVariableValue "APPNAME" | printf "{{ include \"%s.fullname\" . }}-config" }}
68+
- secretRef:
69+
name: {{ .Config.GetVariableValue "ENVSECRETREF" }}
70+
optional: true
6071
{{- `
6172
{{- with .Values.nodeSelector }}
6273
nodeSelector:

template/deployments/helm/charts/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ service:
2525
type: LoadBalancer
2626
port: {{ .Config.GetVariableValue "SERVICEPORT" }}
2727

28+
{{- if eq (.Config.GetVariableValue "ENABLEWORKLOADIDENTITY") "true" }}
29+
serviceAccountName: {{ .Config.GetVariableValue "SERVICEACCOUNT" }}
30+
{{- end}}
31+
2832
resources:
2933
# We usually recommend not to specify default resources and to leave this as a conscious
3034
# choice for the user. This also increases chances charts run on environments with little

template/deployments/helm/draft.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,31 @@ variables:
206206
disablePrompt: true
207207
value: "{}"
208208
description: "a map of key/value environment variables to be set in the deployment"
209+
versions: ">=0.0.1"
210+
- name: "ENABLEWORKLOADIDENTITY"
211+
type: "bool"
212+
kind: "flag"
213+
default:
214+
disablePrompt: true
215+
value: false
216+
description: "flag to enable workload identity"
217+
versions: ">=0.0.1"
218+
- name: "SERVICEACCOUNT"
219+
type: "string"
220+
kind: "kubernetesResourceName"
221+
conditionalReference:
222+
variable: "ENABLEWORKLOADIDENTITY"
223+
conditionValue: true
224+
default:
225+
disablePrompt: true
226+
value: "service-account"
227+
description: "the name of the service account to use with workload identity"
228+
versions: ">=0.0.1"
229+
- name: "ENVSECRETREF"
230+
type: "string"
231+
kind: "kubernetesResourceName"
232+
default:
233+
disablePrompt: true
234+
value: "secret-ref"
235+
description: "the name of the configmap reference"
209236
versions: ">=0.0.1"

template/deployments/kustomize/base/deployment.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ 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}}
811
namespace: {{ .Config.GetVariableValue "NAMESPACE" }}
912
spec:
1013
replicas: 1
@@ -16,6 +19,9 @@ spec:
1619
labels:
1720
app.kubernetes.io/name: {{ .Config.GetVariableValue "APPNAME" }}
1821
spec:
22+
{{- if eq (.Config.GetVariableValue "ENABLEWORKLOADIDENTITY") "true" }}
23+
serviceAccountName: {{ .Config.GetVariableValue "SERVICEACCOUNT" }}
24+
{{- end}}
1925
containers:
2026
- name: {{ .Config.GetVariableValue "APPNAME" }}
2127
image: {{ .Config.GetVariableValue "IMAGENAME" }}:{{ .Config.GetVariableValue "IMAGETAG" }}
@@ -32,6 +38,9 @@ spec:
3238
envFrom:
3339
- configMapRef:
3440
name: {{ .Config.GetVariableValue "APPNAME" | printf "%s-config" }}
41+
- secretRef:
42+
name: {{ .Config.GetVariableValue "ENVSECRETREF" }}
43+
optional: true
3544
livenessProbe:
3645
{{- if eq (.Config.GetVariableValue "PROBETYPE") "httpGet" }}
3746
httpGet:

template/deployments/kustomize/draft.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,31 @@ variables:
206206
disablePrompt: true
207207
value: "{}"
208208
description: "a map of key/value environment variables to be set in the deployment"
209+
versions: ">=0.0.1"
210+
- name: "ENVSECRETREF"
211+
type: "string"
212+
kind: "kubernetesResourceName"
213+
default:
214+
disablePrompt: true
215+
value: "secret-ref"
216+
description: "the name of the configmap reference"
217+
versions: ">=0.0.1"
218+
- name: "ENABLEWORKLOADIDENTITY"
219+
type: "bool"
220+
kind: "flag"
221+
default:
222+
disablePrompt: true
223+
value: false
224+
description: "flag to enable workload identity"
225+
versions: ">=0.0.1"
226+
- name: "SERVICEACCOUNT"
227+
type: "string"
228+
kind: "kubernetesResourceName"
229+
conditionalReference:
230+
variable: "ENABLEWORKLOADIDENTITY"
231+
conditionValue: true
232+
default:
233+
disablePrompt: true
234+
value: "service-account"
235+
description: "the name of the service account to use with workload identity"
209236
versions: ">=0.0.1"

template/deployments/manifests/draft.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,31 @@ variables:
206206
disablePrompt: true
207207
value: "{}"
208208
description: "a json map of string -> string key/value environment variables to be set in the deployment"
209+
versions: ">=0.0.1"
210+
- name: "ENABLEWORKLOADIDENTITY"
211+
type: "bool"
212+
kind: "flag"
213+
default:
214+
disablePrompt: true
215+
value: false
216+
description: "flag to enable workload identity"
217+
versions: ">=0.0.1"
218+
- name: "SERVICEACCOUNT"
219+
type: "string"
220+
kind: "kubernetesResourceName"
221+
conditionalReference:
222+
variable: "ENABLEWORKLOADIDENTITY"
223+
conditionValue: true
224+
default:
225+
disablePrompt: true
226+
value: "service-account"
227+
description: "the name of the service account to use with workload identity"
228+
versions: ">=0.0.1"
229+
- name: "ENVSECRETREF"
230+
type: "string"
231+
kind: "kubernetesResourceName"
232+
default:
233+
disablePrompt: true
234+
value: "secret-ref"
235+
description: "the name of the configmap reference"
209236
versions: ">=0.0.1"

0 commit comments

Comments
 (0)