Skip to content

Commit

Permalink
Fix ordering for custom template values in cluster resource controller (
Browse files Browse the repository at this point in the history
#5648)

Signed-off-by: Katrina Rogan <[email protected]>
  • Loading branch information
katrogan authored Aug 12, 2024
1 parent a13a63d commit 9cfb4e3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
5 changes: 2 additions & 3 deletions flyteadmin/pkg/clusterresource/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
32 changes: 32 additions & 0 deletions flyteadmin/pkg/clusterresource/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: default
namespace: {{ namespace }}
imagePullSecrets:
- name: {{ imagePullSecretsName }}

0 comments on commit 9cfb4e3

Please sign in to comment.