From 69c819da36d305fc53f2d79fb0a11174d2aad3a4 Mon Sep 17 00:00:00 2001 From: TLDMain <119927819+TLDMain@users.noreply.github.com> Date: Fri, 12 Apr 2024 22:28:08 +0300 Subject: [PATCH 1/3] feat: support inline configurations --- .../builtinconfig/transformerconfig.go | 17 +++++++- api/krusty/customconfig_test.go | 39 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/api/internal/plugins/builtinconfig/transformerconfig.go b/api/internal/plugins/builtinconfig/transformerconfig.go index ab847eb6ec..634c0b50fb 100644 --- a/api/internal/plugins/builtinconfig/transformerconfig.go +++ b/api/internal/plugins/builtinconfig/transformerconfig.go @@ -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 } diff --git a/api/krusty/customconfig_test.go b/api/krusty/customconfig_test.go index e563d64c2e..b4ed225495 100644 --- a/api/krusty/customconfig_test.go +++ b/api/krusty/customconfig_test.go @@ -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 +`) +} From 70101ba0a21a79d06d0c6ef3c4880f2aafa5029f Mon Sep 17 00:00:00 2001 From: TLDMain <119927819+TLDMain@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:53:49 +0000 Subject: [PATCH 2/3] fix lint after merge --- api/krusty/customconfig_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/krusty/customconfig_test.go b/api/krusty/customconfig_test.go index 545e30aa65..08002b92c4 100644 --- a/api/krusty/customconfig_test.go +++ b/api/krusty/customconfig_test.go @@ -373,6 +373,7 @@ spec: container: image: new-crd-image:new-v1-tag `) +} func TestLabelTransformerConfig(t *testing.T) { testCases := []struct { From 2c2b0bed80728a0373579320f10b44165391f33e Mon Sep 17 00:00:00 2001 From: TLDMain <119927819+TLDMain@users.noreply.github.com> Date: Sat, 9 Nov 2024 11:26:37 +0000 Subject: [PATCH 3/3] upd(inline config): check new line in configuration string --- api/internal/plugins/builtinconfig/transformerconfig.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/api/internal/plugins/builtinconfig/transformerconfig.go b/api/internal/plugins/builtinconfig/transformerconfig.go index c71079ac78..4e5c8abe70 100644 --- a/api/internal/plugins/builtinconfig/transformerconfig.go +++ b/api/internal/plugins/builtinconfig/transformerconfig.go @@ -6,6 +6,7 @@ package builtinconfig import ( "log" "sort" + "strings" "sync" "sigs.k8s.io/kustomize/api/ifc" @@ -85,11 +86,14 @@ func MakeTransformerConfig( } var paths []string for _, configuration := range configurations { - config, err := makeTransformerConfigFromBytes([]byte(configuration)) - if err != nil { + if (!strings.Contains(configuration, "\n") && !strings.Contains(configuration, "\r")) { paths = append(paths, configuration) continue } + config, err := makeTransformerConfigFromBytes([]byte(configuration)) + if err != nil { + return nil, err + } t1, err = t1.Merge(config) if err != nil { return nil, err