Skip to content

Commit

Permalink
feat: support inline configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
TLDMain committed Apr 12, 2024
1 parent 82ee768 commit eed1477
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
17 changes: 16 additions & 1 deletion api/internal/plugins/builtinconfig/transformerconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,23 @@ func MakeDefaultConfig() *TransformerConfig {
// MakeTransformerConfig returns a merger of custom config,
// if any, with default config.
func MakeTransformerConfig(
ldr ifc.Loader, paths []string) (*TransformerConfig, error) {
ldr ifc.Loader, configurations []string) (*TransformerConfig, error) {
t1 := MakeDefaultConfig()
if len(configurations) == 0 {
return t1, nil
}
var paths []string
for _, configuration := range configurations {
config, err := makeTransformerConfigFromBytes([]byte(configuration))
if err != nil {
paths = append(paths, configuration)
continue
}
t1, err = t1.Merge(config)
if err != nil {
return nil, err
}
}
if len(paths) == 0 {
return t1, nil
}
Expand Down
39 changes: 39 additions & 0 deletions api/krusty/customconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,42 @@ spec:
location: Arizona
`)
}

func TestInlineConfig(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t)
defer th.Reset()

th.WriteF("/app/resource.yaml", `
apiVersion: config/v1
kind: MyKind
metadata:
name: testSvc
spec:
container:
image: crd-image
`)
th.WriteK("/app", `
resources:
- resource.yaml
images:
- name: crd-image
newName: new-crd-image
newTag: new-v1-tag
configurations:
- |-
images:
- kind: MyKind
path: spec/container/image
`)

m := th.Run("/app", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: config/v1
kind: MyKind
metadata:
name: testSvc
spec:
container:
image: new-crd-image:new-v1-tag
`)
}

0 comments on commit eed1477

Please # to comment.