Skip to content

Commit 655dc77

Browse files
feat: adding auth secret for terraform controller and it's jobs
Signed-off-by: Duc Thang Tran <[email protected]> feat: upgrading go version in github workflow and Dockerfile Signed-off-by: Duc Thang Tran <[email protected]> feat: upgrading go version in github workflow Signed-off-by: Duc Thang Tran <[email protected]>
1 parent 0845592 commit 655dc77

File tree

7 files changed

+43
-1
lines changed

7 files changed

+43
-1
lines changed

.github/workflows/unit-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515

1616
env:
1717
# Common versions
18-
GO_VERSION: '1.17.6'
18+
GO_VERSION: '1.18.0'
1919

2020
jobs:
2121
lint:

chart/templates/terraform_controller.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ spec:
2020
- name: terraform-controller
2121
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
2222
imagePullPolicy: {{ .Values.image.pullPolicy }}
23+
{{- if .Values.authSecretName }}
24+
imagePullSecrets:
25+
- name: {{ .Values.authSecretName }}
26+
{{- end }}
2327
args:
2428
{{- if .Values.controllerNamespace }}
2529
- --controller-namespace={{ .Values.controllerNamespace }}
@@ -38,6 +42,10 @@ spec:
3842
value: {{ .Values.busyboxImage}}
3943
- name: GIT_IMAGE
4044
value: {{ .Values.gitImage}}
45+
{{- if .Values.jobAuthSecret }}
46+
- name: JOB_AUTH_SECRET
47+
value: {{ .Values.jobAuthSecret }}
48+
{{- end }}
4149
- name: GITHUB_BLOCKED
4250
value: {{ .Values.githubBlocked }}
4351
{{ if .Values.jobBackoffLimit }}

chart/values.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ busyboxImage: busybox:latest
1010
terraformImage: oamdev/docker-terraform:1.1.5
1111
controllerNamespace: ""
1212

13+
authSecretName: ""
14+
jobAuthSecret: ""
15+
1316
# "{\"nat\": \"true\"}"
1417
jobNodeSelector: ""
1518
jobBackoffLimit: ""

controllers/configuration_controller.go

+2
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ func (r *ConfigurationReconciler) preCheck(ctx context.Context, configuration *v
373373
}
374374
}
375375

376+
meta.JobAuthSecret = os.Getenv("JOB_AUTH_SECRET")
377+
376378
if err := r.preCheckResourcesSetting(meta); err != nil {
377379
return err
378380
}

controllers/configuration_controller_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,31 @@ func TestPreCheck(t *testing.T) {
803803
},
804804
want: want{},
805805
},
806+
{
807+
name: "wrong value in environment variable JOB_AUTH_SECRET",
808+
prepare: func(t *testing.T) {
809+
t.Setenv("JOB_AUTH_SECRET", "test-secret")
810+
},
811+
args: args{
812+
r: r,
813+
configuration: &v1beta2.Configuration{
814+
ObjectMeta: v1.ObjectMeta{
815+
Name: "abc",
816+
},
817+
Spec: v1beta2.ConfigurationSpec{
818+
HCL: "bbb",
819+
},
820+
},
821+
meta: &process.TFConfigurationMeta{
822+
ConfigurationCMName: "abc",
823+
ProviderReference: &crossplane.Reference{
824+
Namespace: "default",
825+
Name: "default",
826+
},
827+
},
828+
},
829+
want: want{},
830+
},
806831
}
807832

808833
for _, tc := range testcases {

controllers/process/meta.go

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ type TFConfigurationMeta struct {
5757
BusyboxImage string
5858
GitImage string
5959

60+
// JobAuthSecret is the secret name for pulling image in the Terraform job
61+
JobAuthSecret string
62+
6063
// BackoffLimit specifies the number of retries to mark the Job as failed
6164
BackoffLimit int32
6265

controllers/process/process.go

+1
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ func (meta *TFConfigurationMeta) assembleTerraformJob(executionType types.Terraf
328328
Volumes: executorVolumes,
329329
RestartPolicy: v1.RestartPolicyOnFailure,
330330
NodeSelector: meta.JobNodeSelector,
331+
ImagePullSecrets: []v1.LocalObjectReference{{Name: meta.JobAuthSecret}},
331332
},
332333
},
333334
},

0 commit comments

Comments
 (0)