From d0e9e1083100c8ab3e99f362a455939fd3d519f9 Mon Sep 17 00:00:00 2001 From: Katrina Rogan Date: Fri, 9 Aug 2024 15:01:53 +0200 Subject: [PATCH] Fix ordering for custom template values in cluster resource controller Signed-off-by: Katrina Rogan --- flyteadmin/pkg/clusterresource/controller.go | 5 ++- .../pkg/clusterresource/controller_test.go | 32 +++++++++++++++++++ .../imagepullsecrets_templatized.yaml | 7 ++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 flyteadmin/pkg/clusterresource/testdata/imagepullsecrets_templatized.yaml 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 }}