Skip to content

Commit

Permalink
feat: adding auth secret for terraform controller and it's jobs
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
TranThang-2804 committed Jan 12, 2025
1 parent 0845592 commit 655dc77
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:

env:
# Common versions
GO_VERSION: '1.17.6'
GO_VERSION: '1.18.0'

jobs:
lint:
Expand Down
8 changes: 8 additions & 0 deletions chart/templates/terraform_controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ spec:
- name: terraform-controller
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if .Values.authSecretName }}
imagePullSecrets:
- name: {{ .Values.authSecretName }}
{{- end }}
args:
{{- if .Values.controllerNamespace }}
- --controller-namespace={{ .Values.controllerNamespace }}
Expand All @@ -38,6 +42,10 @@ spec:
value: {{ .Values.busyboxImage}}
- name: GIT_IMAGE
value: {{ .Values.gitImage}}
{{- if .Values.jobAuthSecret }}
- name: JOB_AUTH_SECRET
value: {{ .Values.jobAuthSecret }}
{{- end }}
- name: GITHUB_BLOCKED
value: {{ .Values.githubBlocked }}
{{ if .Values.jobBackoffLimit }}
Expand Down
3 changes: 3 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ busyboxImage: busybox:latest
terraformImage: oamdev/docker-terraform:1.1.5
controllerNamespace: ""

authSecretName: ""
jobAuthSecret: ""

# "{\"nat\": \"true\"}"
jobNodeSelector: ""
jobBackoffLimit: ""
Expand Down
2 changes: 2 additions & 0 deletions controllers/configuration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ func (r *ConfigurationReconciler) preCheck(ctx context.Context, configuration *v
}
}

meta.JobAuthSecret = os.Getenv("JOB_AUTH_SECRET")

if err := r.preCheckResourcesSetting(meta); err != nil {
return err
}
Expand Down
25 changes: 25 additions & 0 deletions controllers/configuration_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,31 @@ func TestPreCheck(t *testing.T) {
},
want: want{},
},
{
name: "wrong value in environment variable JOB_AUTH_SECRET",
prepare: func(t *testing.T) {
t.Setenv("JOB_AUTH_SECRET", "test-secret")
},
args: args{
r: r,
configuration: &v1beta2.Configuration{
ObjectMeta: v1.ObjectMeta{
Name: "abc",
},
Spec: v1beta2.ConfigurationSpec{
HCL: "bbb",
},
},
meta: &process.TFConfigurationMeta{
ConfigurationCMName: "abc",
ProviderReference: &crossplane.Reference{
Namespace: "default",
Name: "default",
},
},
},
want: want{},
},
}

for _, tc := range testcases {
Expand Down
3 changes: 3 additions & 0 deletions controllers/process/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type TFConfigurationMeta struct {
BusyboxImage string
GitImage string

// JobAuthSecret is the secret name for pulling image in the Terraform job
JobAuthSecret string

// BackoffLimit specifies the number of retries to mark the Job as failed
BackoffLimit int32

Expand Down
1 change: 1 addition & 0 deletions controllers/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ func (meta *TFConfigurationMeta) assembleTerraformJob(executionType types.Terraf
Volumes: executorVolumes,
RestartPolicy: v1.RestartPolicyOnFailure,
NodeSelector: meta.JobNodeSelector,
ImagePullSecrets: []v1.LocalObjectReference{{Name: meta.JobAuthSecret}},
},
},
},
Expand Down

0 comments on commit 655dc77

Please sign in to comment.