diff --git a/flyteadmin/pkg/clusterresource/controller.go b/flyteadmin/pkg/clusterresource/controller.go index daad2600e8..6ea1731909 100644 --- a/flyteadmin/pkg/clusterresource/controller.go +++ b/flyteadmin/pkg/clusterresource/controller.go @@ -485,14 +485,13 @@ func (c *controller) createResourceFromTemplate(ctx context.Context, templateDir templateValues[fmt.Sprintf(templateVariableFormat, domainVariable)] = domain.Id var k8sManifest = string(template) - for templateKey, templateValue := range templateValues { + for templateKey, templateValue := range customTemplateValues { k8sManifest = strings.Replace(k8sManifest, templateKey, templateValue, replaceAllInstancesOfString) } // Replace remaining template variables from domain specific defaults. - for templateKey, templateValue := range customTemplateValues { + for templateKey, templateValue := range templateValues { k8sManifest = strings.Replace(k8sManifest, templateKey, templateValue, replaceAllInstancesOfString) } - return k8sManifest, nil } diff --git a/flyteadmin/pkg/clusterresource/controller_test.go b/flyteadmin/pkg/clusterresource/controller_test.go index dc3239cdc2..f6a966d6ef 100644 --- a/flyteadmin/pkg/clusterresource/controller_test.go +++ b/flyteadmin/pkg/clusterresource/controller_test.go @@ -293,6 +293,38 @@ kind: IAMServiceAccount metadata: name: my-project-dev-gsa namespace: my-project-dev +`, + wantErr: false, + }, + { + name: "test create resource from templatized imagepullsecrets.yaml", + args: args{ + ctx: context.Background(), + templateDir: "testdata", + templateFileName: "imagepullsecrets_templatized.yaml", + project: &admin.Project{ + Name: "my-project", + Id: "my-project", + }, + domain: &admin.Domain{ + Id: "dev", + Name: "dev", + }, + namespace: "my-project-dev", + templateValues: templateValuesType{ + "{{ imagePullSecretsName }}": "default", + }, + customTemplateValues: templateValuesType{ + "{{ imagePullSecretsName }}": "custom", + }, + }, + wantK8sManifest: `apiVersion: v1 +kind: ServiceAccount +metadata: + name: default + namespace: my-project-dev +imagePullSecrets: + - name: custom `, wantErr: false, }, diff --git a/flyteadmin/pkg/clusterresource/testdata/imagepullsecrets_templatized.yaml b/flyteadmin/pkg/clusterresource/testdata/imagepullsecrets_templatized.yaml new file mode 100644 index 0000000000..5c9d267382 --- /dev/null +++ b/flyteadmin/pkg/clusterresource/testdata/imagepullsecrets_templatized.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: default + namespace: {{ namespace }} +imagePullSecrets: + - name: {{ imagePullSecretsName }}