Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ordering for custom template values in cluster resource controller #5648

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}
Loading