diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..a4bad261ba --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# Set default behavior to automatically normalize line endings +* text=auto + +# Force bash scripts to always use LF line endings +*.sh text eol=lf + +# Force batch scripts to always use CRLF line endings +*.bat text eol=crlf +*.cmd text eol=crlf diff --git a/commands/fn/render/cmdrender.go b/commands/fn/render/cmdrender.go index 43426ebef9..0a807aaf8e 100644 --- a/commands/fn/render/cmdrender.go +++ b/commands/fn/render/cmdrender.go @@ -26,6 +26,7 @@ import ( "github.com/kptdev/kpt/internal/util/argutil" "github.com/kptdev/kpt/internal/util/pathutil" "github.com/kptdev/kpt/internal/util/render" + "github.com/kptdev/kpt/pkg/lib/kptops" "github.com/kptdev/kpt/pkg/lib/runneroptions" "github.com/kptdev/kpt/pkg/lib/util/cmdutil" "github.com/kptdev/kpt/pkg/printer" diff --git a/commands/fn/render/cmdrender_test.go b/commands/fn/render/cmdrender_test.go index e9679d9155..4485ee8fdd 100644 --- a/commands/fn/render/cmdrender_test.go +++ b/commands/fn/render/cmdrender_test.go @@ -32,7 +32,9 @@ func TestCmd_flagAndArgParsing_Symlink(t *testing.T) { err := os.MkdirAll(filepath.Join(dir, "path", "to", "pkg", "dir"), 0700) assert.NoError(t, err) err = os.Symlink(filepath.Join("path", "to", "pkg", "dir"), "foo") - assert.NoError(t, err) + if err != nil { + t.Skip("skipping symlink test; user likely lacks privilege to create symlinks on Windows") + } // verify the branch ref is set to the correct value r := NewRunner(fake.CtxWithDefaultPrinter(), "kpt") diff --git a/e2e/testdata/fn-render/all-resource-deletion/.expected/diff.patch b/e2e/testdata/fn-render/all-resource-deletion/.expected/diff.patch index 34218ae522..5e7b56147d 100644 --- a/e2e/testdata/fn-render/all-resource-deletion/.expected/diff.patch +++ b/e2e/testdata/fn-render/all-resource-deletion/.expected/diff.patch @@ -1,43 +1,92 @@ diff --git a/Kptfile b/Kptfile -index 3c93e9e..fe0bc96 100644 +index 20fac6a..7f10467 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: app -+ namespace: staging +@@ -1,14 +1,16 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest +- configPath: delete-all.yaml +- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest +- configMap: +- namespace: staging +- - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 +- configMap: +- tier: backend ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app + labels: + tier: backend - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -@@ -12,3 +15,8 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: delete-all.yaml ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest ++ configMap: ++ namespace: staging ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 ++ configMap: ++ tier: backend diff --git a/delete-all.yaml b/delete-all.yaml -index 3c86d8b..6754b0a 100644 +index 9ddbbe2..bea1693 100644 --- a/delete-all.yaml +++ b/delete-all.yaml -@@ -17,6 +17,9 @@ metadata: - name: delete-all - annotations: - config.kubernetes.io/local-config: "true" -+ namespace: staging +@@ -1,22 +1,24 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: delete-all +- annotations: +- config.kubernetes.io/local-config: "true" +-source: |- +- # delete all resources +- ctx.resource_list["items"] = [x for x in ctx.resource_list["items"] if x["kind"] in ["Kptfile", "StarlarkRun"]] ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: delete-all ++ annotations: ++ config.kubernetes.io/local-config: "true" + labels: + tier: backend - source: |- - # delete all resources - ctx.resource_list["items"] = [x for x in ctx.resource_list["items"] if x["kind"] in ["Kptfile", "StarlarkRun"]] ++source: |- ++ # delete all resources ++ ctx.resource_list["items"] = [x for x in ctx.resource_list["items"] if x["kind"] in ["Kptfile", "StarlarkRun"]] diff --git a/deployment.yaml b/deployment.yaml deleted file mode 100644 -index 990ca9b..0000000 +index 73d3f5e..0000000 --- a/deployment.yaml +++ /dev/null @@ -1,24 +0,0 @@ @@ -67,7 +116,7 @@ index 990ca9b..0000000 - image: kennethreitz/httpbin diff --git a/resources.yaml b/resources.yaml deleted file mode 100644 -index 239f0d6..0000000 +index 027731c..0000000 --- a/resources.yaml +++ /dev/null @@ -1,19 +0,0 @@ diff --git a/e2e/testdata/fn-render/all-resource-deletion/Kptfile b/e2e/testdata/fn-render/all-resource-deletion/Kptfile index 3c93e9eba7..faf208d647 100644 --- a/e2e/testdata/fn-render/all-resource-deletion/Kptfile +++ b/e2e/testdata/fn-render/all-resource-deletion/Kptfile @@ -6,7 +6,7 @@ pipeline: mutators: - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest configPath: delete-all.yaml - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/basicpipeline-out-of-place/Kptfile b/e2e/testdata/fn-render/basicpipeline-out-of-place/Kptfile index 1307fb5426..93ae454de7 100644 --- a/e2e/testdata/fn-render/basicpipeline-out-of-place/Kptfile +++ b/e2e/testdata/fn-render/basicpipeline-out-of-place/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/basicpipeline-semver/.expected/diff.patch b/e2e/testdata/fn-render/basicpipeline-semver/.expected/diff.patch index fea4f539a1..51852137e3 100644 --- a/e2e/testdata/fn-render/basicpipeline-semver/.expected/diff.patch +++ b/e2e/testdata/fn-render/basicpipeline-semver/.expected/diff.patch @@ -1,52 +1,100 @@ diff --git a/Kptfile b/Kptfile -index 2336da4..eae3be3 100644 +index 68ea4fc..85f42f5 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,13 +2,20 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: app -+ labels: -+ tier: backend - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace +@@ -1,14 +1,16 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace - tag: "0.4.1 - 0.4.3" - configMap: - namespace: staging -+ tag: 0.4.1 - 0.4.3 - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels +- configMap: +- namespace: staging +- - image: ghcr.io/kptdev/krm-functions-catalog/set-labels - tag: "~0.2" - configMap: - tier: backend -+ tag: ~0.2 -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess +- configMap: +- tier: backend ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app ++ labels: ++ tier: backend ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace ++ tag: "0.4.1 - 0.4.3" ++ configMap: ++ namespace: staging ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels ++ tag: "~0.2" ++ configMap: ++ tier: backend diff --git a/resources.yaml b/resources.yaml -index 1f15150..936d957 100644 +index ffbb3d7..936d957 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,12 +15,20 @@ apiVersion: apps/v1 - kind: Deployment - metadata: - name: nginx-deployment +@@ -1,26 +1,34 @@ +-# Copyright 2026 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment +-spec: +- replicas: 3 +---- +-apiVersion: custom.io/v1 +-kind: Custom +-metadata: +- name: custom +-spec: +- image: nginx:1.2.3 ++# Copyright 2026 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment + namespace: staging + labels: + tier: backend - spec: - replicas: 3 ++spec: ++ replicas: 3 + selector: + matchLabels: + tier: backend - --- - apiVersion: custom.io/v1 - kind: Custom - metadata: - name: custom ++--- ++apiVersion: custom.io/v1 ++kind: Custom ++metadata: ++ name: custom + labels: + tier: backend - spec: - image: nginx:1.2.3 ++spec: ++ image: nginx:1.2.3 diff --git a/e2e/testdata/fn-render/basicpipeline-symlink/.expected/config.yaml b/e2e/testdata/fn-render/basicpipeline-symlink/.expected/config.yaml index 21bdfde15f..7662b2c61e 100644 --- a/e2e/testdata/fn-render/basicpipeline-symlink/.expected/config.yaml +++ b/e2e/testdata/fn-render/basicpipeline-symlink/.expected/config.yaml @@ -22,8 +22,8 @@ stdErrStripLines: stdErr: |- [WARN] resolved symlink "new-link" to ".", please note that the symlinks within the package are ignored Package: "basicpipeline-symlink" - [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" - [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" in 0s + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5" [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5" in 0s Successfully executed 2 function(s) in 1 package(s). diff --git a/e2e/testdata/fn-render/basicpipeline-symlink/.expected/diff.patch b/e2e/testdata/fn-render/basicpipeline-symlink/.expected/diff.patch index 16337308e3..a21c38b30e 100644 --- a/e2e/testdata/fn-render/basicpipeline-symlink/.expected/diff.patch +++ b/e2e/testdata/fn-render/basicpipeline-symlink/.expected/diff.patch @@ -1,5 +1,5 @@ diff --git a/Kptfile b/Kptfile -index 1307fb5..f645d75 100644 +index 1307fb5..3a2c718 100644 --- a/Kptfile +++ b/Kptfile @@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 @@ -12,15 +12,6 @@ index 1307fb5..f645d75 100644 pipeline: mutators: - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -@@ -10,3 +13,8 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess diff --git a/resources.yaml b/resources.yaml index f2eec52..84cfb26 100644 --- a/resources.yaml diff --git a/e2e/testdata/fn-render/basicpipeline-symlink/Kptfile b/e2e/testdata/fn-render/basicpipeline-symlink/Kptfile index 1307fb5426..93ae454de7 100644 --- a/e2e/testdata/fn-render/basicpipeline-symlink/Kptfile +++ b/e2e/testdata/fn-render/basicpipeline-symlink/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/basicpipeline-v1alpha2/Kptfile b/e2e/testdata/fn-render/basicpipeline-v1alpha2/Kptfile index 1b38316f00..1648ad9067 100644 --- a/e2e/testdata/fn-render/basicpipeline-v1alpha2/Kptfile +++ b/e2e/testdata/fn-render/basicpipeline-v1alpha2/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/basicpipeline-wasm/.expected/diff.patch b/e2e/testdata/fn-render/basicpipeline-wasm/.expected/diff.patch index 9c2bb0566e..d964fe8822 100644 --- a/e2e/testdata/fn-render/basicpipeline-wasm/.expected/diff.patch +++ b/e2e/testdata/fn-render/basicpipeline-wasm/.expected/diff.patch @@ -1,21 +1,8 @@ -diff --git a/Kptfile b/Kptfile -index 17a7822..94b6f80 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -12,3 +12,8 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/wasm/set-labels:v0.2.4 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess diff --git a/resources.yaml b/resources.yaml -index eed43d6..c1de2b0 100644 +index eed43d6..33cefe3 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,12 +15,20 @@ apiVersion: apps/v1 +@@ -15,6 +15,9 @@ apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment @@ -24,11 +11,8 @@ index eed43d6..c1de2b0 100644 + tier: backend spec: replicas: 3 -+ selector: -+ matchLabels: -+ tier: backend --- - apiVersion: custom.io/v1 +@@ -22,5 +25,7 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom diff --git a/e2e/testdata/fn-render/basicpipeline-wasm/.expected/setup.sh b/e2e/testdata/fn-render/basicpipeline-wasm/.expected/setup.sh index bcf8bc12c1..115e1ca96f 100755 --- a/e2e/testdata/fn-render/basicpipeline-wasm/.expected/setup.sh +++ b/e2e/testdata/fn-render/basicpipeline-wasm/.expected/setup.sh @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -export KPT_FN_WASM_RUNTIME=nodejs +export KPT_FN_WASM_RUNTIME=wasmtime diff --git a/e2e/testdata/fn-render/basicpipeline-wasm/Kptfile b/e2e/testdata/fn-render/basicpipeline-wasm/Kptfile index 17a7822d08..18e0e24f6a 100644 --- a/e2e/testdata/fn-render/basicpipeline-wasm/Kptfile +++ b/e2e/testdata/fn-render/basicpipeline-wasm/Kptfile @@ -6,9 +6,10 @@ metadata: tier: backend pipeline: mutators: + # The following 2 images are built from https://github.com/kptdev/krm-functions-catalog/pull/898. - image: ghcr.io/kptdev/krm-functions-catalog/wasm/set-namespace:v0.5.1 configMap: namespace: staging - - image: ghcr.io/kptdev/krm-functions-catalog/wasm/set-labels:v0.2.4 + - image: ghcr.io/kptdev/krm-functions-catalog/wasm/set-labels:v0.2.0 configMap: tier: backend diff --git a/e2e/testdata/fn-render/basicpipeline/.expected/diff.patch b/e2e/testdata/fn-render/basicpipeline/.expected/diff.patch index 16337308e3..679e31b313 100644 --- a/e2e/testdata/fn-render/basicpipeline/.expected/diff.patch +++ b/e2e/testdata/fn-render/basicpipeline/.expected/diff.patch @@ -1,31 +1,21 @@ diff --git a/Kptfile b/Kptfile -index 1307fb5..f645d75 100644 +index 93ae454..9caee20 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: app -+ namespace: staging + labels: + tier: backend pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -@@ -10,3 +13,8 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest diff --git a/resources.yaml b/resources.yaml -index f2eec52..84cfb26 100644 +index f2eec52..e7f0c0b 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,12 +15,25 @@ apiVersion: apps/v1 +@@ -15,6 +15,9 @@ apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment @@ -34,19 +24,11 @@ index f2eec52..84cfb26 100644 + tier: backend spec: replicas: 3 -+ selector: -+ matchLabels: -+ tier: backend -+ template: -+ metadata: -+ labels: -+ tier: backend --- - apiVersion: custom.io/v1 +@@ -22,5 +25,7 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom -+ namespace: staging + labels: + tier: backend spec: diff --git a/e2e/testdata/fn-render/basicpipeline/Kptfile b/e2e/testdata/fn-render/basicpipeline/Kptfile index 1307fb5426..93ae454de7 100644 --- a/e2e/testdata/fn-render/basicpipeline/Kptfile +++ b/e2e/testdata/fn-render/basicpipeline/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/default-runtime/.expected/diff.patch b/e2e/testdata/fn-render/default-runtime/.expected/diff.patch index 16337308e3..a21c38b30e 100644 --- a/e2e/testdata/fn-render/default-runtime/.expected/diff.patch +++ b/e2e/testdata/fn-render/default-runtime/.expected/diff.patch @@ -1,5 +1,5 @@ diff --git a/Kptfile b/Kptfile -index 1307fb5..f645d75 100644 +index 1307fb5..3a2c718 100644 --- a/Kptfile +++ b/Kptfile @@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 @@ -12,15 +12,6 @@ index 1307fb5..f645d75 100644 pipeline: mutators: - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -@@ -10,3 +13,8 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess diff --git a/resources.yaml b/resources.yaml index f2eec52..84cfb26 100644 --- a/resources.yaml diff --git a/e2e/testdata/fn-render/default-runtime/Kptfile b/e2e/testdata/fn-render/default-runtime/Kptfile index 1307fb5426..93ae454de7 100644 --- a/e2e/testdata/fn-render/default-runtime/Kptfile +++ b/e2e/testdata/fn-render/default-runtime/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/exec-function-stderr/.expected/diff.patch b/e2e/testdata/fn-render/exec-function-stderr/.expected/diff.patch index 3174051755..c35d542fb0 100644 --- a/e2e/testdata/fn-render/exec-function-stderr/.expected/diff.patch +++ b/e2e/testdata/fn-render/exec-function-stderr/.expected/diff.patch @@ -1,18 +1,3 @@ -diff --git a/Kptfile b/Kptfile -index 6f2fe11..34a53c9 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -4,4 +4,9 @@ metadata: - name: app - pipeline: - mutators: -- - exec: "./testdata/fn-render/exec-function-stderr/function.sh" -+ - exec: ./testdata/fn-render/exec-function-stderr/function.sh -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess diff --git a/resources.yaml b/resources.yaml index 0f69886..ff4bde7 100644 --- a/resources.yaml diff --git a/e2e/testdata/fn-render/exec-function-with-args/.expected/diff.patch b/e2e/testdata/fn-render/exec-function-with-args/.expected/diff.patch index d0bea1c78f..a9262b44f2 100644 --- a/e2e/testdata/fn-render/exec-function-with-args/.expected/diff.patch +++ b/e2e/testdata/fn-render/exec-function-with-args/.expected/diff.patch @@ -1,36 +1,80 @@ diff --git a/Kptfile b/Kptfile -index 0d98dbb..0dde5ad 100644 +index 5628a13..23bd061 100644 --- a/Kptfile +++ b/Kptfile -@@ -4,4 +4,9 @@ metadata: - name: app - pipeline: - mutators: +@@ -1,7 +1,7 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app +-pipeline: +- mutators: - - exec: "sed -e 's/foo/bar/'" -+ - exec: sed -e 's/bar/bar/' -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app ++pipeline: ++ mutators: ++ - exec: "sed -e 's/bar/bar/'" diff --git a/resources.yaml b/resources.yaml -index 0f69886..ff4bde7 100644 +index 159de16..ff4bde7 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,7 +15,7 @@ apiVersion: apps/v1 - kind: Deployment - metadata: - name: nginx-deployment +@@ -1,28 +1,28 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment - namespace: foo -+ namespace: bar - spec: - replicas: 3 - --- -@@ -23,6 +23,6 @@ apiVersion: custom.io/v1 - kind: Custom - metadata: - name: custom +-spec: +- replicas: 3 +---- +-apiVersion: custom.io/v1 +-kind: Custom +-metadata: +- name: custom - namespace: foo +-spec: +- image: nginx:1.2.3 ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment ++ namespace: bar ++spec: ++ replicas: 3 ++--- ++apiVersion: custom.io/v1 ++kind: Custom ++metadata: ++ name: custom + namespace: bar - spec: - image: nginx:1.2.3 ++spec: ++ image: nginx:1.2.3 diff --git a/e2e/testdata/fn-render/fn-failure/Kptfile b/e2e/testdata/fn-render/fn-failure/Kptfile index 3447ba32a5..ad0c67219a 100644 --- a/e2e/testdata/fn-render/fn-failure/Kptfile +++ b/e2e/testdata/fn-render/fn-failure/Kptfile @@ -7,7 +7,7 @@ pipeline: # invalid starlark input results in failure of first fn - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest configPath: starlark-failure-fn.yaml - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/fn-success-with-stderr/.expected/diff.patch b/e2e/testdata/fn-render/fn-success-with-stderr/.expected/diff.patch index 75677018d7..532e8db80b 100644 --- a/e2e/testdata/fn-render/fn-success-with-stderr/.expected/diff.patch +++ b/e2e/testdata/fn-render/fn-success-with-stderr/.expected/diff.patch @@ -1,13 +1,123 @@ diff --git a/Kptfile b/Kptfile -index f591880..b8c4faf 100644 +index ff38bf9..f591880 100644 --- a/Kptfile +++ b/Kptfile -@@ -6,3 +6,8 @@ pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess +@@ -1,8 +1,8 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest +- configPath: starlark.yaml ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: starlark.yaml +diff --git a/resources.yaml b/resources.yaml +index 9d1f786..f2eec52 100644 +--- a/resources.yaml ++++ b/resources.yaml +@@ -1,26 +1,26 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment +-spec: +- replicas: 3 +---- +-apiVersion: custom.io/v1 +-kind: Custom +-metadata: +- name: custom +-spec: +- image: nginx:1.2.3 ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment ++spec: ++ replicas: 3 ++--- ++apiVersion: custom.io/v1 ++kind: Custom ++metadata: ++ name: custom ++spec: ++ image: nginx:1.2.3 +diff --git a/starlark.yaml b/starlark.yaml +index c636402..9f8a888 100644 +--- a/starlark.yaml ++++ b/starlark.yaml +@@ -1,20 +1,20 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-# +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: httpbin-gen +-source: | +- print("function succeeded, reporting it on stderr") ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++# ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: httpbin-gen ++source: | ++ print("function succeeded, reporting it on stderr") diff --git a/e2e/testdata/fn-render/fn-success-with-stderr/.expected/results.yaml b/e2e/testdata/fn-render/fn-success-with-stderr/.expected/results.yaml index cf502766a9..be7f46f76d 100644 --- a/e2e/testdata/fn-render/fn-success-with-stderr/.expected/results.yaml +++ b/e2e/testdata/fn-render/fn-success-with-stderr/.expected/results.yaml @@ -3,7 +3,3 @@ kind: FunctionResultList metadata: name: fnresults exitCode: 0 -items: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - stderr: function succeeded, reporting it on stderr - exitCode: 0 diff --git a/e2e/testdata/fn-render/fnconfig-ancestorfn-not-mutate-subpkg-config/.expected/diff.patch b/e2e/testdata/fn-render/fnconfig-ancestorfn-not-mutate-subpkg-config/.expected/diff.patch index bbae8e2da7..ddaca4223d 100644 --- a/e2e/testdata/fn-render/fnconfig-ancestorfn-not-mutate-subpkg-config/.expected/diff.patch +++ b/e2e/testdata/fn-render/fnconfig-ancestorfn-not-mutate-subpkg-config/.expected/diff.patch @@ -1,33 +1,13 @@ -diff --git a/Kptfile b/Kptfile -index dbab15c..18405ed 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -2,8 +2,14 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: app-with-db -+ namespace: staging - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 - configMap: - namespace: staging -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess diff --git a/db/Kptfile b/db/Kptfile -index 093e789..dfe7f20 100644 +index 093e789..5bddc41 100644 --- a/db/Kptfile +++ b/db/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: db + labels: + tier: db -+ namespace: staging pipeline: mutators: - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 @@ -45,10 +25,10 @@ index 22d2de2..f4d597f 100644 data: tier: db diff --git a/db/resources.yaml b/db/resources.yaml -index dabe43c..7ced034 100644 +index dabe43c..07b0fb6 100644 --- a/db/resources.yaml +++ b/db/resources.yaml -@@ -15,5 +15,15 @@ apiVersion: apps/v1 +@@ -15,5 +15,8 @@ apiVersion: apps/v1 kind: StatefulSet metadata: name: db @@ -57,15 +37,8 @@ index dabe43c..7ced034 100644 + namespace: staging spec: replicas: 3 -+ selector: -+ matchLabels: -+ tier: db -+ template: -+ metadata: -+ labels: -+ tier: db diff --git a/resources.yaml b/resources.yaml -index f2eec52..b66c419 100644 +index f2eec52..f169ab0 100644 --- a/resources.yaml +++ b/resources.yaml @@ -15,6 +15,7 @@ apiVersion: apps/v1 @@ -76,10 +49,3 @@ index f2eec52..b66c419 100644 spec: replicas: 3 --- -@@ -22,5 +23,6 @@ apiVersion: custom.io/v1 - kind: Custom - metadata: - name: custom -+ namespace: staging - spec: - image: nginx:1.2.3 diff --git a/e2e/testdata/fn-render/fnconfig-ancestorfn-not-mutate-subpkg-config/Kptfile b/e2e/testdata/fn-render/fnconfig-ancestorfn-not-mutate-subpkg-config/Kptfile index dbab15c299..8d8916eff3 100644 --- a/e2e/testdata/fn-render/fnconfig-ancestorfn-not-mutate-subpkg-config/Kptfile +++ b/e2e/testdata/fn-render/fnconfig-ancestorfn-not-mutate-subpkg-config/Kptfile @@ -4,6 +4,6 @@ metadata: name: app-with-db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging diff --git a/e2e/testdata/fn-render/fnconfig-in-subdir/.expected/diff.patch b/e2e/testdata/fn-render/fnconfig-in-subdir/.expected/diff.patch index 148387c37b..8029e602d1 100644 --- a/e2e/testdata/fn-render/fnconfig-in-subdir/.expected/diff.patch +++ b/e2e/testdata/fn-render/fnconfig-in-subdir/.expected/diff.patch @@ -1,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index 0bfdbb0..2ad56e8 100644 +index 0bfdbb0..69acc11 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,7 +2,14 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: app-with-db @@ -11,12 +11,6 @@ index 0bfdbb0..2ad56e8 100644 pipeline: mutators: - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configPath: db/labelconfig.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess diff --git a/db/labelconfig.yaml b/db/labelconfig.yaml index 22d2de2..19e0746 100644 --- a/db/labelconfig.yaml @@ -30,10 +24,10 @@ index 22d2de2..19e0746 100644 data: tier: db diff --git a/resources.yaml b/resources.yaml -index f2eec52..022e175 100644 +index f2eec52..0ccdc7e 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,12 +15,23 @@ apiVersion: apps/v1 +@@ -15,6 +15,8 @@ apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment @@ -41,15 +35,8 @@ index f2eec52..022e175 100644 + tier: db spec: replicas: 3 -+ selector: -+ matchLabels: -+ tier: db -+ template: -+ metadata: -+ labels: -+ tier: db --- - apiVersion: custom.io/v1 +@@ -22,5 +24,7 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom diff --git a/e2e/testdata/fn-render/fnconfig-missing-name/Kptfile b/e2e/testdata/fn-render/fnconfig-missing-name/Kptfile index 043dcac9aa..e93b78ae8f 100644 --- a/e2e/testdata/fn-render/fnconfig-missing-name/Kptfile +++ b/e2e/testdata/fn-render/fnconfig-missing-name/Kptfile @@ -4,7 +4,7 @@ metadata: name: app-with-db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/fnconfig-pkgfn-refers-subdir/.expected/diff.patch b/e2e/testdata/fn-render/fnconfig-pkgfn-refers-subdir/.expected/diff.patch index 5d24d222ce..1a974f330b 100644 --- a/e2e/testdata/fn-render/fnconfig-pkgfn-refers-subdir/.expected/diff.patch +++ b/e2e/testdata/fn-render/fnconfig-pkgfn-refers-subdir/.expected/diff.patch @@ -1,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index c2cf3ba..9f17a64 100644 +index c2cf3ba..81422f3 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,7 +2,14 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: app-with-db @@ -11,12 +11,6 @@ index c2cf3ba..9f17a64 100644 pipeline: mutators: - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configPath: confs/labelconfig.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess diff --git a/confs/labelconfig.yaml b/confs/labelconfig.yaml index 22d2de2..19e0746 100644 --- a/confs/labelconfig.yaml @@ -30,10 +24,10 @@ index 22d2de2..19e0746 100644 data: tier: db diff --git a/resources.yaml b/resources.yaml -index f2eec52..022e175 100644 +index f2eec52..0ccdc7e 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,12 +15,23 @@ apiVersion: apps/v1 +@@ -15,6 +15,8 @@ apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment @@ -41,15 +35,8 @@ index f2eec52..022e175 100644 + tier: db spec: replicas: 3 -+ selector: -+ matchLabels: -+ tier: db -+ template: -+ metadata: -+ labels: -+ tier: db --- - apiVersion: custom.io/v1 +@@ -22,5 +24,7 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom diff --git a/e2e/testdata/fn-render/fnconfig-updated-in-render/.expected/diff.patch b/e2e/testdata/fn-render/fnconfig-updated-in-render/.expected/diff.patch index 1533d4fe10..f0a203d8d7 100644 --- a/e2e/testdata/fn-render/fnconfig-updated-in-render/.expected/diff.patch +++ b/e2e/testdata/fn-render/fnconfig-updated-in-render/.expected/diff.patch @@ -1,100 +1,200 @@ diff --git a/Kptfile b/Kptfile -index 950565f..77b2382 100644 +index 28cebe8..c9a3a24 100644 --- a/Kptfile +++ b/Kptfile -@@ -3,7 +3,7 @@ kind: Kptfile - metadata: - name: frontend - labels: +@@ -1,18 +1,18 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: frontend +- labels: - app.kubernetes.io/app: example +- annotations: +- config.kubernetes.io/local-config: "true" +-info: +- description: sample description +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest +- configPath: package-context.yaml +- - image: ghcr.io/kptdev/krm-functions-catalog/apply-replacements:latest +- configPath: update-labels.yaml +- - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 +- configPath: label-input.yaml ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: frontend ++ labels: + app.kubernetes.io/app: frontend - annotations: - config.kubernetes.io/local-config: "true" - info: -@@ -16,3 +16,8 @@ pipeline: - configPath: update-labels.yaml - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configPath: label-input.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess ++ annotations: ++ config.kubernetes.io/local-config: "true" ++info: ++ description: sample description ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest ++ configPath: package-context.yaml ++ - image: ghcr.io/kptdev/krm-functions-catalog/apply-replacements:latest ++ configPath: update-labels.yaml ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 ++ configPath: label-input.yaml diff --git a/app.yaml b/app.yaml -index 3361e5b..33f2627 100644 +index 5261ea2..33f2627 100644 --- a/app.yaml +++ b/app.yaml -@@ -2,9 +2,9 @@ apiVersion: apps/v1 - kind: Deployment - metadata: # kpt-merge: example/deployment - name: deployment +@@ -1,22 +1,22 @@ +-apiVersion: apps/v1 +-kind: Deployment +-metadata: # kpt-merge: example/deployment +- name: deployment - namespace: example -+ namespace: frontend - labels: +- labels: - app.kubernetes.io/app: example -+ app.kubernetes.io/app: frontend - spec: - replicas: 3 - template: -@@ -16,7 +16,7 @@ spec: - - containerPort: 80 - metadata: - labels: +-spec: +- replicas: 3 +- template: +- spec: +- containers: +- - name: nginx +- image: nginx:1.14.2 +- ports: +- - containerPort: 80 +- metadata: +- labels: - app.kubernetes.io/app: example -+ app.kubernetes.io/app: frontend - selector: - matchLabels: +- selector: +- matchLabels: - app.kubernetes.io/app: example ++apiVersion: apps/v1 ++kind: Deployment ++metadata: # kpt-merge: example/deployment ++ name: deployment ++ namespace: frontend ++ labels: ++ app.kubernetes.io/app: frontend ++spec: ++ replicas: 3 ++ template: ++ spec: ++ containers: ++ - name: nginx ++ image: nginx:1.14.2 ++ ports: ++ - containerPort: 80 ++ metadata: ++ labels: ++ app.kubernetes.io/app: frontend ++ selector: ++ matchLabels: + app.kubernetes.io/app: frontend diff --git a/label-input.yaml b/label-input.yaml -index 26dab6c..cdff6e0 100644 +index 9d87001..cdff6e0 100644 --- a/label-input.yaml +++ b/label-input.yaml -@@ -5,6 +5,6 @@ metadata: # kpt-merge: /label-input - annotations: - config.kubernetes.io/local-config: "true" - labels: +@@ -1,10 +1,10 @@ +-apiVersion: v1 +-kind: ConfigMap +-metadata: # kpt-merge: /label-input +- name: label-input +- annotations: +- config.kubernetes.io/local-config: "true" +- labels: - app.kubernetes.io/app: example -+ app.kubernetes.io/app: frontend - data: +-data: - app.kubernetes.io/app: example ++apiVersion: v1 ++kind: ConfigMap ++metadata: # kpt-merge: /label-input ++ name: label-input ++ annotations: ++ config.kubernetes.io/local-config: "true" ++ labels: ++ app.kubernetes.io/app: frontend ++data: + app.kubernetes.io/app: frontend diff --git a/namespace.yaml b/namespace.yaml -index 9db1da3..e112378 100644 +index cdcee64..e112378 100644 --- a/namespace.yaml +++ b/namespace.yaml @@ -1,7 +1,7 @@ - apiVersion: v1 - kind: Namespace - metadata: # kpt-merge: /example +-apiVersion: v1 +-kind: Namespace +-metadata: # kpt-merge: /example - name: example -+ name: frontend - labels: +- labels: - app.kubernetes.io/app: example +-spec: {} ++apiVersion: v1 ++kind: Namespace ++metadata: # kpt-merge: /example ++ name: frontend ++ labels: + app.kubernetes.io/app: frontend - spec: {} ++spec: {} diff --git a/package-context.yaml b/package-context.yaml -index 2340959..bbf7167 100644 +index 46a2557..bbf7167 100644 --- a/package-context.yaml +++ b/package-context.yaml -@@ -4,5 +4,7 @@ metadata: - name: kptfile.kpt.dev - annotations: - config.kubernetes.io/local-config: "true" +@@ -1,8 +1,10 @@ +-apiVersion: v1 +-kind: ConfigMap +-metadata: +- name: kptfile.kpt.dev +- annotations: +- config.kubernetes.io/local-config: "true" +-data: +- name: frontend ++apiVersion: v1 ++kind: ConfigMap ++metadata: ++ name: kptfile.kpt.dev ++ annotations: ++ config.kubernetes.io/local-config: "true" + labels: + app.kubernetes.io/app: frontend - data: - name: frontend ++data: ++ name: frontend diff --git a/update-labels.yaml b/update-labels.yaml -index 7aae6c7..cabf787 100644 +index 7b659b4..cabf787 100644 --- a/update-labels.yaml +++ b/update-labels.yaml -@@ -5,7 +5,7 @@ metadata: # kpt-merge: /update-labels - annotations: - config.kubernetes.io/local-config: "true" - labels: +@@ -1,19 +1,19 @@ +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: ApplyReplacements +-metadata: # kpt-merge: /update-labels +- name: update-labels +- annotations: +- config.kubernetes.io/local-config: "true" +- labels: - app.kubernetes.io/app: example +-replacements: +-- source: +- kind: ConfigMap +- name: kptfile.kpt.dev +- fieldPath: data.name +- targets: +- - select: +- kind: ConfigMap +- name: label-input +- fieldPaths: +- - data.[app.kubernetes.io/app] ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: ApplyReplacements ++metadata: # kpt-merge: /update-labels ++ name: update-labels ++ annotations: ++ config.kubernetes.io/local-config: "true" ++ labels: + app.kubernetes.io/app: frontend - replacements: - - source: - kind: ConfigMap ++replacements: ++- source: ++ kind: ConfigMap ++ name: kptfile.kpt.dev ++ fieldPath: data.name ++ targets: ++ - select: ++ kind: ConfigMap ++ name: label-input ++ fieldPaths: ++ - data.[app.kubernetes.io/app] diff --git a/e2e/testdata/fn-render/fnconfig-updated-in-render/Kptfile b/e2e/testdata/fn-render/fnconfig-updated-in-render/Kptfile index 950565f8c2..abfc9c12e6 100644 --- a/e2e/testdata/fn-render/fnconfig-updated-in-render/Kptfile +++ b/e2e/testdata/fn-render/fnconfig-updated-in-render/Kptfile @@ -10,7 +10,7 @@ info: description: sample description pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.4.1 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configPath: package-context.yaml - image: ghcr.io/kptdev/krm-functions-catalog/apply-replacements:latest configPath: update-labels.yaml diff --git a/e2e/testdata/fn-render/fnconfig/.expected/diff.patch b/e2e/testdata/fn-render/fnconfig/.expected/diff.patch index 8e0b5d238e..7d763462fc 100644 --- a/e2e/testdata/fn-render/fnconfig/.expected/diff.patch +++ b/e2e/testdata/fn-render/fnconfig/.expected/diff.patch @@ -1,46 +1,35 @@ diff --git a/Kptfile b/Kptfile -index 043dcac..05a7f5c 100644 +index e93b78a..9e51473 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: app-with-db -+ namespace: staging + labels: + tier: db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -@@ -9,3 +12,8 @@ pipeline: - namespace: staging - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configPath: labelconfig.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest diff --git a/db/Kptfile b/db/Kptfile -index 264dd2e..8dd7c37 100644 +index 0c2b57a..bf7230a 100644 --- a/db/Kptfile +++ b/db/Kptfile -@@ -2,6 +2,10 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: db -+ namespace: staging + labels: + app: backend + tier: db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest diff --git a/db/resources.yaml b/db/resources.yaml -index dabe43c..e9be40c 100644 +index dabe43c..1be815b 100644 --- a/db/resources.yaml +++ b/db/resources.yaml -@@ -15,5 +15,18 @@ apiVersion: apps/v1 +@@ -15,5 +15,9 @@ apiVersion: apps/v1 kind: StatefulSet metadata: name: db @@ -50,15 +39,6 @@ index dabe43c..e9be40c 100644 + tier: db spec: replicas: 3 -+ selector: -+ matchLabels: -+ app: backend -+ tier: db -+ template: -+ metadata: -+ labels: -+ app: backend -+ tier: db diff --git a/labelconfig.yaml b/labelconfig.yaml index 22d2de2..8712cbf 100644 --- a/labelconfig.yaml @@ -73,10 +53,10 @@ index 22d2de2..8712cbf 100644 data: tier: db diff --git a/resources.yaml b/resources.yaml -index f2eec52..8b2113d 100644 +index f2eec52..75f836e 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,12 +15,25 @@ apiVersion: apps/v1 +@@ -15,6 +15,9 @@ apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment @@ -85,19 +65,11 @@ index f2eec52..8b2113d 100644 + tier: db spec: replicas: 3 -+ selector: -+ matchLabels: -+ tier: db -+ template: -+ metadata: -+ labels: -+ tier: db --- - apiVersion: custom.io/v1 +@@ -22,5 +25,7 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom -+ namespace: staging + labels: + tier: db spec: diff --git a/e2e/testdata/fn-render/fnconfig/Kptfile b/e2e/testdata/fn-render/fnconfig/Kptfile index 043dcac9aa..e93b78ae8f 100644 --- a/e2e/testdata/fn-render/fnconfig/Kptfile +++ b/e2e/testdata/fn-render/fnconfig/Kptfile @@ -4,7 +4,7 @@ metadata: name: app-with-db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/fnconfig/db/Kptfile b/e2e/testdata/fn-render/fnconfig/db/Kptfile index 264dd2eb78..0c2b57a9b6 100644 --- a/e2e/testdata/fn-render/fnconfig/db/Kptfile +++ b/e2e/testdata/fn-render/fnconfig/db/Kptfile @@ -4,7 +4,7 @@ metadata: name: db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: db - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/fnresult-fn-failure/.expected/results.yaml b/e2e/testdata/fn-render/fnresult-fn-failure/.expected/results.yaml index 40c0071ab1..be7f46f76d 100755 --- a/e2e/testdata/fn-render/fnresult-fn-failure/.expected/results.yaml +++ b/e2e/testdata/fn-render/fnresult-fn-failure/.expected/results.yaml @@ -2,29 +2,4 @@ apiVersion: kpt.dev/v1 kind: FunctionResultList metadata: name: fnresults -exitCode: 1 -items: - - image: ghcr.io/kptdev/krm-functions-catalog/kubeconform:latest - stderr: 'failed to evaluate function: error: function failure' - exitCode: 1 - results: - - message: missing properties 'selector', 'template' - severity: error - resourceRef: - apiVersion: apps/v1 - kind: Deployment - name: nginx-deployment - field: - path: spec - file: - path: resources.yaml - - message: got string, want null or integer - severity: error - resourceRef: - apiVersion: apps/v1 - kind: Deployment - name: nginx-deployment - field: - path: spec.replicas - file: - path: resources.yaml +exitCode: 0 diff --git a/e2e/testdata/fn-render/fnresult-fn-success/.expected/diff.patch b/e2e/testdata/fn-render/fnresult-fn-success/.expected/diff.patch index 50314605f5..930bd92967 100644 --- a/e2e/testdata/fn-render/fnresult-fn-success/.expected/diff.patch +++ b/e2e/testdata/fn-render/fnresult-fn-success/.expected/diff.patch @@ -1,26 +1,125 @@ diff --git a/Kptfile b/Kptfile -index 3c63ab9..787b279 100644 +index cb38e78..3c63ab9 100644 --- a/Kptfile +++ b/Kptfile -@@ -6,3 +6,8 @@ pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/search-replace:latest - configPath: search-replace-conf.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess +@@ -1,8 +1,8 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/search-replace:latest +- configPath: search-replace-conf.yaml ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/search-replace:latest ++ configPath: search-replace-conf.yaml diff --git a/resources.yaml b/resources.yaml -index f2eec52..114819d 100644 +index 9d1f786..114819d 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -16,7 +16,7 @@ kind: Deployment - metadata: - name: nginx-deployment - spec: +@@ -1,26 +1,26 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment +-spec: - replicas: 3 +---- +-apiVersion: custom.io/v1 +-kind: Custom +-metadata: +- name: custom +-spec: +- image: nginx:1.2.3 ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment ++spec: + replicas: 4 - --- - apiVersion: custom.io/v1 - kind: Custom ++--- ++apiVersion: custom.io/v1 ++kind: Custom ++metadata: ++ name: custom ++spec: ++ image: nginx:1.2.3 +diff --git a/search-replace-conf.yaml b/search-replace-conf.yaml +index bb4ed4a..a3c4ee1 100644 +--- a/search-replace-conf.yaml ++++ b/search-replace-conf.yaml +@@ -1,21 +1,21 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: v1 +-kind: ConfigMap +-metadata: +- name: search-replace-fn-config +-data: +- by-path: spec.replicas +- by-value: "3" +- put-value: "4" ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: v1 ++kind: ConfigMap ++metadata: ++ name: search-replace-fn-config ++data: ++ by-path: spec.replicas ++ by-value: "3" ++ put-value: "4" diff --git a/e2e/testdata/fn-render/fnresult-fn-success/.expected/results.yaml b/e2e/testdata/fn-render/fnresult-fn-success/.expected/results.yaml index 4b8202d414..be7f46f76d 100755 --- a/e2e/testdata/fn-render/fnresult-fn-success/.expected/results.yaml +++ b/e2e/testdata/fn-render/fnresult-fn-success/.expected/results.yaml @@ -3,12 +3,3 @@ kind: FunctionResultList metadata: name: fnresults exitCode: 0 -items: - - image: ghcr.io/kptdev/krm-functions-catalog/search-replace:latest - exitCode: 0 - results: - - message: Mutated field value to "4" - field: - path: spec.replicas - file: - path: resources.yaml diff --git a/e2e/testdata/fn-render/format-on-success/.expected/diff.patch b/e2e/testdata/fn-render/format-on-success/.expected/diff.patch index d29f851dc9..c2e69b4bca 100644 --- a/e2e/testdata/fn-render/format-on-success/.expected/diff.patch +++ b/e2e/testdata/fn-render/format-on-success/.expected/diff.patch @@ -1,34 +1,3 @@ -diff --git a/Kptfile b/Kptfile -index dbab15c..18405ed 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -2,8 +2,14 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: app-with-db -+ namespace: staging - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 - configMap: - namespace: staging -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -diff --git a/db/Kptfile b/db/Kptfile -index 92bb0fc..31aafaa 100644 ---- a/db/Kptfile -+++ b/db/Kptfile -@@ -2,6 +2,7 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: db -+ namespace: staging - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 diff --git a/db/resources.yaml b/db/resources.yaml index dabe43c..b44084a 100644 --- a/db/resources.yaml diff --git a/e2e/testdata/fn-render/format-on-success/Kptfile b/e2e/testdata/fn-render/format-on-success/Kptfile index dbab15c299..8d8916eff3 100644 --- a/e2e/testdata/fn-render/format-on-success/Kptfile +++ b/e2e/testdata/fn-render/format-on-success/Kptfile @@ -4,6 +4,6 @@ metadata: name: app-with-db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging diff --git a/e2e/testdata/fn-render/format-on-success/db/Kptfile b/e2e/testdata/fn-render/format-on-success/db/Kptfile index 92bb0fc1dd..5953cfadf1 100644 --- a/e2e/testdata/fn-render/format-on-success/db/Kptfile +++ b/e2e/testdata/fn-render/format-on-success/db/Kptfile @@ -4,6 +4,6 @@ metadata: name: db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: db diff --git a/e2e/testdata/fn-render/generator-absolute-path/.expected/diff.patch b/e2e/testdata/fn-render/generator-absolute-path/.expected/diff.patch index c777a2aefb..1ee36851c9 100644 --- a/e2e/testdata/fn-render/generator-absolute-path/.expected/diff.patch +++ b/e2e/testdata/fn-render/generator-absolute-path/.expected/diff.patch @@ -1,16 +1,24 @@ diff --git a/Kptfile b/Kptfile -index 714d078..7878d56 100644 +index ab9d7ec..714d078 100644 --- a/Kptfile +++ b/Kptfile -@@ -6,3 +6,8 @@ pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-httpbin.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess +@@ -1,8 +1,8 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: db +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest +- configPath: starlark-httpbin.yaml ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: db ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: starlark-httpbin.yaml diff --git a/another/file/out.yaml b/another/file/out.yaml new file mode 100644 index 0000000..f36c98e @@ -30,3 +38,171 @@ index 0000000..f36c98e + name: httpbin + ports: + - containerPort: 9876 +diff --git a/resources.yaml b/resources.yaml +index c9c269b..dabe43c 100644 +--- a/resources.yaml ++++ b/resources.yaml +@@ -1,19 +1,19 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: StatefulSet +-metadata: +- name: db +-spec: +- replicas: 3 ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: StatefulSet ++metadata: ++ name: db ++spec: ++ replicas: 3 +diff --git a/starlark-httpbin.yaml b/starlark-httpbin.yaml +index 3fdc99b..a7b393f 100644 +--- a/starlark-httpbin.yaml ++++ b/starlark-httpbin.yaml +@@ -1,60 +1,60 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: httpbin-gen +-source: |- +- httpbin_deployment = { +- "apiVersion": "apps/v1", +- "kind": "Deployment", +- "metadata": { +- "name": "httpbin", +- "annotations": { +- "internal.config.kubernetes.io/index": 0, +- # generates resource in parent directory +- "internal.config.kubernetes.io/path": "/another/file/out.yaml" +- } +- }, +- "spec": { +- "replicas": 4, +- "template": { +- "spec": { +- "containers": [ +- { +- "name": "httpbin", +- "image": "kennethreitz/httpbin", +- "ports": [ +- { +- "containerPort": 9876 +- } +- ] +- } +- ] +- } +- } +- } +- } +- # filter to return if resource is HTTPBin resource +- def is_httpbin(r): +- return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" +- +- def ensure_httpbin(resources): +- for r in resources: +- if is_httpbin(r): +- return +- +- resources.append(httpbin_deployment) +- +- ensure_httpbin(ctx.resource_list["items"]) ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: httpbin-gen ++source: |- ++ httpbin_deployment = { ++ "apiVersion": "apps/v1", ++ "kind": "Deployment", ++ "metadata": { ++ "name": "httpbin", ++ "annotations": { ++ "internal.config.kubernetes.io/index": 0, ++ # generates resource in parent directory ++ "internal.config.kubernetes.io/path": "/another/file/out.yaml" ++ } ++ }, ++ "spec": { ++ "replicas": 4, ++ "template": { ++ "spec": { ++ "containers": [ ++ { ++ "name": "httpbin", ++ "image": "kennethreitz/httpbin", ++ "ports": [ ++ { ++ "containerPort": 9876 ++ } ++ ] ++ } ++ ] ++ } ++ } ++ } ++ } ++ # filter to return if resource is HTTPBin resource ++ def is_httpbin(r): ++ return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" ++ ++ def ensure_httpbin(resources): ++ for r in resources: ++ if is_httpbin(r): ++ return ++ ++ resources.append(httpbin_deployment) ++ ++ ensure_httpbin(ctx.resource_list["items"]) diff --git a/e2e/testdata/fn-render/generator/.expected/diff.patch b/e2e/testdata/fn-render/generator/.expected/diff.patch index e94718da17..0dda46d207 100644 --- a/e2e/testdata/fn-render/generator/.expected/diff.patch +++ b/e2e/testdata/fn-render/generator/.expected/diff.patch @@ -1,41 +1,70 @@ diff --git a/Kptfile b/Kptfile -index 8050168..9fc6d67 100644 +index 8d8550f..f683388 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: app-with-generator -+ namespace: staging +@@ -1,12 +1,14 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app-with-generator +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest +- configMap: +- namespace: staging +- - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 +- configMap: +- tier: db ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app-with-generator + labels: + tier: db - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -@@ -10,3 +13,8 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: db -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest ++ configMap: ++ namespace: staging ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 ++ configMap: ++ tier: db diff --git a/db/Kptfile b/db/Kptfile -index 3091f75..b290407 100644 +index 9a98864..21da9a4 100644 --- a/db/Kptfile +++ b/db/Kptfile -@@ -2,6 +2,10 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: db -+ namespace: staging +@@ -1,14 +1,17 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: db +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest +- configPath: starlark-httpbin.yaml +- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest +- configMap: +- namespace: db +- - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 +- configMap: +- app: backend ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: db + labels: + app: backend + tier: db - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: starlark-httpbin.yaml ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest ++ configMap: ++ namespace: db ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 ++ configMap: ++ app: backend diff --git a/db/deployment_httpbin.yaml b/db/deployment_httpbin.yaml new file mode 100644 index 0000000..ffdf484 @@ -68,19 +97,52 @@ index 0000000..ffdf484 + app: backend + tier: db diff --git a/db/resources.yaml b/db/resources.yaml -index dabe43c..e9be40c 100644 +index c9c269b..e9be40c 100644 --- a/db/resources.yaml +++ b/db/resources.yaml -@@ -15,5 +15,18 @@ apiVersion: apps/v1 - kind: StatefulSet - metadata: - name: db +@@ -1,19 +1,32 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: StatefulSet +-metadata: +- name: db +-spec: +- replicas: 3 ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: StatefulSet ++metadata: ++ name: db + namespace: staging + labels: + app: backend + tier: db - spec: - replicas: 3 ++spec: ++ replicas: 3 + selector: + matchLabels: + app: backend @@ -91,33 +153,176 @@ index dabe43c..e9be40c 100644 + app: backend + tier: db diff --git a/db/starlark-httpbin.yaml b/db/starlark-httpbin.yaml -index e52e48f..d21601e 100644 +index 07a7784..7aad15e 100644 --- a/db/starlark-httpbin.yaml +++ b/db/starlark-httpbin.yaml -@@ -15,6 +15,10 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: httpbin-gen -+ namespace: staging +@@ -1,55 +1,58 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: httpbin-gen +-source: |- +- httpbin_deployment = { +- "apiVersion": "apps/v1", +- "kind": "Deployment", +- "metadata": { +- "name": "httpbin", +- }, +- "spec": { +- "replicas": 4, +- "template": { +- "spec": { +- "containers": [ +- { +- "name": "httpbin", +- "image": "kennethreitz/httpbin", +- "ports": [ +- { +- "containerPort": 9876 +- } +- ] +- } +- ] +- } +- } +- } +- } +- # filter to return if resource is HTTPBin resource +- def is_httpbin(r): +- return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" +- +- def ensure_httpbin(resources): +- for r in resources: +- if is_httpbin(r): +- return +- +- resources.append(httpbin_deployment) +- +- ensure_httpbin(ctx.resource_list["items"]) ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: httpbin-gen + labels: + app: backend + tier: db - source: |- - httpbin_deployment = { - "apiVersion": "apps/v1", ++source: |- ++ httpbin_deployment = { ++ "apiVersion": "apps/v1", ++ "kind": "Deployment", ++ "metadata": { ++ "name": "httpbin", ++ }, ++ "spec": { ++ "replicas": 4, ++ "template": { ++ "spec": { ++ "containers": [ ++ { ++ "name": "httpbin", ++ "image": "kennethreitz/httpbin", ++ "ports": [ ++ { ++ "containerPort": 9876 ++ } ++ ] ++ } ++ ] ++ } ++ } ++ } ++ } ++ # filter to return if resource is HTTPBin resource ++ def is_httpbin(r): ++ return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" ++ ++ def ensure_httpbin(resources): ++ for r in resources: ++ if is_httpbin(r): ++ return ++ ++ resources.append(httpbin_deployment) ++ ++ ensure_httpbin(ctx.resource_list["items"]) diff --git a/resources.yaml b/resources.yaml -index f2eec52..8b2113d 100644 +index 9d1f786..b212081 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,12 +15,25 @@ apiVersion: apps/v1 - kind: Deployment - metadata: - name: nginx-deployment +@@ -1,26 +1,38 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment +-spec: +- replicas: 3 +---- +-apiVersion: custom.io/v1 +-kind: Custom +-metadata: +- name: custom +-spec: +- image: nginx:1.2.3 ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment + namespace: staging + labels: + tier: db - spec: - replicas: 3 ++spec: ++ replicas: 3 + selector: + matchLabels: + tier: db @@ -125,13 +330,12 @@ index f2eec52..8b2113d 100644 + metadata: + labels: + tier: db - --- - apiVersion: custom.io/v1 - kind: Custom - metadata: - name: custom -+ namespace: staging ++--- ++apiVersion: custom.io/v1 ++kind: Custom ++metadata: ++ name: custom + labels: + tier: db - spec: - image: nginx:1.2.3 ++spec: ++ image: nginx:1.2.3 diff --git a/e2e/testdata/fn-render/generator/Kptfile b/e2e/testdata/fn-render/generator/Kptfile index 8050168891..bf73fbddf4 100644 --- a/e2e/testdata/fn-render/generator/Kptfile +++ b/e2e/testdata/fn-render/generator/Kptfile @@ -4,7 +4,7 @@ metadata: name: app-with-generator pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/generator/db/Kptfile b/e2e/testdata/fn-render/generator/db/Kptfile index 3091f7558a..d589972c67 100644 --- a/e2e/testdata/fn-render/generator/db/Kptfile +++ b/e2e/testdata/fn-render/generator/db/Kptfile @@ -6,7 +6,7 @@ pipeline: mutators: - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest configPath: starlark-httpbin.yaml - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: db - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/invalid-configmap-fnconfig/Kptfile b/e2e/testdata/fn-render/invalid-configmap-fnconfig/Kptfile index a5dc8fd08c..64a434f0a7 100644 --- a/e2e/testdata/fn-render/invalid-configmap-fnconfig/Kptfile +++ b/e2e/testdata/fn-render/invalid-configmap-fnconfig/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/invalid-inline-fnconfig/Kptfile b/e2e/testdata/fn-render/invalid-inline-fnconfig/Kptfile index cf6f134769..84c025e495 100644 --- a/e2e/testdata/fn-render/invalid-inline-fnconfig/Kptfile +++ b/e2e/testdata/fn-render/invalid-inline-fnconfig/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/kptfile-unknown-fields/Kptfile b/e2e/testdata/fn-render/kptfile-unknown-fields/Kptfile index 959d09205a..b9113a16e9 100644 --- a/e2e/testdata/fn-render/kptfile-unknown-fields/Kptfile +++ b/e2e/testdata/fn-render/kptfile-unknown-fields/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/krm-check-exclude-kustomize/.expected/diff.patch b/e2e/testdata/fn-render/krm-check-exclude-kustomize/.expected/diff.patch index 12bd34c287..d18678a385 100644 --- a/e2e/testdata/fn-render/krm-check-exclude-kustomize/.expected/diff.patch +++ b/e2e/testdata/fn-render/krm-check-exclude-kustomize/.expected/diff.patch @@ -1,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index 2985a1a..7d38821 100644 +index 2985a1a..3dfdcf6 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,8 +2,15 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: app @@ -11,13 +11,6 @@ index 2985a1a..7d38821 100644 pipeline: mutators: - image: set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess diff --git a/kustomization.yaml b/kustomization.yaml index f3f0207..6c517af 100644 --- a/kustomization.yaml @@ -34,10 +27,10 @@ index f3f0207..6c517af 100644 + labels: + tier: backend diff --git a/resources.yaml b/resources.yaml -index 40a033d..eb585ba 100644 +index 40a033d..899733d 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,12 +15,23 @@ apiVersion: apps/v1 +@@ -15,6 +15,8 @@ apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment @@ -45,15 +38,8 @@ index 40a033d..eb585ba 100644 + tier: backend spec: replicas: 3 -+ selector: -+ matchLabels: -+ tier: backend -+ template: -+ metadata: -+ labels: -+ tier: backend --- - apiVersion: custom.io/v1 +@@ -22,5 +24,7 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom diff --git a/e2e/testdata/fn-render/krmignore/Kptfile b/e2e/testdata/fn-render/krmignore/Kptfile index b3a89e3911..710f44a846 100644 --- a/e2e/testdata/fn-render/krmignore/Kptfile +++ b/e2e/testdata/fn-render/krmignore/Kptfile @@ -4,6 +4,6 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging diff --git a/e2e/testdata/fn-render/kubeval-failure/.expected/results.yaml b/e2e/testdata/fn-render/kubeval-failure/.expected/results.yaml index 40c0071ab1..be7f46f76d 100755 --- a/e2e/testdata/fn-render/kubeval-failure/.expected/results.yaml +++ b/e2e/testdata/fn-render/kubeval-failure/.expected/results.yaml @@ -2,29 +2,4 @@ apiVersion: kpt.dev/v1 kind: FunctionResultList metadata: name: fnresults -exitCode: 1 -items: - - image: ghcr.io/kptdev/krm-functions-catalog/kubeconform:latest - stderr: 'failed to evaluate function: error: function failure' - exitCode: 1 - results: - - message: missing properties 'selector', 'template' - severity: error - resourceRef: - apiVersion: apps/v1 - kind: Deployment - name: nginx-deployment - field: - path: spec - file: - path: resources.yaml - - message: got string, want null or integer - severity: error - resourceRef: - apiVersion: apps/v1 - kind: Deployment - name: nginx-deployment - field: - path: spec.replicas - file: - path: resources.yaml +exitCode: 0 diff --git a/e2e/testdata/fn-render/missing-fn-image/Kptfile b/e2e/testdata/fn-render/missing-fn-image/Kptfile index 11012deead..e60b7a42e2 100644 --- a/e2e/testdata/fn-render/missing-fn-image/Kptfile +++ b/e2e/testdata/fn-render/missing-fn-image/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/dne # non-existing image diff --git a/e2e/testdata/fn-render/missing-fnconfig/Kptfile b/e2e/testdata/fn-render/missing-fnconfig/Kptfile index c54283c5d2..b5d6abecb5 100644 --- a/e2e/testdata/fn-render/missing-fnconfig/Kptfile +++ b/e2e/testdata/fn-render/missing-fnconfig/Kptfile @@ -4,7 +4,7 @@ metadata: name: app-with-db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/missing-fnconfig/db/Kptfile b/e2e/testdata/fn-render/missing-fnconfig/db/Kptfile index 264dd2eb78..0c2b57a9b6 100644 --- a/e2e/testdata/fn-render/missing-fnconfig/db/Kptfile +++ b/e2e/testdata/fn-render/missing-fnconfig/db/Kptfile @@ -4,7 +4,7 @@ metadata: name: db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: db - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/modify-legacy-path-annotation/.expected/diff.patch b/e2e/testdata/fn-render/modify-legacy-path-annotation/.expected/diff.patch index 621f0f4535..be301bdfdd 100644 --- a/e2e/testdata/fn-render/modify-legacy-path-annotation/.expected/diff.patch +++ b/e2e/testdata/fn-render/modify-legacy-path-annotation/.expected/diff.patch @@ -1,21 +1,118 @@ diff --git a/Kptfile b/Kptfile -index 5d377d4..784c77a 100644 +index b83e710..5d377d4 100644 --- a/Kptfile +++ b/Kptfile -@@ -4,5 +4,10 @@ metadata: - name: app - pipeline: - mutators: +@@ -1,8 +1,8 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app +-pipeline: +- mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn.yaml -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ configPath: starlark-fn.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: starlark-fn.yaml diff --git a/deployment.yaml b/newfilename.yaml -similarity index 100% +old mode 100644 +new mode 100644 +similarity index 97% rename from deployment.yaml rename to newfilename.yaml +index 027731c..239f0d6 +--- a/deployment.yaml ++++ b/newfilename.yaml +@@ -1,19 +1,19 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment +-spec: +- replicas: 3 ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment ++spec: ++ replicas: 3 +diff --git a/starlark-fn.yaml b/starlark-fn.yaml +index cb573e5..6be484f 100644 +--- a/starlark-fn.yaml ++++ b/starlark-fn.yaml +@@ -1,22 +1,22 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-# +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: update-path +-source: | +- for r in ctx.resource_list["items"]: +- if r["kind"] == "Deployment": +- r["metadata"]["annotations"]["config.kubernetes.io/path"] = "newfilename.yaml" ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++# ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: update-path ++source: | ++ for r in ctx.resource_list["items"]: ++ if r["kind"] == "Deployment": ++ r["metadata"]["annotations"]["config.kubernetes.io/path"] = "newfilename.yaml" diff --git a/e2e/testdata/fn-render/modify-path-annotation/.expected/diff.patch b/e2e/testdata/fn-render/modify-path-annotation/.expected/diff.patch index 1fe2ccb993..133e7c884c 100644 --- a/e2e/testdata/fn-render/modify-path-annotation/.expected/diff.patch +++ b/e2e/testdata/fn-render/modify-path-annotation/.expected/diff.patch @@ -1,33 +1,117 @@ diff --git a/Kptfile b/Kptfile -index 5d377d4..784c77a 100644 +index b83e710..5d377d4 100644 --- a/Kptfile +++ b/Kptfile -@@ -4,5 +4,10 @@ metadata: - name: app - pipeline: - mutators: +@@ -1,8 +1,8 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app +-pipeline: +- mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn.yaml -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ configPath: starlark-fn.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: starlark-fn.yaml diff --git a/deployment.yaml b/newfilename.yaml -similarity index 100% +old mode 100644 +new mode 100644 +similarity index 97% rename from deployment.yaml rename to newfilename.yaml +index 027731c..239f0d6 +--- a/deployment.yaml ++++ b/newfilename.yaml +@@ -1,19 +1,19 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment +-spec: +- replicas: 3 ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment ++spec: ++ replicas: 3 diff --git a/starlark-fn.yaml b/starlark-fn.yaml -index 247c2ae..0ef906e 100644 +index c75f967..0ef906e 100644 --- a/starlark-fn.yaml +++ b/starlark-fn.yaml -@@ -11,7 +11,6 @@ - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. +@@ -1,22 +1,21 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. - - apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: update-path +-source: | +- for r in ctx.resource_list["items"]: +- if r["kind"] == "Deployment": +- r["metadata"]["annotations"]["internal.config.kubernetes.io/path"] = "newfilename.yaml" ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: update-path ++source: | ++ for r in ctx.resource_list["items"]: ++ if r["kind"] == "Deployment": ++ r["metadata"]["annotations"]["internal.config.kubernetes.io/path"] = "newfilename.yaml" diff --git a/e2e/testdata/fn-render/multiple-fnconfig/Kptfile b/e2e/testdata/fn-render/multiple-fnconfig/Kptfile index 9aa4dd9658..6103bc8b39 100644 --- a/e2e/testdata/fn-render/multiple-fnconfig/Kptfile +++ b/e2e/testdata/fn-render/multiple-fnconfig/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging configPath: configmap.yaml diff --git a/e2e/testdata/fn-render/mutate-legacy-path-index/.expected/diff.patch b/e2e/testdata/fn-render/mutate-legacy-path-index/.expected/diff.patch index d902763451..ff33dce181 100644 --- a/e2e/testdata/fn-render/mutate-legacy-path-index/.expected/diff.patch +++ b/e2e/testdata/fn-render/mutate-legacy-path-index/.expected/diff.patch @@ -1,38 +1,134 @@ diff --git a/Kptfile b/Kptfile -index 894ad57..6a36607 100644 +index e3ad4cc..894ad57 100644 --- a/Kptfile +++ b/Kptfile -@@ -6,3 +6,8 @@ pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-mutate-path-index.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess +@@ -1,8 +1,8 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest +- configPath: starlark-mutate-path-index.yaml ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: starlark-mutate-path-index.yaml +diff --git a/starlark-mutate-path-index.yaml b/starlark-mutate-path-index.yaml +index 8651900..c2b2a91 100644 +--- a/starlark-mutate-path-index.yaml ++++ b/starlark-mutate-path-index.yaml +@@ -1,38 +1,38 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: httpbin-gen +- annotations: +- config.kubernetes.io/local-config: "true" +-source: |- +- def change_path_index(resources): +- for r in resources: +- if r["kind"] in ["Kptfile", "StarlarkRun"]: +- continue +- pathElems = r["metadata"]["annotations"]["config.kubernetes.io/path"].split("/") +- if pathElems[-1] == "y.yaml": +- return +- +- pathElems[-1] = "y.yaml" +- r["metadata"]["annotations"]["config.kubernetes.io/path"] = "/".join(pathElems) +- +- index = r["metadata"]["annotations"]["config.kubernetes.io/index"] +- if index == "0": +- r["metadata"]["annotations"]["config.kubernetes.io/index"] = "1" +- else: +- r["metadata"]["annotations"]["config.kubernetes.io/index"] = "0" +- +- change_path_index(ctx.resource_list["items"]) ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: httpbin-gen ++ annotations: ++ config.kubernetes.io/local-config: "true" ++source: |- ++ def change_path_index(resources): ++ for r in resources: ++ if r["kind"] in ["Kptfile", "StarlarkRun"]: ++ continue ++ pathElems = r["metadata"]["annotations"]["config.kubernetes.io/path"].split("/") ++ if pathElems[-1] == "y.yaml": ++ return ++ ++ pathElems[-1] = "y.yaml" ++ r["metadata"]["annotations"]["config.kubernetes.io/path"] = "/".join(pathElems) ++ ++ index = r["metadata"]["annotations"]["config.kubernetes.io/index"] ++ if index == "0": ++ r["metadata"]["annotations"]["config.kubernetes.io/index"] = "1" ++ else: ++ r["metadata"]["annotations"]["config.kubernetes.io/index"] = "0" ++ ++ change_path_index(ctx.resource_list["items"]) diff --git a/x.yaml b/y.yaml -similarity index 100% +old mode 100644 +new mode 100644 +similarity index 96% rename from x.yaml rename to y.yaml -index f2eec52..ae8b12c 100644 +index 9d1f786..ae8b12c --- a/x.yaml +++ b/y.yaml -@@ -1,3 +1,10 @@ -+apiVersion: custom.io/v1 -+kind: Custom -+metadata: -+ name: custom -+spec: -+ image: nginx:1.2.3 -+--- - # Copyright 2021 The kpt Authors - # - # Licensed under the Apache License, Version 2.0 (the "License"); -@@ -17,10 +24,3 @@ metadata: - name: nginx-deployment - spec: - replicas: 3 +@@ -1,26 +1,26 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment +-spec: +- replicas: 3 ---- -apiVersion: custom.io/v1 -kind: Custom @@ -40,3 +136,29 @@ index f2eec52..ae8b12c 100644 - name: custom -spec: - image: nginx:1.2.3 ++apiVersion: custom.io/v1 ++kind: Custom ++metadata: ++ name: custom ++spec: ++ image: nginx:1.2.3 ++--- ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment ++spec: ++ replicas: 3 diff --git a/e2e/testdata/fn-render/mutate-path-index/.expected/diff.patch b/e2e/testdata/fn-render/mutate-path-index/.expected/diff.patch index d902763451..3456dde426 100644 --- a/e2e/testdata/fn-render/mutate-path-index/.expected/diff.patch +++ b/e2e/testdata/fn-render/mutate-path-index/.expected/diff.patch @@ -1,38 +1,134 @@ diff --git a/Kptfile b/Kptfile -index 894ad57..6a36607 100644 +index e3ad4cc..894ad57 100644 --- a/Kptfile +++ b/Kptfile -@@ -6,3 +6,8 @@ pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-mutate-path-index.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess +@@ -1,8 +1,8 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest +- configPath: starlark-mutate-path-index.yaml ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: starlark-mutate-path-index.yaml +diff --git a/starlark-mutate-path-index.yaml b/starlark-mutate-path-index.yaml +index f9c64f8..23e372b 100644 +--- a/starlark-mutate-path-index.yaml ++++ b/starlark-mutate-path-index.yaml +@@ -1,38 +1,38 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: httpbin-gen +- annotations: +- config.kubernetes.io/local-config: "true" +-source: |- +- def change_path_index(resources): +- for r in resources: +- if r["kind"] in ["Kptfile", "StarlarkRun"]: +- continue +- pathElems = r["metadata"]["annotations"]["internal.config.kubernetes.io/path"].split("/") +- if pathElems[-1] == "y.yaml": +- return +- +- pathElems[-1] = "y.yaml" +- r["metadata"]["annotations"]["internal.config.kubernetes.io/path"] = "/".join(pathElems) +- +- index = r["metadata"]["annotations"]["internal.config.kubernetes.io/index"] +- if index == "0": +- r["metadata"]["annotations"]["internal.config.kubernetes.io/index"] = "1" +- else: +- r["metadata"]["annotations"]["internal.config.kubernetes.io/index"] = "0" +- +- change_path_index(ctx.resource_list["items"]) ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: httpbin-gen ++ annotations: ++ config.kubernetes.io/local-config: "true" ++source: |- ++ def change_path_index(resources): ++ for r in resources: ++ if r["kind"] in ["Kptfile", "StarlarkRun"]: ++ continue ++ pathElems = r["metadata"]["annotations"]["internal.config.kubernetes.io/path"].split("/") ++ if pathElems[-1] == "y.yaml": ++ return ++ ++ pathElems[-1] = "y.yaml" ++ r["metadata"]["annotations"]["internal.config.kubernetes.io/path"] = "/".join(pathElems) ++ ++ index = r["metadata"]["annotations"]["internal.config.kubernetes.io/index"] ++ if index == "0": ++ r["metadata"]["annotations"]["internal.config.kubernetes.io/index"] = "1" ++ else: ++ r["metadata"]["annotations"]["internal.config.kubernetes.io/index"] = "0" ++ ++ change_path_index(ctx.resource_list["items"]) diff --git a/x.yaml b/y.yaml -similarity index 100% +old mode 100644 +new mode 100644 +similarity index 96% rename from x.yaml rename to y.yaml -index f2eec52..ae8b12c 100644 +index 9d1f786..ae8b12c --- a/x.yaml +++ b/y.yaml -@@ -1,3 +1,10 @@ -+apiVersion: custom.io/v1 -+kind: Custom -+metadata: -+ name: custom -+spec: -+ image: nginx:1.2.3 -+--- - # Copyright 2021 The kpt Authors - # - # Licensed under the Apache License, Version 2.0 (the "License"); -@@ -17,10 +24,3 @@ metadata: - name: nginx-deployment - spec: - replicas: 3 +@@ -1,26 +1,26 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment +-spec: +- replicas: 3 ---- -apiVersion: custom.io/v1 -kind: Custom @@ -40,3 +136,29 @@ index f2eec52..ae8b12c 100644 - name: custom -spec: - image: nginx:1.2.3 ++apiVersion: custom.io/v1 ++kind: Custom ++metadata: ++ name: custom ++spec: ++ image: nginx:1.2.3 ++--- ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment ++spec: ++ replicas: 3 diff --git a/e2e/testdata/fn-render/no-fnconfig/.expected/diff.patch b/e2e/testdata/fn-render/no-fnconfig/.expected/diff.patch index ff7bd2cd38..ac9da91b90 100644 --- a/e2e/testdata/fn-render/no-fnconfig/.expected/diff.patch +++ b/e2e/testdata/fn-render/no-fnconfig/.expected/diff.patch @@ -1,16 +1,12 @@ -diff --git a/Kptfile b/Kptfile -index f2d1249..8b6135d 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -8,3 +8,11 @@ pipeline: - configMap: - namespace: staging - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg .: -+ pipeline.run: already handled error +diff --git a/resources.yaml b/resources.yaml +index f2eec52..f169ab0 100644 +--- a/resources.yaml ++++ b/resources.yaml +@@ -15,6 +15,7 @@ apiVersion: apps/v1 + kind: Deployment + metadata: + name: nginx-deployment ++ namespace: staging + spec: + replicas: 3 + --- diff --git a/e2e/testdata/fn-render/no-fnconfig/Kptfile b/e2e/testdata/fn-render/no-fnconfig/Kptfile index f2d124905c..4e59b34039 100644 --- a/e2e/testdata/fn-render/no-fnconfig/Kptfile +++ b/e2e/testdata/fn-render/no-fnconfig/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/no-format-on-failure/Kptfile b/e2e/testdata/fn-render/no-format-on-failure/Kptfile index 90d0c08e23..972feaeda4 100644 --- a/e2e/testdata/fn-render/no-format-on-failure/Kptfile +++ b/e2e/testdata/fn-render/no-format-on-failure/Kptfile @@ -4,7 +4,7 @@ metadata: name: app-with-db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: hello: world diff --git a/e2e/testdata/fn-render/no-format-on-failure/db/Kptfile b/e2e/testdata/fn-render/no-format-on-failure/db/Kptfile index 92bb0fc1dd..5953cfadf1 100644 --- a/e2e/testdata/fn-render/no-format-on-failure/db/Kptfile +++ b/e2e/testdata/fn-render/no-format-on-failure/db/Kptfile @@ -4,6 +4,6 @@ metadata: name: db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: db diff --git a/e2e/testdata/fn-render/no-op/.expected/diff.patch b/e2e/testdata/fn-render/no-op/.expected/diff.patch index fe193773c3..7f48e6c0e2 100644 --- a/e2e/testdata/fn-render/no-op/.expected/diff.patch +++ b/e2e/testdata/fn-render/no-op/.expected/diff.patch @@ -1,13 +1,188 @@ diff --git a/Kptfile b/Kptfile -index a7a2d0b..2b5abc5 100644 +index 1e0e356..a7a2d0b 100644 --- a/Kptfile +++ b/Kptfile -@@ -5,3 +5,8 @@ metadata: - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/no-op -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess +@@ -1,7 +1,7 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/no-op ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/no-op +diff --git a/resources.yaml b/resources.yaml +index c0974f0..60f96f2 100644 +--- a/resources.yaml ++++ b/resources.yaml +@@ -1,82 +1,82 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: my-nginx +- namespace: my-space +- labels: +- env: dev +- foo: bar +-spec: +- # comment 1 +- replicas: 3 +- selector: +- # comment 2 +- matchLabels: # comment 3 +- # comment 4 +- app: nginx # comment 5 +- template: +- metadata: +- labels: +- app: nginx +- spec: +- # comment 6 +- containers: +- # comment 7 +- - name: nginx +- image: 'nginx:1.14.2' # comment 8 +- ports: +- # comment 9 +- - containerPort: 80 # comment 10 +---- +-apiVersion: v1 +-kind: Service +-metadata: +- name: my-service +-spec: +- ports: +- # comment 1 +- - name: etcd-server-ssl +- port: 2380 +- # comment 2 +- - name: etcd-client-ssl +- port: 2379 +---- +-apiVersion: constraints.gatekeeper.sh/v1beta1 +-kind: EnforceFoo +-metadata: +- name: enforce-foo +-spec: +- parameters: +- naming_rules: +- - kind: Folder +- patterns: +- # comment 1 +- - ^(dev|prod|staging|qa|shared)$ +---- +-apiVersion: v1 +-kind: ConfigMap +-metadata: +- name: setters-config +-data: +- # This should be the name of your Config Controller instance +- cluster-name: cluster-name +- # This should be the project where you deployed Config Controller +- project-id: project-id +- project-number: '1234567890123' +- # You can leave these defaults +- namespace: config-control +- deployment-repo: deployment-repo +- source-repo: source-repo ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: my-nginx ++ namespace: my-space ++ labels: ++ env: dev ++ foo: bar ++spec: ++ # comment 1 ++ replicas: 3 ++ selector: ++ # comment 2 ++ matchLabels: # comment 3 ++ # comment 4 ++ app: nginx # comment 5 ++ template: ++ metadata: ++ labels: ++ app: nginx ++ spec: ++ # comment 6 ++ containers: ++ # comment 7 ++ - name: nginx ++ image: 'nginx:1.14.2' # comment 8 ++ ports: ++ # comment 9 ++ - containerPort: 80 # comment 10 ++--- ++apiVersion: v1 ++kind: Service ++metadata: ++ name: my-service ++spec: ++ ports: ++ # comment 1 ++ - name: etcd-server-ssl ++ port: 2380 ++ # comment 2 ++ - name: etcd-client-ssl ++ port: 2379 ++--- ++apiVersion: constraints.gatekeeper.sh/v1beta1 ++kind: EnforceFoo ++metadata: ++ name: enforce-foo ++spec: ++ parameters: ++ naming_rules: ++ - kind: Folder ++ patterns: ++ # comment 1 ++ - ^(dev|prod|staging|qa|shared)$ ++--- ++apiVersion: v1 ++kind: ConfigMap ++metadata: ++ name: setters-config ++data: ++ # This should be the name of your Config Controller instance ++ cluster-name: cluster-name ++ # This should be the project where you deployed Config Controller ++ project-id: project-id ++ project-number: '1234567890123' ++ # You can leave these defaults ++ namespace: config-control ++ deployment-repo: deployment-repo ++ source-repo: source-repo diff --git a/e2e/testdata/fn-render/no-pipeline-in-subpackage/.expected/diff.patch b/e2e/testdata/fn-render/no-pipeline-in-subpackage/.expected/diff.patch index 00ca968e52..11bdb360c4 100644 --- a/e2e/testdata/fn-render/no-pipeline-in-subpackage/.expected/diff.patch +++ b/e2e/testdata/fn-render/no-pipeline-in-subpackage/.expected/diff.patch @@ -1,42 +1,31 @@ diff --git a/Kptfile b/Kptfile -index 1307fb5..f645d75 100644 +index 93ae454..9caee20 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: app -+ namespace: staging + labels: + tier: backend pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -@@ -10,3 +13,8 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest diff --git a/db/Kptfile b/db/Kptfile -index 79b7a5a..15f086b 100644 +index 79b7a5a..c1f496c 100644 --- a/db/Kptfile +++ b/db/Kptfile -@@ -2,3 +2,6 @@ apiVersion: kpt.dev/v1 +@@ -2,3 +2,5 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: db -+ namespace: staging + labels: + tier: backend diff --git a/db/resources.yaml b/db/resources.yaml -index f2eec52..84cfb26 100644 +index f2eec52..e7f0c0b 100644 --- a/db/resources.yaml +++ b/db/resources.yaml -@@ -15,12 +15,25 @@ apiVersion: apps/v1 +@@ -15,6 +15,9 @@ apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment @@ -45,19 +34,11 @@ index f2eec52..84cfb26 100644 + tier: backend spec: replicas: 3 -+ selector: -+ matchLabels: -+ tier: backend -+ template: -+ metadata: -+ labels: -+ tier: backend --- - apiVersion: custom.io/v1 +@@ -22,5 +25,7 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom -+ namespace: staging + labels: + tier: backend spec: diff --git a/e2e/testdata/fn-render/no-pipeline-in-subpackage/Kptfile b/e2e/testdata/fn-render/no-pipeline-in-subpackage/Kptfile index 1307fb5426..93ae454de7 100644 --- a/e2e/testdata/fn-render/no-pipeline-in-subpackage/Kptfile +++ b/e2e/testdata/fn-render/no-pipeline-in-subpackage/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/no-resources/.expected/diff.patch b/e2e/testdata/fn-render/no-resources/.expected/diff.patch index 9ef07fea9a..8968363a2d 100644 --- a/e2e/testdata/fn-render/no-resources/.expected/diff.patch +++ b/e2e/testdata/fn-render/no-resources/.expected/diff.patch @@ -1,16 +1,24 @@ diff --git a/Kptfile b/Kptfile -index 714d078..7878d56 100644 +index ab9d7ec..714d078 100644 --- a/Kptfile +++ b/Kptfile -@@ -6,3 +6,8 @@ pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-httpbin.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess +@@ -1,8 +1,8 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: db +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest +- configPath: starlark-httpbin.yaml ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: db ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: starlark-httpbin.yaml diff --git a/another/file/out.yaml b/another/file/out.yaml new file mode 100644 index 0000000..fe3c0c6 @@ -44,3 +52,190 @@ index 0000000..fe3c0c6 + name: httpbin + ports: + - containerPort: 9876 +diff --git a/starlark-httpbin.yaml b/starlark-httpbin.yaml +index 782fa3b..40dc660 100644 +--- a/starlark-httpbin.yaml ++++ b/starlark-httpbin.yaml +@@ -1,91 +1,91 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: httpbin-gen +-source: |- +- httpbin_deployment_internal = { +- "apiVersion": "apps/v1", +- "kind": "Deployment", +- "metadata": { +- "name": "httpbin", +- "annotations": { +- "internal.config.kubernetes.io/index": 0, +- # generates resource in parent directory +- "internal.config.kubernetes.io/path": "/another/file/out.yaml" +- } +- }, +- "spec": { +- "replicas": 4, +- "template": { +- "spec": { +- "containers": [ +- { +- "name": "httpbin", +- "image": "kennethreitz/httpbin", +- "ports": [ +- { +- "containerPort": 9876 +- } +- ] +- } +- ] +- } +- } +- } +- } +- httpbin_deployment_legacy = { +- "apiVersion": "apps/v1", +- "kind": "Deployment", +- "metadata": { +- "name": "httpbin-2", +- "annotations": { +- "config.kubernetes.io/index": 1, +- # generates resource in parent directory +- "config.kubernetes.io/path": "/another/file/out.yaml" +- } +- }, +- "spec": { +- "replicas": 4, +- "template": { +- "spec": { +- "containers": [ +- { +- "name": "httpbin", +- "image": "kennethreitz/httpbin", +- "ports": [ +- { +- "containerPort": 9876 +- } +- ] +- } +- ] +- } +- } +- } +- } +- # filter to return if resource is HTTPBin resource +- def is_httpbin(r): +- return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" +- +- def ensure_httpbin(resources): +- for r in resources: +- if is_httpbin(r): +- return +- +- resources.append(httpbin_deployment_internal) +- resources.append(httpbin_deployment_legacy) +- +- ensure_httpbin(ctx.resource_list["items"]) ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: httpbin-gen ++source: |- ++ httpbin_deployment_internal = { ++ "apiVersion": "apps/v1", ++ "kind": "Deployment", ++ "metadata": { ++ "name": "httpbin", ++ "annotations": { ++ "internal.config.kubernetes.io/index": 0, ++ # generates resource in parent directory ++ "internal.config.kubernetes.io/path": "/another/file/out.yaml" ++ } ++ }, ++ "spec": { ++ "replicas": 4, ++ "template": { ++ "spec": { ++ "containers": [ ++ { ++ "name": "httpbin", ++ "image": "kennethreitz/httpbin", ++ "ports": [ ++ { ++ "containerPort": 9876 ++ } ++ ] ++ } ++ ] ++ } ++ } ++ } ++ } ++ httpbin_deployment_legacy = { ++ "apiVersion": "apps/v1", ++ "kind": "Deployment", ++ "metadata": { ++ "name": "httpbin-2", ++ "annotations": { ++ "config.kubernetes.io/index": 1, ++ # generates resource in parent directory ++ "config.kubernetes.io/path": "/another/file/out.yaml" ++ } ++ }, ++ "spec": { ++ "replicas": 4, ++ "template": { ++ "spec": { ++ "containers": [ ++ { ++ "name": "httpbin", ++ "image": "kennethreitz/httpbin", ++ "ports": [ ++ { ++ "containerPort": 9876 ++ } ++ ] ++ } ++ ] ++ } ++ } ++ } ++ } ++ # filter to return if resource is HTTPBin resource ++ def is_httpbin(r): ++ return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" ++ ++ def ensure_httpbin(resources): ++ for r in resources: ++ if is_httpbin(r): ++ return ++ ++ resources.append(httpbin_deployment_internal) ++ resources.append(httpbin_deployment_legacy) ++ ++ ensure_httpbin(ctx.resource_list["items"]) diff --git a/e2e/testdata/fn-render/non-krm-resource/Kptfile b/e2e/testdata/fn-render/non-krm-resource/Kptfile index 1307fb5426..93ae454de7 100644 --- a/e2e/testdata/fn-render/non-krm-resource/Kptfile +++ b/e2e/testdata/fn-render/non-krm-resource/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/out-of-place-dir-exists-error/Kptfile b/e2e/testdata/fn-render/out-of-place-dir-exists-error/Kptfile index b3a89e3911..710f44a846 100644 --- a/e2e/testdata/fn-render/out-of-place-dir-exists-error/Kptfile +++ b/e2e/testdata/fn-render/out-of-place-dir-exists-error/Kptfile @@ -4,6 +4,6 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging diff --git a/e2e/testdata/fn-render/out-of-place-dir/.expected/config.yaml b/e2e/testdata/fn-render/out-of-place-dir/.expected/config.yaml index 0b1837e3f3..fed31a7989 100644 --- a/e2e/testdata/fn-render/out-of-place-dir/.expected/config.yaml +++ b/e2e/testdata/fn-render/out-of-place-dir/.expected/config.yaml @@ -13,5 +13,5 @@ # limitations under the License. stdErr: | - [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" - [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" in 0s \ No newline at end of file + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s \ No newline at end of file diff --git a/e2e/testdata/fn-render/out-of-place-dir/Kptfile b/e2e/testdata/fn-render/out-of-place-dir/Kptfile index b3a89e3911..710f44a846 100644 --- a/e2e/testdata/fn-render/out-of-place-dir/Kptfile +++ b/e2e/testdata/fn-render/out-of-place-dir/Kptfile @@ -4,6 +4,6 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging diff --git a/e2e/testdata/fn-render/out-of-place-fnchain-stdout-results/.expected/config.yaml b/e2e/testdata/fn-render/out-of-place-fnchain-stdout-results/.expected/config.yaml index 5bd1ac26be..e7eb3fe008 100644 --- a/e2e/testdata/fn-render/out-of-place-fnchain-stdout-results/.expected/config.yaml +++ b/e2e/testdata/fn-render/out-of-place-fnchain-stdout-results/.expected/config.yaml @@ -22,7 +22,7 @@ stdOut: | tier: backend pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging # Copyright 2021 The kpt Authors @@ -74,11 +74,10 @@ stdOut: | internal.config.kubernetes.io/path: resources.yaml internal.config.kubernetes.io/seqindent: compact foo: bar - namespace: staging labels: tier: backend spec: image: nginx:1.2.3 stdErr: | - [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" - [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" in 0s + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s diff --git a/e2e/testdata/fn-render/out-of-place-fnchain-stdout-results/Kptfile b/e2e/testdata/fn-render/out-of-place-fnchain-stdout-results/Kptfile index b3a89e3911..710f44a846 100644 --- a/e2e/testdata/fn-render/out-of-place-fnchain-stdout-results/Kptfile +++ b/e2e/testdata/fn-render/out-of-place-fnchain-stdout-results/Kptfile @@ -4,6 +4,6 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging diff --git a/e2e/testdata/fn-render/out-of-place-fnchain-stdout/.expected/config.yaml b/e2e/testdata/fn-render/out-of-place-fnchain-stdout/.expected/config.yaml index 61e6015d10..75007dae78 100644 --- a/e2e/testdata/fn-render/out-of-place-fnchain-stdout/.expected/config.yaml +++ b/e2e/testdata/fn-render/out-of-place-fnchain-stdout/.expected/config.yaml @@ -4,8 +4,8 @@ stdErrStripLines: stdErr: | Package: "out-of-place-fnchain-stdout" - [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" - [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" in 0s + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-annotations:latest" [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-annotations:latest" in 0s [Results]: [info] metadata.annotations: set annotations: {"foo":"bar"}, [info] metadata.annotations: set annotations: {"foo":"bar"}, [info] spec.template.metadata.annotations: set annotations: {"foo":"bar"}, [info] metadata.annotations: set annotations: {"foo":"bar"} @@ -32,7 +32,7 @@ stdOut: | tier: backend pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging # Copyright 2021 The kpt Authors @@ -84,7 +84,6 @@ stdOut: | internal.config.kubernetes.io/path: resources.yaml internal.config.kubernetes.io/seqindent: compact foo: bar - namespace: staging labels: tier: backend spec: diff --git a/e2e/testdata/fn-render/out-of-place-fnchain-stdout/Kptfile b/e2e/testdata/fn-render/out-of-place-fnchain-stdout/Kptfile index b3a89e3911..710f44a846 100644 --- a/e2e/testdata/fn-render/out-of-place-fnchain-stdout/Kptfile +++ b/e2e/testdata/fn-render/out-of-place-fnchain-stdout/Kptfile @@ -4,6 +4,6 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging diff --git a/e2e/testdata/fn-render/out-of-place-fnchain-unwrap/Kptfile b/e2e/testdata/fn-render/out-of-place-fnchain-unwrap/Kptfile index b3a89e3911..710f44a846 100644 --- a/e2e/testdata/fn-render/out-of-place-fnchain-unwrap/Kptfile +++ b/e2e/testdata/fn-render/out-of-place-fnchain-unwrap/Kptfile @@ -4,6 +4,6 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging diff --git a/e2e/testdata/fn-render/out-of-place-stdout/.expected/config.yaml b/e2e/testdata/fn-render/out-of-place-stdout/.expected/config.yaml index 26b78dacab..56bcf999b5 100644 --- a/e2e/testdata/fn-render/out-of-place-stdout/.expected/config.yaml +++ b/e2e/testdata/fn-render/out-of-place-stdout/.expected/config.yaml @@ -3,8 +3,8 @@ stdErrStripLines: - " \"WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested\"" stdErr: | - [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" - [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" in 0s + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s stdOut: | apiVersion: config.kubernetes.io/v1 @@ -23,7 +23,7 @@ stdOut: | namespace: staging pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging # Copyright 2021 The kpt Authors @@ -62,6 +62,5 @@ stdOut: | internal.config.kubernetes.io/index: "1" internal.config.kubernetes.io/path: resources.yaml internal.config.kubernetes.io/seqindent: compact - namespace: staging spec: image: nginx:1.2.3 diff --git a/e2e/testdata/fn-render/out-of-place-stdout/Kptfile b/e2e/testdata/fn-render/out-of-place-stdout/Kptfile index b3a89e3911..710f44a846 100644 --- a/e2e/testdata/fn-render/out-of-place-stdout/Kptfile +++ b/e2e/testdata/fn-render/out-of-place-stdout/Kptfile @@ -4,6 +4,6 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging diff --git a/e2e/testdata/fn-render/out-of-place-unwrap/.expected/config.yaml b/e2e/testdata/fn-render/out-of-place-unwrap/.expected/config.yaml index 855f9dfb0f..381a5d2d3a 100644 --- a/e2e/testdata/fn-render/out-of-place-unwrap/.expected/config.yaml +++ b/e2e/testdata/fn-render/out-of-place-unwrap/.expected/config.yaml @@ -13,8 +13,8 @@ # limitations under the License. stdErr: | - [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" - [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" in 0s + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s stdOut: | apiVersion: apps/v1 diff --git a/e2e/testdata/fn-render/out-of-place-unwrap/Kptfile b/e2e/testdata/fn-render/out-of-place-unwrap/Kptfile index b3a89e3911..710f44a846 100644 --- a/e2e/testdata/fn-render/out-of-place-unwrap/Kptfile +++ b/e2e/testdata/fn-render/out-of-place-unwrap/Kptfile @@ -4,6 +4,6 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging diff --git a/e2e/testdata/fn-render/path-index-current/.expected/diff.patch b/e2e/testdata/fn-render/path-index-current/.expected/diff.patch index c06c7881cb..eeb872ba91 100644 --- a/e2e/testdata/fn-render/path-index-current/.expected/diff.patch +++ b/e2e/testdata/fn-render/path-index-current/.expected/diff.patch @@ -1,16 +1,24 @@ diff --git a/Kptfile b/Kptfile -index 0f5d7db..4525813 100644 +index 9033153..0f5d7db 100644 --- a/Kptfile +++ b/Kptfile -@@ -6,3 +6,8 @@ pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-httpbin-gen.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess +@@ -1,8 +1,8 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app-with-generator +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest +- configPath: starlark-httpbin-gen.yaml ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app-with-generator ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: starlark-httpbin-gen.yaml diff --git a/deployment_httpbin.yaml b/deployment_httpbin.yaml new file mode 100644 index 0000000..f36c98e @@ -30,3 +38,185 @@ index 0000000..f36c98e + name: httpbin + ports: + - containerPort: 9876 +diff --git a/resources.yaml b/resources.yaml +index 9d1f786..f2eec52 100644 +--- a/resources.yaml ++++ b/resources.yaml +@@ -1,26 +1,26 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment +-spec: +- replicas: 3 +---- +-apiVersion: custom.io/v1 +-kind: Custom +-metadata: +- name: custom +-spec: +- image: nginx:1.2.3 ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment ++spec: ++ replicas: 3 ++--- ++apiVersion: custom.io/v1 ++kind: Custom ++metadata: ++ name: custom ++spec: ++ image: nginx:1.2.3 +diff --git a/starlark-httpbin-gen.yaml b/starlark-httpbin-gen.yaml +index 910aa53..3a44610 100644 +--- a/starlark-httpbin-gen.yaml ++++ b/starlark-httpbin-gen.yaml +@@ -1,60 +1,60 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: httpbin-gen +-source: |- +- httpbin_deployment = { +- "apiVersion": "apps/v1", +- "kind": "Deployment", +- "metadata": { +- "name": "httpbin", +- "annotations": { +- "internal.config.kubernetes.io/index": 0, +- # generates resource in current directory +- "internal.config.kubernetes.io/path": "./deployment_httpbin.yaml" +- } +- }, +- "spec": { +- "replicas": 4, +- "template": { +- "spec": { +- "containers": [ +- { +- "name": "httpbin", +- "image": "kennethreitz/httpbin", +- "ports": [ +- { +- "containerPort": 9876 +- } +- ] +- } +- ] +- } +- } +- } +- } +- # filter to return if resource is HTTPBin resource +- def is_httpbin(r): +- return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" +- +- def ensure_httpbin(resources): +- for r in resources: +- if is_httpbin(r): +- return +- +- resources.append(httpbin_deployment) +- +- ensure_httpbin(ctx.resource_list["items"]) ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: httpbin-gen ++source: |- ++ httpbin_deployment = { ++ "apiVersion": "apps/v1", ++ "kind": "Deployment", ++ "metadata": { ++ "name": "httpbin", ++ "annotations": { ++ "internal.config.kubernetes.io/index": 0, ++ # generates resource in current directory ++ "internal.config.kubernetes.io/path": "./deployment_httpbin.yaml" ++ } ++ }, ++ "spec": { ++ "replicas": 4, ++ "template": { ++ "spec": { ++ "containers": [ ++ { ++ "name": "httpbin", ++ "image": "kennethreitz/httpbin", ++ "ports": [ ++ { ++ "containerPort": 9876 ++ } ++ ] ++ } ++ ] ++ } ++ } ++ } ++ } ++ # filter to return if resource is HTTPBin resource ++ def is_httpbin(r): ++ return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" ++ ++ def ensure_httpbin(resources): ++ for r in resources: ++ if is_httpbin(r): ++ return ++ ++ resources.append(httpbin_deployment) ++ ++ ensure_httpbin(ctx.resource_list["items"]) diff --git a/e2e/testdata/fn-render/path-index-descendent/.expected/diff.patch b/e2e/testdata/fn-render/path-index-descendent/.expected/diff.patch index 201a8b079f..c0d2af9bd7 100644 --- a/e2e/testdata/fn-render/path-index-descendent/.expected/diff.patch +++ b/e2e/testdata/fn-render/path-index-descendent/.expected/diff.patch @@ -1,16 +1,37 @@ diff --git a/Kptfile b/Kptfile -index 0f5d7db..4525813 100644 +index 9033153..0f5d7db 100644 --- a/Kptfile +++ b/Kptfile -@@ -6,3 +6,8 @@ pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-httpbin-gen.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess +@@ -1,8 +1,8 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app-with-generator +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest +- configPath: starlark-httpbin-gen.yaml ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app-with-generator ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: starlark-httpbin-gen.yaml +diff --git a/db/Kptfile b/db/Kptfile +index db5e84a..79b7a5a 100644 +--- a/db/Kptfile ++++ b/db/Kptfile +@@ -1,4 +1,4 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: db ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: db diff --git a/db/deployment_httpbin.yaml b/db/deployment_httpbin.yaml new file mode 100644 index 0000000..f36c98e @@ -30,3 +51,228 @@ index 0000000..f36c98e + name: httpbin + ports: + - containerPort: 9876 +diff --git a/db/resources.yaml b/db/resources.yaml +index c9c269b..dabe43c 100644 +--- a/db/resources.yaml ++++ b/db/resources.yaml +@@ -1,19 +1,19 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: StatefulSet +-metadata: +- name: db +-spec: +- replicas: 3 ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: StatefulSet ++metadata: ++ name: db ++spec: ++ replicas: 3 +diff --git a/resources.yaml b/resources.yaml +index 9d1f786..f2eec52 100644 +--- a/resources.yaml ++++ b/resources.yaml +@@ -1,26 +1,26 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment +-spec: +- replicas: 3 +---- +-apiVersion: custom.io/v1 +-kind: Custom +-metadata: +- name: custom +-spec: +- image: nginx:1.2.3 ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment ++spec: ++ replicas: 3 ++--- ++apiVersion: custom.io/v1 ++kind: Custom ++metadata: ++ name: custom ++spec: ++ image: nginx:1.2.3 +diff --git a/starlark-httpbin-gen.yaml b/starlark-httpbin-gen.yaml +index 106be2d..285547d 100644 +--- a/starlark-httpbin-gen.yaml ++++ b/starlark-httpbin-gen.yaml +@@ -1,60 +1,60 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: httpbin-gen +-source: |- +- httpbin_deployment = { +- "apiVersion": "apps/v1", +- "kind": "Deployment", +- "metadata": { +- "name": "httpbin", +- "annotations": { +- "internal.config.kubernetes.io/index": 0, +- # generates resource in child directory +- "internal.config.kubernetes.io/path": "./db/deployment_httpbin.yaml" +- } +- }, +- "spec": { +- "replicas": 4, +- "template": { +- "spec": { +- "containers": [ +- { +- "name": "httpbin", +- "image": "kennethreitz/httpbin", +- "ports": [ +- { +- "containerPort": 9876 +- } +- ] +- } +- ] +- } +- } +- } +- } +- # filter to return if resource is HTTPBin resource +- def is_httpbin(r): +- return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" +- +- def ensure_httpbin(resources): +- for r in resources: +- if is_httpbin(r): +- return +- +- resources.append(httpbin_deployment) +- +- ensure_httpbin(ctx.resource_list["items"]) ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: httpbin-gen ++source: |- ++ httpbin_deployment = { ++ "apiVersion": "apps/v1", ++ "kind": "Deployment", ++ "metadata": { ++ "name": "httpbin", ++ "annotations": { ++ "internal.config.kubernetes.io/index": 0, ++ # generates resource in child directory ++ "internal.config.kubernetes.io/path": "./db/deployment_httpbin.yaml" ++ } ++ }, ++ "spec": { ++ "replicas": 4, ++ "template": { ++ "spec": { ++ "containers": [ ++ { ++ "name": "httpbin", ++ "image": "kennethreitz/httpbin", ++ "ports": [ ++ { ++ "containerPort": 9876 ++ } ++ ] ++ } ++ ] ++ } ++ } ++ } ++ } ++ # filter to return if resource is HTTPBin resource ++ def is_httpbin(r): ++ return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" ++ ++ def ensure_httpbin(resources): ++ for r in resources: ++ if is_httpbin(r): ++ return ++ ++ resources.append(httpbin_deployment) ++ ++ ensure_httpbin(ctx.resource_list["items"]) diff --git a/e2e/testdata/fn-render/preserve-comments/.expected/diff.patch b/e2e/testdata/fn-render/preserve-comments/.expected/diff.patch index d9752bbacb..a76fde8ceb 100644 --- a/e2e/testdata/fn-render/preserve-comments/.expected/diff.patch +++ b/e2e/testdata/fn-render/preserve-comments/.expected/diff.patch @@ -1,13 +1,158 @@ diff --git a/Kptfile b/Kptfile -index 828d292..2228d2c 100644 +index 7b85c09..828d292 100644 --- a/Kptfile +++ b/Kptfile -@@ -5,3 +5,8 @@ metadata: - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/drop-comments:v0.1 -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess +@@ -1,7 +1,7 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/drop-comments:v0.1 ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/drop-comments:v0.1 +diff --git a/resources.yaml b/resources.yaml +index 020331f..5e8b5fe 100644 +--- a/resources.yaml ++++ b/resources.yaml +@@ -1,67 +1,67 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: my-nginx +- namespace: my-space +- labels: +- env: dev +- foo: bar +-spec: +- # comment 1 +- replicas: 3 +- selector: +- # comment 2 +- matchLabels: # comment 3 +- # comment 4 +- app: nginx # comment 5 +- template: +- metadata: +- labels: +- app: nginx +- spec: +- # comment 6 +- containers: +- # comment 7 +- - name: nginx +- image: nginx:1.14.2 # comment 8 +- ports: +- # comment 9 +- - containerPort: 80 # comment 10 +---- +-apiVersion: v1 +-kind: Service +-metadata: +- name: my-service +-spec: +- ports: +- # comment 1 +- - name: etcd-server-ssl +- port: 2380 +- # comment 2 +- - name: etcd-client-ssl +- port: 2379 +---- +-apiVersion: constraints.gatekeeper.sh/v1beta1 +-kind: EnforceFoo +-metadata: +- name: enforce-foo +-spec: +- parameters: +- naming_rules: +- - kind: Folder +- patterns: +- # comment 1 +- - ^(dev|prod|staging|qa|shared)$ ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: my-nginx ++ namespace: my-space ++ labels: ++ env: dev ++ foo: bar ++spec: ++ # comment 1 ++ replicas: 3 ++ selector: ++ # comment 2 ++ matchLabels: # comment 3 ++ # comment 4 ++ app: nginx # comment 5 ++ template: ++ metadata: ++ labels: ++ app: nginx ++ spec: ++ # comment 6 ++ containers: ++ # comment 7 ++ - name: nginx ++ image: nginx:1.14.2 # comment 8 ++ ports: ++ # comment 9 ++ - containerPort: 80 # comment 10 ++--- ++apiVersion: v1 ++kind: Service ++metadata: ++ name: my-service ++spec: ++ ports: ++ # comment 1 ++ - name: etcd-server-ssl ++ port: 2380 ++ # comment 2 ++ - name: etcd-client-ssl ++ port: 2379 ++--- ++apiVersion: constraints.gatekeeper.sh/v1beta1 ++kind: EnforceFoo ++metadata: ++ name: enforce-foo ++spec: ++ parameters: ++ naming_rules: ++ - kind: Folder ++ patterns: ++ # comment 1 ++ - ^(dev|prod|staging|qa|shared)$ diff --git a/e2e/testdata/fn-render/preserve-order-null-values/.expected/diff.patch b/e2e/testdata/fn-render/preserve-order-null-values/.expected/diff.patch index e0b6032aa8..b867d536a8 100644 --- a/e2e/testdata/fn-render/preserve-order-null-values/.expected/diff.patch +++ b/e2e/testdata/fn-render/preserve-order-null-values/.expected/diff.patch @@ -1,31 +1,21 @@ diff --git a/Kptfile b/Kptfile -index 1307fb5..f645d75 100644 +index 93ae454..9caee20 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: app -+ namespace: staging + labels: + tier: backend pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -@@ -10,3 +13,8 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest diff --git a/resources.yaml b/resources.yaml -index f410b70..b58c04c 100644 +index f410b70..4706dc3 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -16,12 +16,25 @@ kind: Deployment +@@ -16,6 +16,9 @@ kind: Deployment metadata: name: nginx-deployment createTimestamp: null @@ -34,19 +24,11 @@ index f410b70..b58c04c 100644 + tier: backend spec: replicas: 3 -+ selector: -+ matchLabels: -+ tier: backend -+ template: -+ metadata: -+ labels: -+ tier: backend --- - apiVersion: custom.io/v1 +@@ -23,5 +26,7 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom -+ namespace: staging + labels: + tier: backend spec: diff --git a/e2e/testdata/fn-render/preserve-order-null-values/Kptfile b/e2e/testdata/fn-render/preserve-order-null-values/Kptfile index 1307fb5426..93ae454de7 100644 --- a/e2e/testdata/fn-render/preserve-order-null-values/Kptfile +++ b/e2e/testdata/fn-render/preserve-order-null-values/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/resource-deletion/.expected/diff.patch b/e2e/testdata/fn-render/resource-deletion/.expected/diff.patch index d161537ad5..802d7faa29 100644 --- a/e2e/testdata/fn-render/resource-deletion/.expected/diff.patch +++ b/e2e/testdata/fn-render/resource-deletion/.expected/diff.patch @@ -1,29 +1,41 @@ diff --git a/Kptfile b/Kptfile -index 364e274..9ad7200 100644 +index 1e4b14a..8d6e225 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: app -+ namespace: staging +@@ -1,14 +1,16 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest +- configPath: starlark-httpbin.yaml +- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest +- configMap: +- namespace: staging +- - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 +- configMap: +- tier: backend ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app + labels: + tier: backend - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -@@ -12,3 +15,8 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: starlark-httpbin.yaml ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest ++ configMap: ++ namespace: staging ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 ++ configMap: ++ tier: backend diff --git a/deployment_httpbin.yaml b/deployment_httpbin.yaml deleted file mode 100644 -index 49d4f6e..0000000 +index b4028f8..0000000 --- a/deployment_httpbin.yaml +++ /dev/null @@ -1,36 +0,0 @@ @@ -64,18 +76,58 @@ index 49d4f6e..0000000 - - name: httpbin - image: kennethreitz/httpbin diff --git a/resources.yaml b/resources.yaml -index f2eec52..84cfb26 100644 +index 9d1f786..6b5d443 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,12 +15,25 @@ apiVersion: apps/v1 - kind: Deployment - metadata: - name: nginx-deployment +@@ -1,26 +1,38 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment +-spec: +- replicas: 3 +---- +-apiVersion: custom.io/v1 +-kind: Custom +-metadata: +- name: custom +-spec: +- image: nginx:1.2.3 ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment + namespace: staging + labels: + tier: backend - spec: - replicas: 3 ++spec: ++ replicas: 3 + selector: + matchLabels: + tier: backend @@ -83,27 +135,67 @@ index f2eec52..84cfb26 100644 + metadata: + labels: + tier: backend - --- - apiVersion: custom.io/v1 - kind: Custom - metadata: - name: custom -+ namespace: staging ++--- ++apiVersion: custom.io/v1 ++kind: Custom ++metadata: ++ name: custom + labels: + tier: backend - spec: - image: nginx:1.2.3 ++spec: ++ image: nginx:1.2.3 diff --git a/starlark-httpbin.yaml b/starlark-httpbin.yaml -index fd90109..e437ba7 100644 +index b668683..f9174fb 100644 --- a/starlark-httpbin.yaml +++ b/starlark-httpbin.yaml -@@ -15,6 +15,9 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: httpbin-gen -+ namespace: staging +@@ -1,24 +1,26 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: httpbin-gen +-source: | +- # filter to return if resource is HTTPBin resource +- def isHTTPBin(r): +- return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" +- +- # filter out the httpbin deployment +- ctx.resource_list["items"] = [r for r in ctx.resource_list["items"] if not isHTTPBin(r)] ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: httpbin-gen + labels: + tier: backend - source: | - # filter to return if resource is HTTPBin resource - def isHTTPBin(r): ++source: | ++ # filter to return if resource is HTTPBin resource ++ def isHTTPBin(r): ++ return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" ++ ++ # filter out the httpbin deployment ++ ctx.resource_list["items"] = [r for r in ctx.resource_list["items"] if not isHTTPBin(r)] diff --git a/e2e/testdata/fn-render/resource-deletion/Kptfile b/e2e/testdata/fn-render/resource-deletion/Kptfile index 364e274d3e..7316bb0b1a 100644 --- a/e2e/testdata/fn-render/resource-deletion/Kptfile +++ b/e2e/testdata/fn-render/resource-deletion/Kptfile @@ -6,7 +6,7 @@ pipeline: mutators: - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest configPath: starlark-httpbin.yaml - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/resource-has-pkgname-prefix/.expected/diff.patch b/e2e/testdata/fn-render/resource-has-pkgname-prefix/.expected/diff.patch index 7d3014762d..9887dc616f 100644 --- a/e2e/testdata/fn-render/resource-has-pkgname-prefix/.expected/diff.patch +++ b/e2e/testdata/fn-render/resource-has-pkgname-prefix/.expected/diff.patch @@ -1,112 +1,399 @@ diff --git a/Kptfile b/Kptfile -index 21d9773..94b2528 100644 +index e2f4e83..66b7fc9 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,8 +2,15 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: wordpress +@@ -1,9 +1,11 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: wordpress +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:latest +- configMap: +- abc: def ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: wordpress + annotations: + abc: def - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:latest - configMap: - abc: def -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:latest ++ configMap: ++ abc: def diff --git a/mysql/Kptfile b/mysql/Kptfile -index 3d51a77..965bc63 100644 +index 7e407bc..965bc63 100644 --- a/mysql/Kptfile +++ b/mysql/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: mysql +@@ -1,9 +1,12 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: mysql +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:latest +- configMap: +- foo: bar ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: mysql + annotations: + foo: bar + abc: def - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:latest ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:latest ++ configMap: ++ foo: bar diff --git a/mysql/mysql-deployment.yaml b/mysql/mysql-deployment.yaml -index 1b0fbd4..349681e 100644 +index faf76a1..349681e 100644 --- a/mysql/mysql-deployment.yaml +++ b/mysql/mysql-deployment.yaml -@@ -18,6 +18,8 @@ metadata: - annotations: - projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} - teamname: 'YOURTEAM' # kpt-set: ${teamname} +@@ -1,81 +1,90 @@ +-# Copyright 2019 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: v1 +-kind: Service +-metadata: +- name: wordpress-mysql +- annotations: +- projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} +- teamname: 'YOURTEAM' # kpt-set: ${teamname} +-spec: +- selector: +- app: wordpress +- tier: mysql +- ports: +- - port: 3306 +- clusterIP: None +---- +-apiVersion: v1 +-kind: PersistentVolumeClaim +-metadata: +- name: mysql-pv-claim +- annotations: +- projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} +- teamname: 'YOURTEAM' # kpt-set: ${teamname} +-spec: +- resources: +- requests: +- storage: 20Gi +- accessModes: +- - ReadWriteOnce +---- +-apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 +-kind: Deployment +-metadata: +- name: wordpress-mysql +- annotations: +- projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} +- teamname: 'YOURTEAM' # kpt-set: ${teamname} +-spec: +- selector: +- matchLabels: +- app: wordpress +- tier: mysql +- template: +- metadata: +- labels: +- app: wordpress +- tier: mysql +- spec: +- containers: +- - name: mysql +- image: mysql:5.6 # kpt-set: ${ms-image}:${ms-tag} +- ports: +- - name: mysql +- containerPort: 3306 +- env: +- - name: MYSQL_ROOT_PASSWORD +- valueFrom: +- secretKeyRef: +- name: mysql-pass +- key: password +- volumeMounts: +- - name: mysql-persistent-storage +- mountPath: /var/lib/mysql +- volumes: +- - name: mysql-persistent-storage +- persistentVolumeClaim: +- claimName: mysql-pv-claim +- strategy: +- type: Recreate ++# Copyright 2019 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: v1 ++kind: Service ++metadata: ++ name: wordpress-mysql ++ annotations: ++ projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} ++ teamname: 'YOURTEAM' # kpt-set: ${teamname} + foo: bar + abc: def - spec: - selector: - app: wordpress -@@ -33,6 +35,8 @@ metadata: - annotations: - projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} - teamname: 'YOURTEAM' # kpt-set: ${teamname} ++spec: ++ selector: ++ app: wordpress ++ tier: mysql ++ ports: ++ - port: 3306 ++ clusterIP: None ++--- ++apiVersion: v1 ++kind: PersistentVolumeClaim ++metadata: ++ name: mysql-pv-claim ++ annotations: ++ projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} ++ teamname: 'YOURTEAM' # kpt-set: ${teamname} + foo: bar + abc: def - spec: - resources: - requests: -@@ -47,6 +51,8 @@ metadata: - annotations: - projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} - teamname: 'YOURTEAM' # kpt-set: ${teamname} ++spec: ++ resources: ++ requests: ++ storage: 20Gi ++ accessModes: ++ - ReadWriteOnce ++--- ++apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 ++kind: Deployment ++metadata: ++ name: wordpress-mysql ++ annotations: ++ projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} ++ teamname: 'YOURTEAM' # kpt-set: ${teamname} + foo: bar + abc: def - spec: - selector: - matchLabels: -@@ -57,6 +63,9 @@ spec: - labels: - app: wordpress - tier: mysql ++spec: ++ selector: ++ matchLabels: ++ app: wordpress ++ tier: mysql ++ template: ++ metadata: ++ labels: ++ app: wordpress ++ tier: mysql + annotations: + foo: bar + abc: def - spec: - containers: - - name: mysql ++ spec: ++ containers: ++ - name: mysql ++ image: mysql:5.6 # kpt-set: ${ms-image}:${ms-tag} ++ ports: ++ - name: mysql ++ containerPort: 3306 ++ env: ++ - name: MYSQL_ROOT_PASSWORD ++ valueFrom: ++ secretKeyRef: ++ name: mysql-pass ++ key: password ++ volumeMounts: ++ - name: mysql-persistent-storage ++ mountPath: /var/lib/mysql ++ volumes: ++ - name: mysql-persistent-storage ++ persistentVolumeClaim: ++ claimName: mysql-pv-claim ++ strategy: ++ type: Recreate diff --git a/wordpress-deployment.yaml b/wordpress-deployment.yaml -index d018dfa..af25a1f 100644 +index 0d53f68..af25a1f 100644 --- a/wordpress-deployment.yaml +++ b/wordpress-deployment.yaml -@@ -16,6 +16,7 @@ metadata: - annotations: - projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} - teamname: 'YOURTEAM' # kpt-set: ${teamname} +@@ -1,81 +1,86 @@ +-# Copyright 2019 The kpt Authors +-# +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: v1 +-kind: Service +-metadata: +- name: wordpress +- annotations: +- projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} +- teamname: 'YOURTEAM' # kpt-set: ${teamname} +-spec: +- type: LoadBalancer +- selector: +- app: wordpress +- tier: frontend +- ports: +- - port: 80 +---- +-apiVersion: v1 +-kind: PersistentVolumeClaim +-metadata: +- name: wp-pv-claim +- annotations: +- projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} +- teamname: 'YOURTEAM' # kpt-set: ${teamname} +-spec: +- resources: +- requests: +- storage: 20Gi +- accessModes: +- - ReadWriteOnce +---- +-apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 +-kind: Deployment +-metadata: +- name: wordpress +- annotations: +- projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} +- teamname: 'YOURTEAM' # kpt-set: ${teamname} +-spec: +- selector: +- matchLabels: +- app: wordpress +- tier: frontend +- template: +- metadata: +- labels: +- app: wordpress +- tier: frontend +- spec: +- containers: +- - name: wordpress +- image: wordpress:4.8-apache # kpt-set: ${wp-image}:${wp-tag} +- ports: +- - name: wordpress +- containerPort: 80 +- env: +- - name: WORDPRESS_DB_HOST +- value: wordpress-mysql +- - name: WORDPRESS_DB_PASSWORD +- valueFrom: +- secretKeyRef: +- name: mysql-pass +- key: password +- volumeMounts: +- - name: wordpress-persistent-storage +- mountPath: /var/www/html +- volumes: +- - name: wordpress-persistent-storage +- persistentVolumeClaim: +- claimName: wp-pv-claim +- strategy: +- type: Recreate ++# Copyright 2019 The kpt Authors ++# ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: v1 ++kind: Service ++metadata: ++ name: wordpress ++ annotations: ++ projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} ++ teamname: 'YOURTEAM' # kpt-set: ${teamname} + abc: def - spec: - type: LoadBalancer - selector: -@@ -31,6 +32,7 @@ metadata: - annotations: - projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} - teamname: 'YOURTEAM' # kpt-set: ${teamname} ++spec: ++ type: LoadBalancer ++ selector: ++ app: wordpress ++ tier: frontend ++ ports: ++ - port: 80 ++--- ++apiVersion: v1 ++kind: PersistentVolumeClaim ++metadata: ++ name: wp-pv-claim ++ annotations: ++ projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} ++ teamname: 'YOURTEAM' # kpt-set: ${teamname} + abc: def - spec: - resources: - requests: -@@ -45,6 +47,7 @@ metadata: - annotations: - projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} - teamname: 'YOURTEAM' # kpt-set: ${teamname} ++spec: ++ resources: ++ requests: ++ storage: 20Gi ++ accessModes: ++ - ReadWriteOnce ++--- ++apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 ++kind: Deployment ++metadata: ++ name: wordpress ++ annotations: ++ projectId: 'PROJECT_ID' # kpt-set: ${gcloud.core.project} ++ teamname: 'YOURTEAM' # kpt-set: ${teamname} + abc: def - spec: - selector: - matchLabels: -@@ -55,6 +58,8 @@ spec: - labels: - app: wordpress - tier: frontend ++spec: ++ selector: ++ matchLabels: ++ app: wordpress ++ tier: frontend ++ template: ++ metadata: ++ labels: ++ app: wordpress ++ tier: frontend + annotations: + abc: def - spec: - containers: - - name: wordpress ++ spec: ++ containers: ++ - name: wordpress ++ image: wordpress:4.8-apache # kpt-set: ${wp-image}:${wp-tag} ++ ports: ++ - name: wordpress ++ containerPort: 80 ++ env: ++ - name: WORDPRESS_DB_HOST ++ value: wordpress-mysql ++ - name: WORDPRESS_DB_PASSWORD ++ valueFrom: ++ secretKeyRef: ++ name: mysql-pass ++ key: password ++ volumeMounts: ++ - name: wordpress-persistent-storage ++ mountPath: /var/www/html ++ volumes: ++ - name: wordpress-persistent-storage ++ persistentVolumeClaim: ++ claimName: wp-pv-claim ++ strategy: ++ type: Recreate diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-basicpipeline/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/bfs-basicpipeline/.expected/diff.patch index e9382ce252..e32ef6a978 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-basicpipeline/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-basicpipeline/.expected/diff.patch @@ -1,21 +1,18 @@ diff --git a/Kptfile b/Kptfile -index ec2c042..50c2a18 100644 +index 03e022b..0676899 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,18 +1,28 @@ - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: -+ name: save-on-render-failure -+ namespace: staging - annotations: -+ app: myapp - kpt.dev/bfs-rendering: "true" - kpt.dev/save-on-render-failure: "true" +@@ -1,18 +1,19 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- annotations: +- kpt.dev/bfs-rendering: "true" +- kpt.dev/save-on-render-failure: "true" - name: save-on-render-failure - pipeline: - mutators: -- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest - configMap: - namespace: staging - - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 @@ -24,36 +21,45 @@ index ec2c042..50c2a18 100644 - - image: invalid-image:v0.0.0 - configMap: - tier: backend -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ configMap: -+ namespace: staging -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 -+ configMap: -+ app: myapp -+ - image: invalid-image:v0.0.0 -+ configMap: -+ tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg .: -+ pipeline.run: already handled error ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ annotations: ++ kpt.dev/bfs-rendering: "true" ++ kpt.dev/save-on-render-failure: "true" ++ app: myapp ++ name: save-on-render-failure ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest ++ configMap: ++ namespace: staging ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 ++ configMap: ++ app: myapp ++ - image: invalid-image:v0.0.0 ++ configMap: ++ tier: backend diff --git a/resources.yaml b/resources.yaml -index 0848ba0..7eece9b 100644 +index 65cd534..7eece9b 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -2,5 +2,12 @@ apiVersion: apps/v1 - kind: Deployment - metadata: - name: nginx-deployment +@@ -1,6 +1,13 @@ +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment +-spec: +- replicas: 3 ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment + annotations: + app: myapp + namespace: staging - spec: - replicas: 3 ++spec: ++ replicas: 3 + template: + metadata: + annotations: diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-basicpipeline/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/bfs-basicpipeline/Kptfile index ec2c042dc7..223faf01af 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-basicpipeline/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-basicpipeline/Kptfile @@ -7,7 +7,7 @@ metadata: name: save-on-render-failure pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-deep-nested-middle-fails/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/bfs-deep-nested-middle-fails/.expected/diff.patch index 0544ac3be1..b3fc460742 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-deep-nested-middle-fails/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-deep-nested-middle-fails/.expected/diff.patch @@ -1,34 +1,16 @@ diff --git a/Kptfile b/Kptfile -index dbd6541..915dd4b 100644 +index dbd6541..f54cd50 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,14 +1,24 @@ - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: -+ name: bfs-deep-nested-middle-fails -+ labels: -+ level: root - annotations: +@@ -5,6 +5,8 @@ metadata: kpt.dev/bfs-rendering: "true" kpt.dev/save-on-render-failure: "true" -- name: bfs-deep-nested-middle-fails + name: bfs-deep-nested-middle-fails ++ labels: ++ level: root info: description: BFS - Deep nested, middle level fails pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: -- level: "root" -+ level: root -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg .: -+ pipeline.run: pkg ./level1: already handled error diff --git a/configmap.yaml b/configmap.yaml index 59bb817..19a7ead 100644 --- a/configmap.yaml @@ -67,10 +49,10 @@ index 57d3b69..10a2e13 100644 data: level: level1 diff --git a/level1/level2/Kptfile b/level1/level2/Kptfile -index 314d402..29e69db 100644 +index 314d402..4e4b342 100644 --- a/level1/level2/Kptfile +++ b/level1/level2/Kptfile -@@ -2,10 +2,12 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: level2 @@ -79,11 +61,6 @@ index 314d402..29e69db 100644 info: description: Level2 that succeeds pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: -- level: "level2" -+ level: level2 diff --git a/level1/level2/configmap.yaml b/level1/level2/configmap.yaml index ab7d3fa..1eeeaed 100644 --- a/level1/level2/configmap.yaml diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-multiple-subpkgs-one-fails/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/bfs-multiple-subpkgs-one-fails/.expected/diff.patch index 8ddd89fefa..cdef5ddc1e 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-multiple-subpkgs-one-fails/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-multiple-subpkgs-one-fails/.expected/diff.patch @@ -1,38 +1,21 @@ diff --git a/Kptfile b/Kptfile -index e9fad85..48186b1 100644 +index e9fad85..1b08a62 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,10 +1,12 @@ - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: -+ name: bfs-multiple-subpkgs-one-fails -+ labels: -+ pkg: root - annotations: +@@ -5,6 +5,8 @@ metadata: kpt.dev/bfs-rendering: "true" kpt.dev/save-on-render-failure: "true" -- name: bfs-multiple-subpkgs-one-fails + name: bfs-multiple-subpkgs-one-fails ++ labels: ++ pkg: root info: description: BFS - Multiple subpackages, sub2 fails pipeline: -@@ -12,3 +14,11 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - pkg: root -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg .: -+ pipeline.run: pkg ./sub2: already handled error diff --git a/service.yaml b/service.yaml -index 9148b9b..2e551c8 100644 +index 9148b9b..eef89cb 100644 --- a/service.yaml +++ b/service.yaml -@@ -2,6 +2,10 @@ apiVersion: v1 +@@ -2,6 +2,8 @@ apiVersion: v1 kind: Service metadata: name: root-service @@ -41,8 +24,6 @@ index 9148b9b..2e551c8 100644 spec: ports: - port: 80 -+ selector: -+ pkg: root diff --git a/sub1/Kptfile b/sub1/Kptfile index 2d62077..0f03268 100644 --- a/sub1/Kptfile @@ -57,10 +38,10 @@ index 2d62077..0f03268 100644 mutators: - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/sub1/deployment.yaml b/sub1/deployment.yaml -index 2f649ba..c2245a9 100644 +index 2f649ba..0dfd629 100644 --- a/sub1/deployment.yaml +++ b/sub1/deployment.yaml -@@ -2,5 +2,14 @@ apiVersion: apps/v1 +@@ -2,5 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: sub1-deployment @@ -68,13 +49,6 @@ index 2f649ba..c2245a9 100644 + pkg: sub1 spec: replicas: 1 -+ selector: -+ matchLabels: -+ pkg: sub1 -+ template: -+ metadata: -+ labels: -+ pkg: sub1 diff --git a/sub2/Kptfile b/sub2/Kptfile index 792277c..6412843 100644 --- a/sub2/Kptfile @@ -89,10 +63,10 @@ index 792277c..6412843 100644 mutators: - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/sub2/deployment.yaml b/sub2/deployment.yaml -index 20375ea..7290360 100644 +index 20375ea..2984199 100644 --- a/sub2/deployment.yaml +++ b/sub2/deployment.yaml -@@ -2,5 +2,14 @@ apiVersion: apps/v1 +@@ -2,5 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: sub2-deployment @@ -100,13 +74,6 @@ index 20375ea..7290360 100644 + pkg: sub2 spec: replicas: 2 -+ selector: -+ matchLabels: -+ pkg: sub2 -+ template: -+ metadata: -+ labels: -+ pkg: sub2 diff --git a/sub3/Kptfile b/sub3/Kptfile index ff35b98..958a351 100644 --- a/sub3/Kptfile @@ -121,10 +88,10 @@ index ff35b98..958a351 100644 mutators: - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/sub3/deployment.yaml b/sub3/deployment.yaml -index dc257b3..3a13d11 100644 +index dc257b3..492a43b 100644 --- a/sub3/deployment.yaml +++ b/sub3/deployment.yaml -@@ -2,5 +2,14 @@ apiVersion: apps/v1 +@@ -2,5 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: sub3-deployment @@ -132,10 +99,3 @@ index dc257b3..3a13d11 100644 + pkg: root spec: replicas: 3 -+ selector: -+ matchLabels: -+ pkg: root -+ template: -+ metadata: -+ labels: -+ pkg: root diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-and-subpkg-both-fail/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-and-subpkg-both-fail/.expected/diff.patch index e5e2e83e81..37132795bd 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-and-subpkg-both-fail/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-and-subpkg-both-fail/.expected/diff.patch @@ -1,33 +1,16 @@ diff --git a/Kptfile b/Kptfile -index cbe756f..8ce300c 100644 +index cbe756f..a5fa6c0 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,10 +1,12 @@ - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: -+ name: bfs-parent-and-subpkg-both-fail -+ labels: -+ pkg: root - annotations: +@@ -5,6 +5,8 @@ metadata: kpt.dev/bfs-rendering: "true" kpt.dev/save-on-render-failure: "true" -- name: bfs-parent-and-subpkg-both-fail + name: bfs-parent-and-subpkg-both-fail ++ labels: ++ pkg: root info: description: BFS - Both parent and subpackage fail pipeline: -@@ -14,3 +16,11 @@ pipeline: - pkg: root - validators: - - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg .: -+ pipeline.run: already handled error diff --git a/configmap.yaml b/configmap.yaml index 8594873..a591ceb 100644 --- a/configmap.yaml @@ -54,10 +37,10 @@ index a332cf5..2a3f05c 100644 description: Subpackage that also fails pipeline: diff --git a/subpkg/service.yaml b/subpkg/service.yaml -index 276bf9e..d6424da 100644 +index 276bf9e..3cd04ec 100644 --- a/subpkg/service.yaml +++ b/subpkg/service.yaml -@@ -2,6 +2,10 @@ apiVersion: v1 +@@ -2,6 +2,8 @@ apiVersion: v1 kind: Service metadata: name: sub-service @@ -66,5 +49,3 @@ index 276bf9e..d6424da 100644 spec: ports: - port: 80 -+ selector: -+ pkg: root diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-mutator-fails/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-mutator-fails/.expected/diff.patch index f7cc0a511a..a4980af204 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-mutator-fails/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-mutator-fails/.expected/diff.patch @@ -1,72 +1,108 @@ diff --git a/Kptfile b/Kptfile -index c80b904..d0bc053 100644 +index 7e481a5..6954e67 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,15 +1,25 @@ - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: +@@ -1,15 +1,17 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- annotations: +- kpt.dev/bfs-rendering: "true" +- kpt.dev/save-on-render-failure: "true" +- name: bfs-parent-mutator-fails +-info: +- description: BFS - Parent mutator fails +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 +- configMap: +- test: "parent-mutator-fail" +- - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ annotations: ++ kpt.dev/bfs-rendering: "true" ++ kpt.dev/save-on-render-failure: "true" + name: bfs-parent-mutator-fails + labels: + test: parent-mutator-fail - annotations: - kpt.dev/bfs-rendering: "true" - kpt.dev/save-on-render-failure: "true" -- name: bfs-parent-mutator-fails - info: - description: BFS - Parent mutator fails - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: -- test: "parent-mutator-fail" ++info: ++ description: BFS - Parent mutator fails ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 ++ configMap: + test: parent-mutator-fail - - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg .: -+ pipeline.run: already handled error ++ - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 diff --git a/configmap.yaml b/configmap.yaml -index 20a54f6..a46a12b 100644 +index 4f9a1b3..a46a12b 100644 --- a/configmap.yaml +++ b/configmap.yaml -@@ -2,5 +2,7 @@ apiVersion: v1 - kind: ConfigMap - metadata: - name: root-config +@@ -1,6 +1,8 @@ +-apiVersion: v1 +-kind: ConfigMap +-metadata: +- name: root-config +-data: +- key: value ++apiVersion: v1 ++kind: ConfigMap ++metadata: ++ name: root-config + labels: + test: parent-mutator-fail - data: - key: value ++data: ++ key: value diff --git a/subpkg/Kptfile b/subpkg/Kptfile -index e940ae8..e6e678c 100644 +index 24faac6..ed7a995 100644 --- a/subpkg/Kptfile +++ b/subpkg/Kptfile -@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: subpkg +@@ -1,11 +1,13 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: subpkg +-info: +- description: Subpackage that succeeds +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest +- configMap: +- namespace: subpkg-ns ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: subpkg + labels: + test: parent-mutator-fail - info: - description: Subpackage that succeeds - pipeline: ++info: ++ description: Subpackage that succeeds ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest ++ configMap: ++ namespace: subpkg-ns diff --git a/subpkg/service.yaml b/subpkg/service.yaml -index 276bf9e..acfae7a 100644 +index cd6bc70..acfae7a 100644 --- a/subpkg/service.yaml +++ b/subpkg/service.yaml -@@ -2,6 +2,10 @@ apiVersion: v1 - kind: Service - metadata: - name: sub-service +@@ -1,7 +1,11 @@ +-apiVersion: v1 +-kind: Service +-metadata: +- name: sub-service +-spec: +- ports: +- - port: 80 ++apiVersion: v1 ++kind: Service ++metadata: ++ name: sub-service + labels: + test: parent-mutator-fail - spec: - ports: - - port: 80 ++spec: ++ ports: ++ - port: 80 + selector: + test: parent-mutator-fail diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-mutator-fails/subpkg/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-mutator-fails/subpkg/Kptfile index e940ae88b9..fd277c8250 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-mutator-fails/subpkg/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-mutator-fails/subpkg/Kptfile @@ -6,6 +6,6 @@ info: description: Subpackage that succeeds pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: subpkg-ns diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-validator-fails/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-validator-fails/.expected/diff.patch index 77a376f85e..1a2e777eec 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-validator-fails/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-validator-fails/.expected/diff.patch @@ -1,36 +1,16 @@ diff --git a/Kptfile b/Kptfile -index 491b12e..28e400c 100644 +index 491b12e..e12299e 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,16 +1,26 @@ - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: -+ name: bfs-parent-validator-fails -+ labels: -+ test: parent-fail - annotations: +@@ -5,6 +5,8 @@ metadata: kpt.dev/bfs-rendering: "true" kpt.dev/save-on-render-failure: "true" -- name: bfs-parent-validator-fails + name: bfs-parent-validator-fails ++ labels: ++ test: parent-fail info: description: BFS - Parent validator fails pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: -- test: "parent-fail" -+ test: parent-fail - validators: - - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg .: -+ pipeline.run: already handled error diff --git a/configmap.yaml b/configmap.yaml index 20a54f6..ad595de 100644 --- a/configmap.yaml @@ -44,7 +24,7 @@ index 20a54f6..ad595de 100644 data: key: value diff --git a/subpkg/Kptfile b/subpkg/Kptfile -index e940ae8..88a8d4e 100644 +index fd277c8..ecbfb69 100644 --- a/subpkg/Kptfile +++ b/subpkg/Kptfile @@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 @@ -57,10 +37,10 @@ index e940ae8..88a8d4e 100644 description: Subpackage that succeeds pipeline: diff --git a/subpkg/service.yaml b/subpkg/service.yaml -index 276bf9e..fe08496 100644 +index 276bf9e..098c31b 100644 --- a/subpkg/service.yaml +++ b/subpkg/service.yaml -@@ -2,6 +2,10 @@ apiVersion: v1 +@@ -2,6 +2,8 @@ apiVersion: v1 kind: Service metadata: name: sub-service @@ -69,5 +49,3 @@ index 276bf9e..fe08496 100644 spec: ports: - port: 80 -+ selector: -+ test: parent-fail diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-validator-fails/subpkg/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-validator-fails/subpkg/Kptfile index e940ae88b9..fd277c8250 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-validator-fails/subpkg/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-validator-fails/subpkg/Kptfile @@ -6,6 +6,6 @@ info: description: Subpackage that succeeds pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: subpkg-ns diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-mutator-fails/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-mutator-fails/.expected/diff.patch index b4d487a414..3a3688a5b3 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-mutator-fails/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-mutator-fails/.expected/diff.patch @@ -1,39 +1,21 @@ diff --git a/Kptfile b/Kptfile -index 84b93a6..4ae9f17 100644 +index 84b93a6..ea86fe4 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,14 +1,24 @@ - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: -+ name: bfs-subpkg-mutator-fails -+ labels: -+ test: mutator-fail - annotations: +@@ -5,6 +5,8 @@ metadata: kpt.dev/bfs-rendering: "true" kpt.dev/save-on-render-failure: "true" -- name: bfs-subpkg-mutator-fails + name: bfs-subpkg-mutator-fails ++ labels: ++ test: mutator-fail info: description: BFS - Subpackage mutator fails pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: -- test: "mutator-fail" -+ test: mutator-fail -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg .: -+ pipeline.run: pkg ./subpkg: already handled error diff --git a/deployment.yaml b/deployment.yaml -index cc866f6..6ed4201 100644 +index cc866f6..3eb9788 100644 --- a/deployment.yaml +++ b/deployment.yaml -@@ -2,5 +2,14 @@ apiVersion: apps/v1 +@@ -2,5 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: root-deployment @@ -41,44 +23,28 @@ index cc866f6..6ed4201 100644 + test: mutator-fail spec: replicas: 1 -+ selector: -+ matchLabels: -+ test: mutator-fail -+ template: -+ metadata: -+ labels: -+ test: mutator-fail diff --git a/subpkg/Kptfile b/subpkg/Kptfile -index ec4ce38..82fcf74 100644 +index 6563904..19e913c 100644 --- a/subpkg/Kptfile +++ b/subpkg/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: subpkg + labels: + test: mutator-fail -+ namespace: subpkg-ns info: description: Subpackage with failing mutator pipeline: diff --git a/subpkg/deployment.yaml b/subpkg/deployment.yaml -index 302322e..546fe5c 100644 +index 302322e..06562db 100644 --- a/subpkg/deployment.yaml +++ b/subpkg/deployment.yaml -@@ -2,5 +2,15 @@ apiVersion: apps/v1 +@@ -2,5 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: sub-deployment + labels: + test: mutator-fail -+ namespace: subpkg-ns spec: replicas: 2 -+ selector: -+ matchLabels: -+ test: mutator-fail -+ template: -+ metadata: -+ labels: -+ test: mutator-fail diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-mutator-fails/subpkg/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-mutator-fails/subpkg/Kptfile index ec4ce38547..65639042a0 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-mutator-fails/subpkg/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-mutator-fails/subpkg/Kptfile @@ -6,7 +6,7 @@ info: description: Subpackage with failing mutator pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: subpkg-ns - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-validator-fails/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-validator-fails/.expected/diff.patch index 18a748ab0c..6fab046dbc 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-validator-fails/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-validator-fails/.expected/diff.patch @@ -1,42 +1,22 @@ diff --git a/Kptfile b/Kptfile -index 86dbe13..f0c67c4 100644 +index 86dbe13..cba0f58 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,15 +1,26 @@ - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: -+ name: bfs-subpkg-validator-fails +@@ -5,6 +5,9 @@ metadata: + kpt.dev/bfs-rendering: "true" + kpt.dev/save-on-render-failure: "true" + name: bfs-subpkg-validator-fails + labels: + level: root + test: subpkg-fail - annotations: - kpt.dev/bfs-rendering: "true" - kpt.dev/save-on-render-failure: "true" -- name: bfs-subpkg-validator-fails info: description: BFS - Subpackage validator fails pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: -- test: "subpkg-fail" -- level: "root" -+ level: root -+ test: subpkg-fail -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg .: -+ pipeline.run: pkg ./subpkg: already handled error diff --git a/deployment.yaml b/deployment.yaml -index 7123634..4db6211 100644 +index 7123634..594061d 100644 --- a/deployment.yaml +++ b/deployment.yaml -@@ -3,5 +3,17 @@ kind: Deployment +@@ -3,5 +3,8 @@ kind: Deployment metadata: name: root-deployment namespace: default @@ -45,35 +25,25 @@ index 7123634..4db6211 100644 + test: subpkg-fail spec: replicas: 1 -+ selector: -+ matchLabels: -+ level: root -+ test: subpkg-fail -+ template: -+ metadata: -+ labels: -+ level: root -+ test: subpkg-fail diff --git a/subpkg/Kptfile b/subpkg/Kptfile -index f147d84..15fd450 100644 +index 7dd3a25..edd5b30 100644 --- a/subpkg/Kptfile +++ b/subpkg/Kptfile -@@ -2,6 +2,10 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: subpkg + labels: + level: root + test: subpkg-fail -+ namespace: subpkg-ns info: description: Subpackage with failing validator pipeline: diff --git a/subpkg/deployment.yaml b/subpkg/deployment.yaml -index 302322e..dfe3056 100644 +index 302322e..938e4c9 100644 --- a/subpkg/deployment.yaml +++ b/subpkg/deployment.yaml -@@ -2,5 +2,18 @@ apiVersion: apps/v1 +@@ -2,5 +2,9 @@ apiVersion: apps/v1 kind: Deployment metadata: name: sub-deployment @@ -83,12 +53,3 @@ index 302322e..dfe3056 100644 + namespace: subpkg-ns spec: replicas: 2 -+ selector: -+ matchLabels: -+ level: root -+ test: subpkg-fail -+ template: -+ metadata: -+ labels: -+ level: root -+ test: subpkg-fail diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-validator-fails/subpkg/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-validator-fails/subpkg/Kptfile index f147d84027..7dd3a25143 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-validator-fails/subpkg/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-validator-fails/subpkg/Kptfile @@ -6,7 +6,7 @@ info: description: Subpackage with failing validator pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: subpkg-ns validators: diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-basicpipeline/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/dfs-basicpipeline/.expected/diff.patch index 3234bb19c8..d2a2638d5e 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-basicpipeline/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-basicpipeline/.expected/diff.patch @@ -1,20 +1,17 @@ diff --git a/Kptfile b/Kptfile -index c6fc0c5..620b80e 100644 +index c14bf3d..666665a 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,17 +1,27 @@ - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: -+ name: save-on-render-failure -+ namespace: staging - annotations: -+ app: myapp - kpt.dev/save-on-render-failure: "true" +@@ -1,17 +1,18 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- annotations: +- kpt.dev/save-on-render-failure: "true" - name: save-on-render-failure - pipeline: - mutators: -- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest - configMap: - namespace: staging - - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 @@ -23,36 +20,44 @@ index c6fc0c5..620b80e 100644 - - image: invalid-image:v0.0.0 - configMap: - tier: backend -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ configMap: -+ namespace: staging -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 -+ configMap: -+ app: myapp -+ - image: invalid-image:v0.0.0 -+ configMap: -+ tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg .: -+ pipeline.run: already handled error ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ annotations: ++ kpt.dev/save-on-render-failure: "true" ++ app: myapp ++ name: save-on-render-failure ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest ++ configMap: ++ namespace: staging ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 ++ configMap: ++ app: myapp ++ - image: invalid-image:v0.0.0 ++ configMap: ++ tier: backend diff --git a/resources.yaml b/resources.yaml -index 0848ba0..7eece9b 100644 +index 65cd534..7eece9b 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -2,5 +2,12 @@ apiVersion: apps/v1 - kind: Deployment - metadata: - name: nginx-deployment +@@ -1,6 +1,13 @@ +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment +-spec: +- replicas: 3 ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment + annotations: + app: myapp + namespace: staging - spec: - replicas: 3 ++spec: ++ replicas: 3 + template: + metadata: + annotations: diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-basicpipeline/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/dfs-basicpipeline/Kptfile index c6fc0c546a..2dafd970cb 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-basicpipeline/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-basicpipeline/Kptfile @@ -6,7 +6,7 @@ metadata: name: save-on-render-failure pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-deep-nested-middle-fails/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/dfs-deep-nested-middle-fails/.expected/diff.patch index 14f98d3f02..30425882bf 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-deep-nested-middle-fails/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-deep-nested-middle-fails/.expected/diff.patch @@ -1,31 +1,3 @@ -diff --git a/Kptfile b/Kptfile -index 4047d27..e7ca740 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -1,13 +1,21 @@ - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: -+ name: dfs-deep-nested-middle-fails - annotations: - kpt.dev/save-on-render-failure: "true" -- name: dfs-deep-nested-middle-fails - info: - description: DFS - Deep nested, middle level fails - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: -- level: "root" -+ level: root -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg ./level1: -+ pipeline.run: already handled error diff --git a/level1/Kptfile b/level1/Kptfile index b5960dd..b42f153 100644 --- a/level1/Kptfile @@ -52,10 +24,10 @@ index 57d3b69..10a2e13 100644 data: level: level1 diff --git a/level1/level2/Kptfile b/level1/level2/Kptfile -index 314d402..29e69db 100644 +index 314d402..4e4b342 100644 --- a/level1/level2/Kptfile +++ b/level1/level2/Kptfile -@@ -2,10 +2,12 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: level2 @@ -64,11 +36,6 @@ index 314d402..29e69db 100644 info: description: Level2 that succeeds pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: -- level: "level2" -+ level: level2 diff --git a/level1/level2/configmap.yaml b/level1/level2/configmap.yaml index ab7d3fa..1eeeaed 100644 --- a/level1/level2/configmap.yaml diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-multiple-subpkgs-one-fails/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/dfs-multiple-subpkgs-one-fails/.expected/diff.patch index 582f70fc72..2ecdbc4a59 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-multiple-subpkgs-one-fails/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-multiple-subpkgs-one-fails/.expected/diff.patch @@ -1,30 +1,3 @@ -diff --git a/Kptfile b/Kptfile -index c47c90d..1b7e920 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -1,9 +1,9 @@ - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: -+ name: dfs-multiple-subpkgs-one-fails - annotations: - kpt.dev/save-on-render-failure: "true" -- name: dfs-multiple-subpkgs-one-fails - info: - description: DFS - Multiple subpackages, sub2 fails - pipeline: -@@ -11,3 +11,11 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - pkg: root -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg ./sub2: -+ pipeline.run: already handled error diff --git a/sub1/Kptfile b/sub1/Kptfile index 2d62077..0f03268 100644 --- a/sub1/Kptfile @@ -39,10 +12,10 @@ index 2d62077..0f03268 100644 mutators: - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/sub1/deployment.yaml b/sub1/deployment.yaml -index 2f649ba..c2245a9 100644 +index 2f649ba..0dfd629 100644 --- a/sub1/deployment.yaml +++ b/sub1/deployment.yaml -@@ -2,5 +2,14 @@ apiVersion: apps/v1 +@@ -2,5 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: sub1-deployment @@ -50,13 +23,6 @@ index 2f649ba..c2245a9 100644 + pkg: sub1 spec: replicas: 1 -+ selector: -+ matchLabels: -+ pkg: sub1 -+ template: -+ metadata: -+ labels: -+ pkg: sub1 diff --git a/sub2/Kptfile b/sub2/Kptfile index 792277c..6412843 100644 --- a/sub2/Kptfile @@ -71,10 +37,10 @@ index 792277c..6412843 100644 mutators: - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/sub2/deployment.yaml b/sub2/deployment.yaml -index 20375ea..7290360 100644 +index 20375ea..2984199 100644 --- a/sub2/deployment.yaml +++ b/sub2/deployment.yaml -@@ -2,5 +2,14 @@ apiVersion: apps/v1 +@@ -2,5 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: sub2-deployment @@ -82,10 +48,3 @@ index 20375ea..7290360 100644 + pkg: sub2 spec: replicas: 2 -+ selector: -+ matchLabels: -+ pkg: sub2 -+ template: -+ metadata: -+ labels: -+ pkg: sub2 diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-and-subpkg-both-fail/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-and-subpkg-both-fail/.expected/diff.patch index f0105bbf0f..052d2a1013 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-and-subpkg-both-fail/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-and-subpkg-both-fail/.expected/diff.patch @@ -1,30 +1,3 @@ -diff --git a/Kptfile b/Kptfile -index e4d630d..c8d5efb 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -1,9 +1,9 @@ - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: -+ name: dfs-parent-and-subpkg-both-fail - annotations: - kpt.dev/save-on-render-failure: "true" -- name: dfs-parent-and-subpkg-both-fail - info: - description: DFS - Both parent and subpackage fail - pipeline: -@@ -13,3 +13,11 @@ pipeline: - pkg: root - validators: - - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg ./subpkg: -+ pipeline.run: already handled error diff --git a/subpkg/Kptfile b/subpkg/Kptfile index a332cf5..cb45834 100644 --- a/subpkg/Kptfile @@ -39,10 +12,10 @@ index a332cf5..cb45834 100644 description: Subpackage that also fails pipeline: diff --git a/subpkg/service.yaml b/subpkg/service.yaml -index 276bf9e..7b26a8d 100644 +index 276bf9e..cd48b60 100644 --- a/subpkg/service.yaml +++ b/subpkg/service.yaml -@@ -2,6 +2,10 @@ apiVersion: v1 +@@ -2,6 +2,8 @@ apiVersion: v1 kind: Service metadata: name: sub-service @@ -51,5 +24,3 @@ index 276bf9e..7b26a8d 100644 spec: ports: - port: 80 -+ selector: -+ pkg: subpkg diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-mutator-fails/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-mutator-fails/.expected/diff.patch index eecfacca1c..0dc32fe5c1 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-mutator-fails/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-mutator-fails/.expected/diff.patch @@ -1,73 +1,12 @@ -diff --git a/Kptfile b/Kptfile -index c134b37..a48d9bb 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -1,14 +1,24 @@ - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: -+ name: dfs-parent-mutator-fails -+ labels: -+ test: parent-mutator-fail - annotations: - kpt.dev/save-on-render-failure: "true" -- name: dfs-parent-mutator-fails - info: - description: DFS - Parent mutator fails - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: -- test: "parent-mutator-fail" -+ test: parent-mutator-fail - - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg .: -+ pipeline.run: already handled error -diff --git a/configmap.yaml b/configmap.yaml -index 20a54f6..a46a12b 100644 ---- a/configmap.yaml -+++ b/configmap.yaml -@@ -2,5 +2,7 @@ apiVersion: v1 - kind: ConfigMap - metadata: - name: root-config -+ labels: -+ test: parent-mutator-fail - data: - key: value -diff --git a/subpkg/Kptfile b/subpkg/Kptfile -index e940ae8..9b73f07 100644 ---- a/subpkg/Kptfile -+++ b/subpkg/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: subpkg -+ namespace: subpkg-ns -+ labels: -+ test: parent-mutator-fail - info: - description: Subpackage that succeeds - pipeline: diff --git a/subpkg/service.yaml b/subpkg/service.yaml -index 276bf9e..571e684 100644 +index 276bf9e..5a2899c 100644 --- a/subpkg/service.yaml +++ b/subpkg/service.yaml -@@ -2,6 +2,11 @@ apiVersion: v1 +@@ -2,6 +2,7 @@ apiVersion: v1 kind: Service metadata: name: sub-service + namespace: subpkg-ns -+ labels: -+ test: parent-mutator-fail spec: ports: - port: 80 -+ selector: -+ test: parent-mutator-fail diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-mutator-fails/subpkg/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-mutator-fails/subpkg/Kptfile index e940ae88b9..fd277c8250 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-mutator-fails/subpkg/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-mutator-fails/subpkg/Kptfile @@ -6,6 +6,6 @@ info: description: Subpackage that succeeds pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: subpkg-ns diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-validator-fails/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-validator-fails/.expected/diff.patch index 0d65d79302..68451bb8b8 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-validator-fails/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-validator-fails/.expected/diff.patch @@ -1,35 +1,16 @@ diff --git a/Kptfile b/Kptfile -index 94a7a73..8965faa 100644 +index 94a7a73..a30e287 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,15 +1,25 @@ - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: -+ name: dfs-parent-validator-fails -+ labels: -+ test: parent-fail +@@ -4,6 +4,8 @@ metadata: annotations: kpt.dev/save-on-render-failure: "true" -- name: dfs-parent-validator-fails + name: dfs-parent-validator-fails ++ labels: ++ test: parent-fail info: description: DFS - Parent validator fails pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: -- test: "parent-fail" -+ test: parent-fail - validators: - - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg .: -+ pipeline.run: already handled error diff --git a/configmap.yaml b/configmap.yaml index 20a54f6..ad595de 100644 --- a/configmap.yaml @@ -43,24 +24,23 @@ index 20a54f6..ad595de 100644 data: key: value diff --git a/subpkg/Kptfile b/subpkg/Kptfile -index e940ae8..a2fe9c5 100644 +index fd277c8..ecbfb69 100644 --- a/subpkg/Kptfile +++ b/subpkg/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: subpkg -+ namespace: subpkg-ns + labels: + test: parent-fail info: description: Subpackage that succeeds pipeline: diff --git a/subpkg/service.yaml b/subpkg/service.yaml -index 276bf9e..3ba5cae 100644 +index 276bf9e..12c038b 100644 --- a/subpkg/service.yaml +++ b/subpkg/service.yaml -@@ -2,6 +2,11 @@ apiVersion: v1 +@@ -2,6 +2,9 @@ apiVersion: v1 kind: Service metadata: name: sub-service @@ -70,5 +50,3 @@ index 276bf9e..3ba5cae 100644 spec: ports: - port: 80 -+ selector: -+ test: parent-fail diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-validator-fails/subpkg/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-validator-fails/subpkg/Kptfile index e940ae88b9..fd277c8250 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-validator-fails/subpkg/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-validator-fails/subpkg/Kptfile @@ -6,6 +6,6 @@ info: description: Subpackage that succeeds pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: subpkg-ns diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-mutator-fails/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-mutator-fails/.expected/diff.patch index 514a0dde24..511e0005d7 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-mutator-fails/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-mutator-fails/.expected/diff.patch @@ -1,51 +1,95 @@ diff --git a/Kptfile b/Kptfile -index 80aa788..0fca116 100644 +index 368e39e..80aa788 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,13 +1,21 @@ - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: -+ name: dfs-subpkg-mutator-fails - annotations: - kpt.dev/save-on-render-failure: "true" +@@ -1,13 +1,13 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- annotations: +- kpt.dev/save-on-render-failure: "true" - name: dfs-subpkg-mutator-fails - info: - description: DFS - Subpackage mutator fails - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: +-info: +- description: DFS - Subpackage mutator fails +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 +- configMap: - test: "mutator-fail" -+ test: mutator-fail -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg ./subpkg: -+ pipeline.run: already handled error ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ annotations: ++ kpt.dev/save-on-render-failure: "true" ++ name: dfs-subpkg-mutator-fails ++info: ++ description: DFS - Subpackage mutator fails ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 ++ configMap: ++ test: "mutator-fail" +diff --git a/deployment.yaml b/deployment.yaml +index d4db082..cc866f6 100644 +--- a/deployment.yaml ++++ b/deployment.yaml +@@ -1,6 +1,6 @@ +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: root-deployment +-spec: +- replicas: 1 ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: root-deployment ++spec: ++ replicas: 1 diff --git a/subpkg/Kptfile b/subpkg/Kptfile -index ec4ce38..d7ac408 100644 +index ae05dfe..6563904 100644 --- a/subpkg/Kptfile +++ b/subpkg/Kptfile -@@ -2,6 +2,7 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: subpkg -+ namespace: subpkg-ns - info: - description: Subpackage with failing mutator - pipeline: +@@ -1,12 +1,12 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: subpkg +-info: +- description: Subpackage with failing mutator +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest +- configMap: +- namespace: subpkg-ns +- - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: subpkg ++info: ++ description: Subpackage with failing mutator ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest ++ configMap: ++ namespace: subpkg-ns ++ - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 diff --git a/subpkg/deployment.yaml b/subpkg/deployment.yaml -index 302322e..98ff830 100644 +index 1c4bc07..98ff830 100644 --- a/subpkg/deployment.yaml +++ b/subpkg/deployment.yaml -@@ -2,5 +2,6 @@ apiVersion: apps/v1 - kind: Deployment - metadata: - name: sub-deployment +@@ -1,6 +1,7 @@ +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: sub-deployment +-spec: +- replicas: 2 ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: sub-deployment + namespace: subpkg-ns - spec: - replicas: 2 ++spec: ++ replicas: 2 diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-mutator-fails/subpkg/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-mutator-fails/subpkg/Kptfile index ec4ce38547..65639042a0 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-mutator-fails/subpkg/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-mutator-fails/subpkg/Kptfile @@ -6,7 +6,7 @@ info: description: Subpackage with failing mutator pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: subpkg-ns - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-validator-fails/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-validator-fails/.expected/diff.patch index 4dbe465e7d..ef916a1b98 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-validator-fails/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-validator-fails/.expected/diff.patch @@ -1,45 +1,3 @@ -diff --git a/Kptfile b/Kptfile -index 7c3b09a..6bc279b 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -1,14 +1,22 @@ - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: -+ name: dfs-subpkg-validator-fails - annotations: - kpt.dev/save-on-render-failure: "true" -- name: dfs-subpkg-validator-fails - info: - description: DFS - Subpackage validator fails - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: -- test: "subpkg-fail" -- level: "root" -+ level: root -+ test: subpkg-fail -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg ./subpkg: -+ pipeline.run: already handled error -diff --git a/subpkg/Kptfile b/subpkg/Kptfile -index f147d84..b3c532e 100644 ---- a/subpkg/Kptfile -+++ b/subpkg/Kptfile -@@ -2,6 +2,7 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: subpkg -+ namespace: subpkg-ns - info: - description: Subpackage with failing validator - pipeline: diff --git a/subpkg/deployment.yaml b/subpkg/deployment.yaml index 302322e..98ff830 100644 --- a/subpkg/deployment.yaml diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-validator-fails/subpkg/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-validator-fails/subpkg/Kptfile index f147d84027..7dd3a25143 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-validator-fails/subpkg/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-validator-fails/subpkg/Kptfile @@ -6,7 +6,7 @@ info: description: Subpackage with failing validator pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: subpkg-ns validators: diff --git a/e2e/testdata/fn-render/save-on-render-failure/no-save-on-render-failure/.expected/diff.patch b/e2e/testdata/fn-render/save-on-render-failure/no-save-on-render-failure/.expected/diff.patch index 187669d407..e69de29bb2 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/no-save-on-render-failure/.expected/diff.patch +++ b/e2e/testdata/fn-render/save-on-render-failure/no-save-on-render-failure/.expected/diff.patch @@ -1,34 +0,0 @@ -diff --git a/Kptfile b/Kptfile -index 6e26cd3..fb2aa71 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -4,12 +4,20 @@ metadata: - name: no-save-on-render-failure - pipeline: - mutators: -- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -- configMap: -- namespace: staging -- - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 -- configMap: -- app: myapp -- - image: invalid-image:v0.0.0 -- configMap: -- tier: backend -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ configMap: -+ namespace: staging -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 -+ configMap: -+ app: myapp -+ - image: invalid-image:v0.0.0 -+ configMap: -+ tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "False" -+ reason: RenderFailed -+ message: |- -+ pkg.render: pkg .: -+ pipeline.run: already handled error diff --git a/e2e/testdata/fn-render/save-on-render-failure/no-save-on-render-failure/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/no-save-on-render-failure/Kptfile index 6e26cd3f3e..0cb6c3e75a 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/no-save-on-render-failure/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/no-save-on-render-failure/Kptfile @@ -4,7 +4,7 @@ metadata: name: no-save-on-render-failure pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 diff --git a/e2e/testdata/fn-render/selectors/basicpipeline/.expected/config.yaml b/e2e/testdata/fn-render/selectors/basicpipeline/.expected/config.yaml index 57b3444047..609c132e4a 100644 --- a/e2e/testdata/fn-render/selectors/basicpipeline/.expected/config.yaml +++ b/e2e/testdata/fn-render/selectors/basicpipeline/.expected/config.yaml @@ -21,8 +21,8 @@ stdErrStripLines: stdErr: | Package: "basicpipeline" - [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" on 1 resource(s) - [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" in 0s + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" on 1 resource(s) + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5" [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5" in 0s Successfully executed 2 function(s) in 1 package(s). diff --git a/e2e/testdata/fn-render/selectors/basicpipeline/.expected/diff.patch b/e2e/testdata/fn-render/selectors/basicpipeline/.expected/diff.patch index 8187cff1d0..b844e1345b 100644 --- a/e2e/testdata/fn-render/selectors/basicpipeline/.expected/diff.patch +++ b/e2e/testdata/fn-render/selectors/basicpipeline/.expected/diff.patch @@ -1,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index abc7b97..0b78750 100644 +index 351f2fe..e322be3 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,14 +2,21 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: app @@ -10,27 +10,12 @@ index abc7b97..0b78750 100644 + tier: backend pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 - configMap: - namespace: staging - selectors: -- - name: nginx-deployment -- kind: Deployment -+ - kind: Deployment -+ name: nginx-deployment - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest diff --git a/resources.yaml b/resources.yaml -index f2eec52..6b5d443 100644 +index f2eec52..e7f0c0b 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,12 +15,24 @@ apiVersion: apps/v1 +@@ -15,6 +15,9 @@ apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment @@ -39,15 +24,8 @@ index f2eec52..6b5d443 100644 + tier: backend spec: replicas: 3 -+ selector: -+ matchLabels: -+ tier: backend -+ template: -+ metadata: -+ labels: -+ tier: backend --- - apiVersion: custom.io/v1 +@@ -22,5 +25,7 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom diff --git a/e2e/testdata/fn-render/selectors/basicpipeline/Kptfile b/e2e/testdata/fn-render/selectors/basicpipeline/Kptfile index abc7b972c9..351f2feb05 100644 --- a/e2e/testdata/fn-render/selectors/basicpipeline/Kptfile +++ b/e2e/testdata/fn-render/selectors/basicpipeline/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging selectors: diff --git a/e2e/testdata/fn-render/selectors/exclude/.expected/config.yaml b/e2e/testdata/fn-render/selectors/exclude/.expected/config.yaml index c3726a64be..a606d03525 100644 --- a/e2e/testdata/fn-render/selectors/exclude/.expected/config.yaml +++ b/e2e/testdata/fn-render/selectors/exclude/.expected/config.yaml @@ -21,8 +21,8 @@ stdErrStripLines: stdErr: | Package: "exclude" - [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" on 1 resource(s) - [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" in 0s + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" on 1 resource(s) + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5" on 2 resource(s) [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5" in 0s Successfully executed 2 function(s) in 1 package(s). diff --git a/e2e/testdata/fn-render/selectors/exclude/.expected/diff.patch b/e2e/testdata/fn-render/selectors/exclude/.expected/diff.patch index c092089266..5164251518 100644 --- a/e2e/testdata/fn-render/selectors/exclude/.expected/diff.patch +++ b/e2e/testdata/fn-render/selectors/exclude/.expected/diff.patch @@ -1,30 +1,8 @@ -diff --git a/Kptfile b/Kptfile -index 266b33a..92e4a02 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -8,10 +8,15 @@ pipeline: - configMap: - namespace: staging - selectors: -- - name: nginx-deployment -- kind: Deployment -+ - kind: Deployment -+ name: nginx-deployment - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend - exclude: - - kind: Kptfile -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess diff --git a/resources.yaml b/resources.yaml -index f2eec52..6b5d443 100644 +index f2eec52..e7f0c0b 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,12 +15,24 @@ apiVersion: apps/v1 +@@ -15,6 +15,9 @@ apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment @@ -33,15 +11,8 @@ index f2eec52..6b5d443 100644 + tier: backend spec: replicas: 3 -+ selector: -+ matchLabels: -+ tier: backend -+ template: -+ metadata: -+ labels: -+ tier: backend --- - apiVersion: custom.io/v1 +@@ -22,5 +25,7 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom diff --git a/e2e/testdata/fn-render/selectors/exclude/Kptfile b/e2e/testdata/fn-render/selectors/exclude/Kptfile index 266b33a717..6632e9cd74 100644 --- a/e2e/testdata/fn-render/selectors/exclude/Kptfile +++ b/e2e/testdata/fn-render/selectors/exclude/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging selectors: diff --git a/e2e/testdata/fn-render/selectors/generator/.expected/config.yaml b/e2e/testdata/fn-render/selectors/generator/.expected/config.yaml index e8c0181cc4..10e7c3733f 100644 --- a/e2e/testdata/fn-render/selectors/generator/.expected/config.yaml +++ b/e2e/testdata/fn-render/selectors/generator/.expected/config.yaml @@ -23,13 +23,13 @@ stdErr: | Package: "generator/db" [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/starlark:latest" [PASS] "ghcr.io/kptdev/krm-functions-catalog/starlark:latest" in 0s - [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" on 1 resource(s) - [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" in 0s + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" on 1 resource(s) + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5" on 1 resource(s) [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5" in 0s Package: "generator" - [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" on 1 resource(s) - [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" in 0s + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" on 1 resource(s) + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5" on 1 resource(s) [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5" in 0s Successfully executed 5 function(s) in 2 package(s). diff --git a/e2e/testdata/fn-render/selectors/generator/.expected/diff.patch b/e2e/testdata/fn-render/selectors/generator/.expected/diff.patch index 9722438cf4..c8f6f65d25 100644 --- a/e2e/testdata/fn-render/selectors/generator/.expected/diff.patch +++ b/e2e/testdata/fn-render/selectors/generator/.expected/diff.patch @@ -1,16 +1,81 @@ diff --git a/Kptfile b/Kptfile -index eb2f084..cb608a0 100644 +index 8b11afc..15df83b 100644 --- a/Kptfile +++ b/Kptfile -@@ -14,3 +14,8 @@ pipeline: - tier: db - selectors: - - name: httpbin -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess +@@ -1,16 +1,16 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app-with-generator +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest +- configMap: +- namespace: staging +- selectors: +- - name: httpbin +- - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 +- configMap: +- tier: db +- selectors: +- - name: httpbin ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app-with-generator ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest ++ configMap: ++ namespace: staging ++ selectors: ++ - name: httpbin ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 ++ configMap: ++ tier: db ++ selectors: ++ - name: httpbin +diff --git a/db/Kptfile b/db/Kptfile +index 61d51d2..913523f 100644 +--- a/db/Kptfile ++++ b/db/Kptfile +@@ -1,18 +1,18 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: db +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest +- configPath: starlark-httpbin.yaml +- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest +- configMap: +- namespace: db +- selectors: +- - name: httpbin +- - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 +- configMap: +- app: backend +- selectors: +- - name: httpbin ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: db ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: starlark-httpbin.yaml ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest ++ configMap: ++ namespace: db ++ selectors: ++ - name: httpbin ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 ++ configMap: ++ app: backend ++ selectors: ++ - name: httpbin diff --git a/db/deployment_httpbin.yaml b/db/deployment_httpbin.yaml new file mode 100644 index 0000000..ffdf484 @@ -42,3 +107,218 @@ index 0000000..ffdf484 + matchLabels: + app: backend + tier: db +diff --git a/db/resources.yaml b/db/resources.yaml +index c9c269b..dabe43c 100644 +--- a/db/resources.yaml ++++ b/db/resources.yaml +@@ -1,19 +1,19 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: StatefulSet +-metadata: +- name: db +-spec: +- replicas: 3 ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: StatefulSet ++metadata: ++ name: db ++spec: ++ replicas: 3 +diff --git a/db/starlark-httpbin.yaml b/db/starlark-httpbin.yaml +index 07a7784..e52e48f 100644 +--- a/db/starlark-httpbin.yaml ++++ b/db/starlark-httpbin.yaml +@@ -1,55 +1,55 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: httpbin-gen +-source: |- +- httpbin_deployment = { +- "apiVersion": "apps/v1", +- "kind": "Deployment", +- "metadata": { +- "name": "httpbin", +- }, +- "spec": { +- "replicas": 4, +- "template": { +- "spec": { +- "containers": [ +- { +- "name": "httpbin", +- "image": "kennethreitz/httpbin", +- "ports": [ +- { +- "containerPort": 9876 +- } +- ] +- } +- ] +- } +- } +- } +- } +- # filter to return if resource is HTTPBin resource +- def is_httpbin(r): +- return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" +- +- def ensure_httpbin(resources): +- for r in resources: +- if is_httpbin(r): +- return +- +- resources.append(httpbin_deployment) +- +- ensure_httpbin(ctx.resource_list["items"]) ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: httpbin-gen ++source: |- ++ httpbin_deployment = { ++ "apiVersion": "apps/v1", ++ "kind": "Deployment", ++ "metadata": { ++ "name": "httpbin", ++ }, ++ "spec": { ++ "replicas": 4, ++ "template": { ++ "spec": { ++ "containers": [ ++ { ++ "name": "httpbin", ++ "image": "kennethreitz/httpbin", ++ "ports": [ ++ { ++ "containerPort": 9876 ++ } ++ ] ++ } ++ ] ++ } ++ } ++ } ++ } ++ # filter to return if resource is HTTPBin resource ++ def is_httpbin(r): ++ return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" ++ ++ def ensure_httpbin(resources): ++ for r in resources: ++ if is_httpbin(r): ++ return ++ ++ resources.append(httpbin_deployment) ++ ++ ensure_httpbin(ctx.resource_list["items"]) +diff --git a/resources.yaml b/resources.yaml +index 9d1f786..f2eec52 100644 +--- a/resources.yaml ++++ b/resources.yaml +@@ -1,26 +1,26 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment +-spec: +- replicas: 3 +---- +-apiVersion: custom.io/v1 +-kind: Custom +-metadata: +- name: custom +-spec: +- image: nginx:1.2.3 ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment ++spec: ++ replicas: 3 ++--- ++apiVersion: custom.io/v1 ++kind: Custom ++metadata: ++ name: custom ++spec: ++ image: nginx:1.2.3 diff --git a/e2e/testdata/fn-render/selectors/generator/Kptfile b/e2e/testdata/fn-render/selectors/generator/Kptfile index eb2f084f63..15df83b26a 100644 --- a/e2e/testdata/fn-render/selectors/generator/Kptfile +++ b/e2e/testdata/fn-render/selectors/generator/Kptfile @@ -4,7 +4,7 @@ metadata: name: app-with-generator pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging selectors: diff --git a/e2e/testdata/fn-render/selectors/generator/db/Kptfile b/e2e/testdata/fn-render/selectors/generator/db/Kptfile index 0eeaac2a4e..913523f0d3 100644 --- a/e2e/testdata/fn-render/selectors/generator/db/Kptfile +++ b/e2e/testdata/fn-render/selectors/generator/db/Kptfile @@ -6,7 +6,7 @@ pipeline: mutators: - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest configPath: starlark-httpbin.yaml - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: db selectors: diff --git a/e2e/testdata/fn-render/selectors/selectors-with-exclude/.expected/config.yaml b/e2e/testdata/fn-render/selectors/selectors-with-exclude/.expected/config.yaml index c777aff6b4..aff411b9db 100644 --- a/e2e/testdata/fn-render/selectors/selectors-with-exclude/.expected/config.yaml +++ b/e2e/testdata/fn-render/selectors/selectors-with-exclude/.expected/config.yaml @@ -21,8 +21,8 @@ stdErrStripLines: stdErr: | Package: "selectors-with-exclude" - [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" on 1 resource(s) - [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" in 0s + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" on 1 resource(s) + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5" [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5" in 0s Successfully executed 2 function(s) in 1 package(s). diff --git a/e2e/testdata/fn-render/selectors/selectors-with-exclude/.expected/diff.patch b/e2e/testdata/fn-render/selectors/selectors-with-exclude/.expected/diff.patch index ea9cd478bc..342bf37b21 100644 --- a/e2e/testdata/fn-render/selectors/selectors-with-exclude/.expected/diff.patch +++ b/e2e/testdata/fn-render/selectors/selectors-with-exclude/.expected/diff.patch @@ -1,5 +1,5 @@ diff --git a/Kptfile b/Kptfile -index c16cdca..8941f26 100644 +index bc10671..d8897bb 100644 --- a/Kptfile +++ b/Kptfile @@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 @@ -10,21 +10,12 @@ index c16cdca..8941f26 100644 + tier: backend pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -@@ -15,3 +17,8 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest diff --git a/resources.yaml b/resources.yaml -index d3ed04c..f66e542 100644 +index d3ed04c..09153ec 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -17,8 +17,17 @@ metadata: +@@ -17,6 +17,8 @@ metadata: name: nginx-deployment labels: foo: bar @@ -32,17 +23,8 @@ index d3ed04c..f66e542 100644 + namespace: staging spec: replicas: 3 -+ selector: -+ matchLabels: -+ tier: backend -+ template: -+ metadata: -+ labels: -+ tier: backend --- - apiVersion: custom.io/v1 - kind: Custom -@@ -26,5 +35,6 @@ metadata: +@@ -26,5 +28,6 @@ metadata: name: custom labels: foo: bar diff --git a/e2e/testdata/fn-render/selectors/selectors-with-exclude/Kptfile b/e2e/testdata/fn-render/selectors/selectors-with-exclude/Kptfile index c16cdcab24..bc106717b4 100644 --- a/e2e/testdata/fn-render/selectors/selectors-with-exclude/Kptfile +++ b/e2e/testdata/fn-render/selectors/selectors-with-exclude/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging selectors: diff --git a/e2e/testdata/fn-render/short-image-path/.expected/config.yaml b/e2e/testdata/fn-render/short-image-path/.expected/config.yaml index 4ea574d071..359f4574b0 100644 --- a/e2e/testdata/fn-render/short-image-path/.expected/config.yaml +++ b/e2e/testdata/fn-render/short-image-path/.expected/config.yaml @@ -16,8 +16,8 @@ actualStripLines: - " stderr: 'WARNING: The requested image''s platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested'" stdErr: | - [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" - [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" in 0s + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5" [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5" in 0s diff --git a/e2e/testdata/fn-render/short-image-path/.expected/diff.patch b/e2e/testdata/fn-render/short-image-path/.expected/diff.patch index 2312d6f22c..77a44de771 100644 --- a/e2e/testdata/fn-render/short-image-path/.expected/diff.patch +++ b/e2e/testdata/fn-render/short-image-path/.expected/diff.patch @@ -1,31 +1,21 @@ diff --git a/Kptfile b/Kptfile -index d4e5935..95f5ba8 100644 +index 5e29eb2..37954f5 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: app -+ namespace: staging + labels: + tier: backend pipeline: mutators: - - image: set-namespace:v0.2.0 -@@ -10,3 +13,8 @@ pipeline: - - image: set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess + - image: set-namespace:latest diff --git a/resources.yaml b/resources.yaml -index f2eec52..84cfb26 100644 +index f2eec52..e7f0c0b 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,12 +15,25 @@ apiVersion: apps/v1 +@@ -15,6 +15,9 @@ apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment @@ -34,19 +24,11 @@ index f2eec52..84cfb26 100644 + tier: backend spec: replicas: 3 -+ selector: -+ matchLabels: -+ tier: backend -+ template: -+ metadata: -+ labels: -+ tier: backend --- - apiVersion: custom.io/v1 +@@ -22,5 +25,7 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom -+ namespace: staging + labels: + tier: backend spec: diff --git a/e2e/testdata/fn-render/short-image-path/.expected/results.yaml b/e2e/testdata/fn-render/short-image-path/.expected/results.yaml index 1ea8a8f00b..b326e355a3 100755 --- a/e2e/testdata/fn-render/short-image-path/.expected/results.yaml +++ b/e2e/testdata/fn-render/short-image-path/.expected/results.yaml @@ -4,7 +4,7 @@ metadata: name: fnresults exitCode: 0 items: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest exitCode: 0 - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 exitCode: 0 diff --git a/e2e/testdata/fn-render/short-image-path/Kptfile b/e2e/testdata/fn-render/short-image-path/Kptfile index d4e59353ef..5e29eb2fa8 100644 --- a/e2e/testdata/fn-render/short-image-path/Kptfile +++ b/e2e/testdata/fn-render/short-image-path/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: set-namespace:v0.2.0 + - image: set-namespace:latest configMap: namespace: staging - image: set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/structured-results-from-muiltiple-fns/.expected/results.yaml b/e2e/testdata/fn-render/structured-results-from-muiltiple-fns/.expected/results.yaml index 098ca6dea9..be7f46f76d 100755 --- a/e2e/testdata/fn-render/structured-results-from-muiltiple-fns/.expected/results.yaml +++ b/e2e/testdata/fn-render/structured-results-from-muiltiple-fns/.expected/results.yaml @@ -2,56 +2,4 @@ apiVersion: kpt.dev/v1 kind: FunctionResultList metadata: name: fnresults -exitCode: 1 -items: - - image: ghcr.io/kptdev/krm-functions-catalog/gatekeeper:latest - exitCode: 0 - results: - - message: |- - The following banned keys are being used in the ConfigMap: {"private_key"} - violatedConstraint: no-secrets-in-configmap - severity: warning - resourceRef: - apiVersion: v1 - kind: ConfigMap - name: some-secret - namespace: default - file: - path: resources.yaml - index: 4 - - message: |- - The following banned keys are being used in the ConfigMap: {"less_sensitive_key"} - violatedConstraint: no-sensitive-data-in-configmap - severity: info - resourceRef: - apiVersion: v1 - kind: ConfigMap - name: some-secret - namespace: default - file: - path: resources.yaml - index: 4 - - image: ghcr.io/kptdev/krm-functions-catalog/kubeconform:latest - stderr: 'failed to evaluate function: error: function failure' - exitCode: 1 - results: - - message: missing properties 'selector', 'template' - severity: error - resourceRef: - apiVersion: apps/v1 - kind: Deployment - name: nginx-deployment - field: - path: spec - file: - path: resources.yaml - - message: got string, want null or integer - severity: error - resourceRef: - apiVersion: apps/v1 - kind: Deployment - name: nginx-deployment - field: - path: spec.replicas - file: - path: resources.yaml +exitCode: 0 diff --git a/e2e/testdata/fn-render/subpkg-fn-failure/Kptfile b/e2e/testdata/fn-render/subpkg-fn-failure/Kptfile index 364e274d3e..7316bb0b1a 100644 --- a/e2e/testdata/fn-render/subpkg-fn-failure/Kptfile +++ b/e2e/testdata/fn-render/subpkg-fn-failure/Kptfile @@ -6,7 +6,7 @@ pipeline: mutators: - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest configPath: starlark-httpbin.yaml - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/subpkg-fn-failure/db/Kptfile b/e2e/testdata/fn-render/subpkg-fn-failure/db/Kptfile index 6c7674c0af..9295ee3a83 100644 --- a/e2e/testdata/fn-render/subpkg-fn-failure/db/Kptfile +++ b/e2e/testdata/fn-render/subpkg-fn-failure/db/Kptfile @@ -6,7 +6,7 @@ pipeline: mutators: - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest configPath: statefulset-filter.yaml - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: db - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/subpkg-has-invalid-kptfile/Kptfile b/e2e/testdata/fn-render/subpkg-has-invalid-kptfile/Kptfile index 1307fb5426..93ae454de7 100644 --- a/e2e/testdata/fn-render/subpkg-has-invalid-kptfile/Kptfile +++ b/e2e/testdata/fn-render/subpkg-has-invalid-kptfile/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/subpkg-has-invalid-kptfile/db/Kptfile b/e2e/testdata/fn-render/subpkg-has-invalid-kptfile/db/Kptfile index c235ded584..ea39e22f9f 100644 --- a/e2e/testdata/fn-render/subpkg-has-invalid-kptfile/db/Kptfile +++ b/e2e/testdata/fn-render/subpkg-has-invalid-kptfile/db/Kptfile @@ -7,7 +7,7 @@ pipeline: - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest # malformed Kptfile configPath: statefulset-filter.yaml - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: db - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/subpkg-has-samename-subdir/.expected/diff.patch b/e2e/testdata/fn-render/subpkg-has-samename-subdir/.expected/diff.patch index cb038df6d8..11af1f7ad6 100644 --- a/e2e/testdata/fn-render/subpkg-has-samename-subdir/.expected/diff.patch +++ b/e2e/testdata/fn-render/subpkg-has-samename-subdir/.expected/diff.patch @@ -1,30 +1,5 @@ -diff --git a/Kptfile b/Kptfile -index 701e0a1..3107d07 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -4,3 +4,8 @@ metadata: - name: root-pkg - info: - description: sample description -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -diff --git a/pkg-a/Kptfile b/pkg-a/Kptfile -index 088bc03..c42f368 100644 ---- a/pkg-a/Kptfile -+++ b/pkg-a/Kptfile -@@ -2,6 +2,7 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: pkg-a -+ namespace: dev - info: - description: sample description - pipeline: diff --git a/pkg-a/pkg-a/resources.yaml b/pkg-a/pkg-a/resources.yaml -index f2eec52..c4e4abb 100644 +index f2eec52..1934a8f 100644 --- a/pkg-a/pkg-a/resources.yaml +++ b/pkg-a/pkg-a/resources.yaml @@ -15,6 +15,7 @@ apiVersion: apps/v1 @@ -35,10 +10,3 @@ index f2eec52..c4e4abb 100644 spec: replicas: 3 --- -@@ -22,5 +23,6 @@ apiVersion: custom.io/v1 - kind: Custom - metadata: - name: custom -+ namespace: dev - spec: - image: nginx:1.2.3 diff --git a/e2e/testdata/fn-render/subpkg-has-samename-subdir/pkg-a/Kptfile b/e2e/testdata/fn-render/subpkg-has-samename-subdir/pkg-a/Kptfile index 088bc0319c..4a4ab87785 100644 --- a/e2e/testdata/fn-render/subpkg-has-samename-subdir/pkg-a/Kptfile +++ b/e2e/testdata/fn-render/subpkg-has-samename-subdir/pkg-a/Kptfile @@ -6,6 +6,6 @@ info: description: sample description pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: dev diff --git a/e2e/testdata/fn-render/subpkg-resource-deletion/.expected/diff.patch b/e2e/testdata/fn-render/subpkg-resource-deletion/.expected/diff.patch index ace86b1bd8..b0248356d4 100644 --- a/e2e/testdata/fn-render/subpkg-resource-deletion/.expected/diff.patch +++ b/e2e/testdata/fn-render/subpkg-resource-deletion/.expected/diff.patch @@ -1,46 +1,79 @@ diff --git a/Kptfile b/Kptfile -index 364e274..9ad7200 100644 +index 1e4b14a..8d6e225 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: app -+ namespace: staging +@@ -1,14 +1,16 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: app +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest +- configPath: starlark-httpbin.yaml +- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest +- configMap: +- namespace: staging +- - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 +- configMap: +- tier: backend ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: app + labels: + tier: backend - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -@@ -12,3 +15,8 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: starlark-httpbin.yaml ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest ++ configMap: ++ namespace: staging ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 ++ configMap: ++ tier: backend diff --git a/db/Kptfile b/db/Kptfile -index 6c7674c..11fe9cc 100644 +index e8a364c..cd33860 100644 --- a/db/Kptfile +++ b/db/Kptfile -@@ -2,6 +2,10 @@ apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: db -+ namespace: staging +@@ -1,14 +1,17 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: db +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest +- configPath: statefulset-filter.yaml +- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest +- configMap: +- namespace: db +- - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 +- configMap: +- app: backend ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: db + labels: + app: backend + tier: backend - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: statefulset-filter.yaml ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest ++ configMap: ++ namespace: db ++ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 ++ configMap: ++ app: backend diff --git a/db/resources.yaml b/db/resources.yaml -index f983597..9dabb18 100644 +index 2905805..e21782c 100644 --- a/db/resources.yaml +++ b/db/resources.yaml -@@ -1,26 +1,10 @@ +@@ -1,26 +1,9 @@ -# Copyright 2021 The kpt Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); @@ -61,34 +94,80 @@ index f983597..9dabb18 100644 -spec: - replicas: 3 ---- - apiVersion: custom.io/v1 - kind: Custom - metadata: - name: custom -+ namespace: staging +-apiVersion: custom.io/v1 +-kind: Custom +-metadata: +- name: custom +-spec: +- image: nginx:1.2.3 ++apiVersion: custom.io/v1 ++kind: Custom ++metadata: ++ name: custom + labels: + app: backend + tier: backend - spec: - image: nginx:1.2.3 ++spec: ++ image: nginx:1.2.3 diff --git a/db/statefulset-filter.yaml b/db/statefulset-filter.yaml -index e1f7b67..ac69c02 100644 +index f47fa4e..8ab4033 100644 --- a/db/statefulset-filter.yaml +++ b/db/statefulset-filter.yaml -@@ -15,6 +15,10 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: statefulset-filter -+ namespace: staging +@@ -1,24 +1,27 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: statefulset-filter +-source: | +- # filter to return if resource is statefulset kind +- def isStatefulSet(r): +- return r["apiVersion"] == "apps/v1" and r["kind"] == "StatefulSet" +- +- # filter out statefulsets +- ctx.resource_list["items"] = [r for r in ctx.resource_list["items"] if not isStatefulSet(r)] ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: statefulset-filter + labels: + app: backend + tier: backend - source: | - # filter to return if resource is statefulset kind - def isStatefulSet(r): ++source: | ++ # filter to return if resource is statefulset kind ++ def isStatefulSet(r): ++ return r["apiVersion"] == "apps/v1" and r["kind"] == "StatefulSet" ++ ++ # filter out statefulsets ++ ctx.resource_list["items"] = [r for r in ctx.resource_list["items"] if not isStatefulSet(r)] diff --git a/deployment_httpbin.yaml b/deployment_httpbin.yaml deleted file mode 100644 -index 49d4f6e..0000000 +index b4028f8..0000000 --- a/deployment_httpbin.yaml +++ /dev/null @@ -1,36 +0,0 @@ @@ -129,18 +208,51 @@ index 49d4f6e..0000000 - - name: httpbin - image: kennethreitz/httpbin diff --git a/resources.yaml b/resources.yaml -index 239f0d6..9ca3271 100644 +index 027731c..9ca3271 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,5 +15,15 @@ apiVersion: apps/v1 - kind: Deployment - metadata: - name: nginx-deployment +@@ -1,19 +1,29 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment +-spec: +- replicas: 3 ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment + namespace: staging + labels: + tier: backend - spec: - replicas: 3 ++spec: ++ replicas: 3 + selector: + matchLabels: + tier: backend @@ -149,16 +261,57 @@ index 239f0d6..9ca3271 100644 + labels: + tier: backend diff --git a/starlark-httpbin.yaml b/starlark-httpbin.yaml -index fd90109..e437ba7 100644 +index b668683..f9174fb 100644 --- a/starlark-httpbin.yaml +++ b/starlark-httpbin.yaml -@@ -15,6 +15,9 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: httpbin-gen -+ namespace: staging +@@ -1,24 +1,26 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: httpbin-gen +-source: | +- # filter to return if resource is HTTPBin resource +- def isHTTPBin(r): +- return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" +- +- # filter out the httpbin deployment +- ctx.resource_list["items"] = [r for r in ctx.resource_list["items"] if not isHTTPBin(r)] ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: httpbin-gen + labels: + tier: backend - source: | - # filter to return if resource is HTTPBin resource - def isHTTPBin(r): ++source: | ++ # filter to return if resource is HTTPBin resource ++ def isHTTPBin(r): ++ return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" ++ ++ # filter out the httpbin deployment ++ ctx.resource_list["items"] = [r for r in ctx.resource_list["items"] if not isHTTPBin(r)] diff --git a/e2e/testdata/fn-render/subpkg-resource-deletion/Kptfile b/e2e/testdata/fn-render/subpkg-resource-deletion/Kptfile index 364e274d3e..7316bb0b1a 100644 --- a/e2e/testdata/fn-render/subpkg-resource-deletion/Kptfile +++ b/e2e/testdata/fn-render/subpkg-resource-deletion/Kptfile @@ -6,7 +6,7 @@ pipeline: mutators: - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest configPath: starlark-httpbin.yaml - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/subpkg-resource-deletion/db/Kptfile b/e2e/testdata/fn-render/subpkg-resource-deletion/db/Kptfile index 6c7674c0af..9295ee3a83 100644 --- a/e2e/testdata/fn-render/subpkg-resource-deletion/db/Kptfile +++ b/e2e/testdata/fn-render/subpkg-resource-deletion/db/Kptfile @@ -6,7 +6,7 @@ pipeline: mutators: - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest configPath: statefulset-filter.yaml - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: db - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/subpkgs-with-krmignore/.expected/diff.patch b/e2e/testdata/fn-render/subpkgs-with-krmignore/.expected/diff.patch index 63ae894e45..915926857d 100644 --- a/e2e/testdata/fn-render/subpkgs-with-krmignore/.expected/diff.patch +++ b/e2e/testdata/fn-render/subpkgs-with-krmignore/.expected/diff.patch @@ -1,46 +1,35 @@ diff --git a/Kptfile b/Kptfile -index 82686a8..a4b2da6 100644 +index f97e8a4..4215c05 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: app-with-db -+ namespace: staging + labels: + tier: db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -@@ -10,3 +13,8 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: db -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest diff --git a/db/Kptfile b/db/Kptfile -index 264dd2e..8dd7c37 100644 +index 0c2b57a..bf7230a 100644 --- a/db/Kptfile +++ b/db/Kptfile -@@ -2,6 +2,10 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: db -+ namespace: staging + labels: + app: backend + tier: db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest diff --git a/db/resources.yaml b/db/resources.yaml -index dabe43c..e9be40c 100644 +index dabe43c..1be815b 100644 --- a/db/resources.yaml +++ b/db/resources.yaml -@@ -15,5 +15,18 @@ apiVersion: apps/v1 +@@ -15,5 +15,9 @@ apiVersion: apps/v1 kind: StatefulSet metadata: name: db @@ -50,20 +39,11 @@ index dabe43c..e9be40c 100644 + tier: db spec: replicas: 3 -+ selector: -+ matchLabels: -+ app: backend -+ tier: db -+ template: -+ metadata: -+ labels: -+ app: backend -+ tier: db diff --git a/resources.yaml b/resources.yaml -index f2eec52..8b2113d 100644 +index f2eec52..75f836e 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,12 +15,25 @@ apiVersion: apps/v1 +@@ -15,6 +15,9 @@ apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment @@ -72,19 +52,11 @@ index f2eec52..8b2113d 100644 + tier: db spec: replicas: 3 -+ selector: -+ matchLabels: -+ tier: db -+ template: -+ metadata: -+ labels: -+ tier: db --- - apiVersion: custom.io/v1 +@@ -22,5 +25,7 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom -+ namespace: staging + labels: + tier: db spec: diff --git a/e2e/testdata/fn-render/subpkgs-with-krmignore/Kptfile b/e2e/testdata/fn-render/subpkgs-with-krmignore/Kptfile index 82686a8952..f97e8a4746 100644 --- a/e2e/testdata/fn-render/subpkgs-with-krmignore/Kptfile +++ b/e2e/testdata/fn-render/subpkgs-with-krmignore/Kptfile @@ -4,7 +4,7 @@ metadata: name: app-with-db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/subpkgs-with-krmignore/db/Kptfile b/e2e/testdata/fn-render/subpkgs-with-krmignore/db/Kptfile index 264dd2eb78..0c2b57a9b6 100644 --- a/e2e/testdata/fn-render/subpkgs-with-krmignore/db/Kptfile +++ b/e2e/testdata/fn-render/subpkgs-with-krmignore/db/Kptfile @@ -4,7 +4,7 @@ metadata: name: db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: db - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/subpkgs/.expected/diff.patch b/e2e/testdata/fn-render/subpkgs/.expected/diff.patch index 63ae894e45..915926857d 100644 --- a/e2e/testdata/fn-render/subpkgs/.expected/diff.patch +++ b/e2e/testdata/fn-render/subpkgs/.expected/diff.patch @@ -1,46 +1,35 @@ diff --git a/Kptfile b/Kptfile -index 82686a8..a4b2da6 100644 +index f97e8a4..4215c05 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: app-with-db -+ namespace: staging + labels: + tier: db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -@@ -10,3 +13,8 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: db -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest diff --git a/db/Kptfile b/db/Kptfile -index 264dd2e..8dd7c37 100644 +index 0c2b57a..bf7230a 100644 --- a/db/Kptfile +++ b/db/Kptfile -@@ -2,6 +2,10 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: db -+ namespace: staging + labels: + app: backend + tier: db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest diff --git a/db/resources.yaml b/db/resources.yaml -index dabe43c..e9be40c 100644 +index dabe43c..1be815b 100644 --- a/db/resources.yaml +++ b/db/resources.yaml -@@ -15,5 +15,18 @@ apiVersion: apps/v1 +@@ -15,5 +15,9 @@ apiVersion: apps/v1 kind: StatefulSet metadata: name: db @@ -50,20 +39,11 @@ index dabe43c..e9be40c 100644 + tier: db spec: replicas: 3 -+ selector: -+ matchLabels: -+ app: backend -+ tier: db -+ template: -+ metadata: -+ labels: -+ app: backend -+ tier: db diff --git a/resources.yaml b/resources.yaml -index f2eec52..8b2113d 100644 +index f2eec52..75f836e 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,12 +15,25 @@ apiVersion: apps/v1 +@@ -15,6 +15,9 @@ apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment @@ -72,19 +52,11 @@ index f2eec52..8b2113d 100644 + tier: db spec: replicas: 3 -+ selector: -+ matchLabels: -+ tier: db -+ template: -+ metadata: -+ labels: -+ tier: db --- - apiVersion: custom.io/v1 +@@ -22,5 +25,7 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom -+ namespace: staging + labels: + tier: db spec: diff --git a/e2e/testdata/fn-render/subpkgs/Kptfile b/e2e/testdata/fn-render/subpkgs/Kptfile index 82686a8952..f97e8a4746 100644 --- a/e2e/testdata/fn-render/subpkgs/Kptfile +++ b/e2e/testdata/fn-render/subpkgs/Kptfile @@ -4,7 +4,7 @@ metadata: name: app-with-db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/subpkgs/db/Kptfile b/e2e/testdata/fn-render/subpkgs/db/Kptfile index 264dd2eb78..0c2b57a9b6 100644 --- a/e2e/testdata/fn-render/subpkgs/db/Kptfile +++ b/e2e/testdata/fn-render/subpkgs/db/Kptfile @@ -4,7 +4,7 @@ metadata: name: db pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: db - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/success-stdout/.expected/diff.patch b/e2e/testdata/fn-render/success-stdout/.expected/diff.patch index 16337308e3..679e31b313 100644 --- a/e2e/testdata/fn-render/success-stdout/.expected/diff.patch +++ b/e2e/testdata/fn-render/success-stdout/.expected/diff.patch @@ -1,31 +1,21 @@ diff --git a/Kptfile b/Kptfile -index 1307fb5..f645d75 100644 +index 93ae454..9caee20 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: app -+ namespace: staging + labels: + tier: backend pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -@@ -10,3 +13,8 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest diff --git a/resources.yaml b/resources.yaml -index f2eec52..84cfb26 100644 +index f2eec52..e7f0c0b 100644 --- a/resources.yaml +++ b/resources.yaml -@@ -15,12 +15,25 @@ apiVersion: apps/v1 +@@ -15,6 +15,9 @@ apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment @@ -34,19 +24,11 @@ index f2eec52..84cfb26 100644 + tier: backend spec: replicas: 3 -+ selector: -+ matchLabels: -+ tier: backend -+ template: -+ metadata: -+ labels: -+ tier: backend --- - apiVersion: custom.io/v1 +@@ -22,5 +25,7 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom -+ namespace: staging + labels: + tier: backend spec: diff --git a/e2e/testdata/fn-render/success-stdout/Kptfile b/e2e/testdata/fn-render/success-stdout/Kptfile index 1307fb5426..93ae454de7 100644 --- a/e2e/testdata/fn-render/success-stdout/Kptfile +++ b/e2e/testdata/fn-render/success-stdout/Kptfile @@ -4,7 +4,7 @@ metadata: name: app pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest configMap: namespace: staging - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 diff --git a/e2e/testdata/fn-render/validate-generated-resource/.expected/diff.patch b/e2e/testdata/fn-render/validate-generated-resource/.expected/diff.patch index 5499661a18..c0feb501ac 100644 --- a/e2e/testdata/fn-render/validate-generated-resource/.expected/diff.patch +++ b/e2e/testdata/fn-render/validate-generated-resource/.expected/diff.patch @@ -1,16 +1,30 @@ diff --git a/Kptfile b/Kptfile -index b2432a4..0362808 100644 +index 5c1d9fa..b2432a4 100644 --- a/Kptfile +++ b/Kptfile -@@ -9,3 +9,8 @@ pipeline: - validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-httpbin-val.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess +@@ -1,11 +1,11 @@ +-apiVersion: kpt.dev/v1 +-kind: Kptfile +-metadata: +- name: db +-pipeline: +- mutators: +- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest +- configPath: starlark-httpbin-gen.yaml +- validators: +- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest +- configPath: starlark-httpbin-val.yaml ++apiVersion: kpt.dev/v1 ++kind: Kptfile ++metadata: ++ name: db ++pipeline: ++ mutators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: starlark-httpbin-gen.yaml ++ validators: ++ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest ++ configPath: starlark-httpbin-val.yaml diff --git a/deployment_httpbin.yaml b/deployment_httpbin.yaml new file mode 100644 index 0000000..f36c98e @@ -30,3 +44,228 @@ index 0000000..f36c98e + name: httpbin + ports: + - containerPort: 9876 +diff --git a/resources.yaml b/resources.yaml +index 9d1f786..f2eec52 100644 +--- a/resources.yaml ++++ b/resources.yaml +@@ -1,26 +1,26 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: apps/v1 +-kind: Deployment +-metadata: +- name: nginx-deployment +-spec: +- replicas: 3 +---- +-apiVersion: custom.io/v1 +-kind: Custom +-metadata: +- name: custom +-spec: +- image: nginx:1.2.3 ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: apps/v1 ++kind: Deployment ++metadata: ++ name: nginx-deployment ++spec: ++ replicas: 3 ++--- ++apiVersion: custom.io/v1 ++kind: Custom ++metadata: ++ name: custom ++spec: ++ image: nginx:1.2.3 +diff --git a/starlark-httpbin-gen.yaml b/starlark-httpbin-gen.yaml +index 07a7784..e52e48f 100644 +--- a/starlark-httpbin-gen.yaml ++++ b/starlark-httpbin-gen.yaml +@@ -1,55 +1,55 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: httpbin-gen +-source: |- +- httpbin_deployment = { +- "apiVersion": "apps/v1", +- "kind": "Deployment", +- "metadata": { +- "name": "httpbin", +- }, +- "spec": { +- "replicas": 4, +- "template": { +- "spec": { +- "containers": [ +- { +- "name": "httpbin", +- "image": "kennethreitz/httpbin", +- "ports": [ +- { +- "containerPort": 9876 +- } +- ] +- } +- ] +- } +- } +- } +- } +- # filter to return if resource is HTTPBin resource +- def is_httpbin(r): +- return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" +- +- def ensure_httpbin(resources): +- for r in resources: +- if is_httpbin(r): +- return +- +- resources.append(httpbin_deployment) +- +- ensure_httpbin(ctx.resource_list["items"]) ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: httpbin-gen ++source: |- ++ httpbin_deployment = { ++ "apiVersion": "apps/v1", ++ "kind": "Deployment", ++ "metadata": { ++ "name": "httpbin", ++ }, ++ "spec": { ++ "replicas": 4, ++ "template": { ++ "spec": { ++ "containers": [ ++ { ++ "name": "httpbin", ++ "image": "kennethreitz/httpbin", ++ "ports": [ ++ { ++ "containerPort": 9876 ++ } ++ ] ++ } ++ ] ++ } ++ } ++ } ++ } ++ # filter to return if resource is HTTPBin resource ++ def is_httpbin(r): ++ return r["apiVersion"] == "apps/v1" and r["kind"] == "Deployment" and r["metadata"]["name"] == "httpbin" ++ ++ def ensure_httpbin(resources): ++ for r in resources: ++ if is_httpbin(r): ++ return ++ ++ resources.append(httpbin_deployment) ++ ++ ensure_httpbin(ctx.resource_list["items"]) +diff --git a/starlark-httpbin-val.yaml b/starlark-httpbin-val.yaml +index 386aa6f..81973cf 100644 +--- a/starlark-httpbin-val.yaml ++++ b/starlark-httpbin-val.yaml +@@ -1,24 +1,24 @@ +-# Copyright 2021 The kpt Authors +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +-apiVersion: fn.kpt.dev/v1alpha1 +-kind: StarlarkRun +-metadata: +- name: httpbin-val +-source: |- +- def contains_httpbin_resource(resource_list): +- for r in resource_list["items"]: +- if r["metadata"]["name"] == "httpbin" and r["kind"] == "Deployment": +- return +- fail("could not find httpbin deployment") +- contains_httpbin_resource(ctx.resource_list) ++# Copyright 2021 The kpt Authors ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++apiVersion: fn.kpt.dev/v1alpha1 ++kind: StarlarkRun ++metadata: ++ name: httpbin-val ++source: |- ++ def contains_httpbin_resource(resource_list): ++ for r in resource_list["items"]: ++ if r["metadata"]["name"] == "httpbin" and r["kind"] == "Deployment": ++ return ++ fail("could not find httpbin deployment") ++ contains_httpbin_resource(ctx.resource_list) diff --git a/e2e/testdata/fn-render/validate-resource-failure/.expected/results.yaml b/e2e/testdata/fn-render/validate-resource-failure/.expected/results.yaml index 9d17070ca8..be7f46f76d 100755 --- a/e2e/testdata/fn-render/validate-resource-failure/.expected/results.yaml +++ b/e2e/testdata/fn-render/validate-resource-failure/.expected/results.yaml @@ -2,11 +2,4 @@ apiVersion: kpt.dev/v1 kind: FunctionResultList metadata: name: fnresults -exitCode: 1 -items: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - stderr: 'failed to evaluate function: error: function failure' - exitCode: 1 - results: - - message: 'fail: could not find httpbin deployment' - severity: error +exitCode: 0 diff --git a/internal/docs/generated/fndocs/docs.go b/internal/docs/generated/fndocs/docs.go index 4fc85f397b..1688590bb2 100644 --- a/internal/docs/generated/fndocs/docs.go +++ b/internal/docs/generated/fndocs/docs.go @@ -161,20 +161,20 @@ Environment Variables: var EvalExamples = ` # execute container my-fn on the resources in DIR directory and # write output back to DIR - $ kpt fn eval DIR -i ghcr.io/example.com/my-fn + $ kpt fn eval DIR -i gcr.io/example.com/my-fn # execute container my-fn on the resources in DIR directory with # ` + "`" + `functionConfig` + "`" + ` my-fn-config - $ kpt fn eval DIR -i ghcr.io/example.com/my-fn --fn-config my-fn-config + $ kpt fn eval DIR -i gcr.io/example.com/my-fn --fn-config my-fn-config # execute container my-fn with an input ConfigMap containing ` + "`" + `data: {foo: bar}` + "`" + ` - $ kpt fn eval DIR -i ghcr.io/example.com/my-fn:v1.0.0 -- foo=bar + $ kpt fn eval DIR -i gcr.io/example.com/my-fn:v1.0.0 -- foo=bar # execute container my-fn and save it to Kptfile ` + "`" + `pipeline.mutators` + "`" + ` (Default) list. - $ kpt fn eval DIR -s -i ghcr.io/example.com/my-fn:v1.0.0 -- foo=bar + $ kpt fn eval DIR -s -i gcr.io/example.com/my-fn:v1.0.0 -- foo=bar # execute container my-fn and save it to Kptfile ` + "`" + `pipeline.validators` + "`" + ` list. - $ kpt fn eval DIR -s -t validator -i ghcr.io/example.com/my-fn:v1.0.0 -- foo=bar + $ kpt fn eval DIR -s -t validator -i gcr.io/example.com/my-fn:v1.0.0 -- foo=bar # execute executable my-fn on the resources in DIR directory and # write output back to DIR @@ -186,15 +186,15 @@ var EvalExamples = ` # execute container my-fn on the resources in DIR directory, # save structured results in /tmp/my-results dir and write output back to DIR - $ kpt fn eval DIR -i ghcr.io/example.com/my-fn --results-dir /tmp/my-results-dir + $ kpt fn eval DIR -i gcr.io/example.com/my-fn --results-dir /tmp/my-results-dir # execute container my-fn on the resources in DIR directory with network access enabled, # and write output back to DIR - $ kpt fn eval DIR -i ghcr.io/example.com/my-fn --network + $ kpt fn eval DIR -i gcr.io/example.com/my-fn --network # execute container my-fn on the resource in DIR and export KUBECONFIG # and foo environment variable - $ kpt fn eval DIR -i ghcr.io/example.com/my-fn --env KUBECONFIG -e foo=bar + $ kpt fn eval DIR -i gcr.io/example.com/my-fn --env KUBECONFIG -e foo=bar # execute kubeconform function by mounting schema from a local directory on wordpress package $ kpt fn eval -i ghcr.io/kptdev/krm-functions-catalog/kubeconform:latest \ @@ -229,7 +229,7 @@ var EvalExamples = ` # execute container my-fn with podman on the resources in DIR directory and # write output back to DIR - $ KRM_FN_RUNTIME=podman kpt fn eval DIR -i ghcr.io/example.com/my-fn + $ KRM_FN_RUNTIME=podman kpt fn eval DIR -i gcr.io/example.com/my-fn ` var RenderShort = `Render a package.` @@ -272,16 +272,6 @@ Flags: to ` + "`" + `results.yaml` + "`" + ` file in the specified directory. If not specified, no result files are written to the local filesystem. -Kptfile Annotations: - - kpt.dev/save-on-render-failure: - Controls whether partially rendered resources are saved when rendering fails. - Set to "true" in the Kptfile metadata.annotations section to preserve the state - of resources at the point of failure. This is useful for debugging render failures - and understanding what changes were applied before the error occurred. - This follows the same pattern as kpt.dev/bfs-rendering annotation. - Default: false (failures will revert changes). - Environment Variables: KRM_FN_RUNTIME: @@ -315,15 +305,6 @@ var RenderExamples = ` # Render my-package-dir with network access enabled for functions $ kpt fn render --allow-network - - # Example Kptfile with save-on-render-failure annotation - apiVersion: kpt.dev/v1 - kind: Kptfile - metadata: - name: my-package - annotations: - kpt.dev/save-on-render-failure: "true" - ... ` var SinkShort = `Write resources to a local directory` @@ -337,7 +318,7 @@ var SinkExamples = ` # read resources from DIR directory, execute my-fn on them and write the # output to DIR directory. $ kpt fn source DIR | - kpt fn eval - --image ghcr.io/example.com/my-fn | + kpt fn eval - --image gcr.io/example.com/my-fn | kpt fn sink NEW_DIR ` @@ -373,6 +354,6 @@ var SourceExamples = ` # read resources from DIR directory, execute my-fn on them and write the # output to DIR directory. $ kpt fn source DIR | - kpt fn eval - --image ghcr.io/example.com/my-fn - | + kpt fn eval - --image gcr.io/example.com/my-fn - | kpt fn sink DIR ` diff --git a/internal/docs/generated/wasmdocs/docs.go b/internal/docs/generated/wasmdocs/docs.go index 4e2e51ac34..a4f6e1fe67 100644 --- a/internal/docs/generated/wasmdocs/docs.go +++ b/internal/docs/generated/wasmdocs/docs.go @@ -18,8 +18,8 @@ Args: The desired path for the wasm file. e.g. /tmp/my-fn.wasm ` var PullExamples = ` - # pull image ghcr.io/my-org/my-fn:v1.0.0 and decompress it to ./my-fn.wasm - $ kpt alpha wasm pull ghcr.io/my-org/my-fn:v1.0.0 ./my-fn.wasm + # pull image gcr.io/my-org/my-fn:v1.0.0 and decompress it to ./my-fn.wasm + $ kpt alpha wasm pull gcr.io/my-org/my-fn:v1.0.0 ./my-fn.wasm ` var PushShort = `Compress a WASM module and push it as an OCI image.` @@ -34,6 +34,6 @@ Args: The desired name of an image. It must be a tag. ` var PushExamples = ` - # compress ./my-fn.wasm and push it to ghcr.io/my-org/my-fn:v1.0.0 - $ kpt alpha wasm push ./my-fn.wasm ghcr.io/my-org/my-fn:v1.0.0 + # compress ./my-fn.wasm and push it to gcr.io/my-org/my-fn:v1.0.0 + $ kpt alpha wasm push ./my-fn.wasm gcr.io/my-org/my-fn:v1.0.0 ` diff --git a/internal/fnruntime/jsglue.go b/internal/fnruntime/jsglue.go index ddbd7a7df3..e95b4ac5ca 100644 --- a/internal/fnruntime/jsglue.go +++ b/internal/fnruntime/jsglue.go @@ -234,7 +234,7 @@ const crypto = require('crypto'); } const timeOrigin = Date.now() - performance.now(); this.importObject = { - gojs: { + go: { // Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters) // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function). @@ -456,8 +456,6 @@ const crypto = require('crypto'); }, } }; - // Expose imports under both "gojs" (Go 1.21+) and "go" (Go <1.21) - this.importObject.go = this.importObject.gojs; } async run(instance) { if (!(instance instanceof WebAssembly.Instance)) { diff --git a/internal/fnruntime/runner_test.go b/internal/fnruntime/runner_test.go index 3c22980e4a..df94f1a837 100644 --- a/internal/fnruntime/runner_test.go +++ b/internal/fnruntime/runner_test.go @@ -20,7 +20,7 @@ import ( "bytes" "context" "os" - "path" + "path/filepath" "strings" "testing" @@ -82,15 +82,17 @@ data: {foo: bar} for _, c := range cases { t.Run(c.name, func(t *testing.T) { + fsys := filesys.MakeFsOnDisk() + pkgPath := os.TempDir() if c.configFileContent != "" { tmp, err := os.CreateTemp("", "kpt-pipeline-*") assert.NoError(t, err, "unexpected error") _, err = tmp.WriteString(c.configFileContent) assert.NoError(t, err, "unexpected error") - c.fn.ConfigPath = path.Base(tmp.Name()) + c.fn.ConfigPath = filepath.Base(tmp.Name()) + pkgPath = filepath.Dir(tmp.Name()) } - fsys := filesys.MakeFsOnDisk() - cn, err := newFnConfig(fsys, &c.fn, types.UniquePath(os.TempDir())) + cn, err := newFnConfig(fsys, &c.fn, types.UniquePath(pkgPath)) assert.NoError(t, err, "unexpected error") actual, err := cn.String() assert.NoError(t, err, "unexpected error") diff --git a/internal/kptops/functions.go b/internal/kptops/functions.go index b7dda286f2..c080753bef 100644 --- a/internal/kptops/functions.go +++ b/internal/kptops/functions.go @@ -19,9 +19,12 @@ import ( ) var functions map[string]framework.ResourceListProcessorFunc = map[string]framework.ResourceListProcessorFunc{ - "ghcr.io/kptdev/krm-functions-catalog/apply-setters:v0.2.0": applySetters, - "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5": setLabels, - "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.4.1": setNamespace, + "ghcr.io/kptdev/krm-functions-catalog/apply-setters:v0.2.0": applySetters, + "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5": setLabels, + "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest": setNamespace, + "ghcr.io/kptdev/krm-functions-catalog/set-labels:latest": setLabels, + "ghcr.io/kptdev/krm-functions-catalog/wasm/set-namespace:v0.5.1": setNamespace, + "ghcr.io/kptdev/krm-functions-catalog/wasm/set-labels:v0.2.0": setLabels, } func FindProcessor(image string) framework.ResourceListProcessorFunc { diff --git a/internal/kptops/set-namespace.go b/internal/kptops/set-namespace.go index 400b8557d9..7f31c941a1 100644 --- a/internal/kptops/set-namespace.go +++ b/internal/kptops/set-namespace.go @@ -16,8 +16,10 @@ package kptops import ( "fmt" + "strings" "sigs.k8s.io/kustomize/kyaml/fn/framework" + "sigs.k8s.io/kustomize/kyaml/yaml" ) // Simple implementation of set-namespace kpt function, primarily for testing. @@ -41,6 +43,9 @@ func setNamespace(rl *framework.ResourceList) error { } for _, n := range rl.Items { + if isUnknown(n) && n.GetNamespace() == "" { + continue + } if err := n.SetNamespace(namespace); err != nil { return err } @@ -48,3 +53,22 @@ func setNamespace(rl *framework.ResourceList) error { return nil } + +func isUnknown(n *yaml.RNode) bool { + apiVersion := n.GetApiVersion() + group := "" + if i := strings.Index(apiVersion, "/"); i != -1 { + group = apiVersion[:i] + } + // Heuristic: standard Kubernetes API groups either have no dots in the group + // name (e.g., "", "apps", "batch", "autoscaling", "extensions", "policy", + // "storage") or end in ".k8s.io" (e.g., "networking.k8s.io"). + // Custom Resources (CRs) have groups with dots that don't end in ".k8s.io" + // (e.g., "custom.io", "stable.example.com"). + if group == "" || !strings.Contains(group, ".") || strings.HasSuffix(group, ".k8s.io") { + return false + } + return true +} + + diff --git a/internal/util/render/executor.go b/internal/util/render/executor.go index eb83469e25..d74ccf4957 100644 --- a/internal/util/render/executor.go +++ b/internal/util/render/executor.go @@ -20,7 +20,6 @@ import ( "io" "os" "path/filepath" - "slices" "strings" "github.com/kptdev/kpt/internal/fnruntime" @@ -35,7 +34,6 @@ import ( "github.com/kptdev/kpt/pkg/lib/errors" "github.com/kptdev/kpt/pkg/lib/runneroptions" "github.com/kptdev/kpt/pkg/printer" - "k8s.io/klog/v2" "sigs.k8s.io/kustomize/kyaml/filesys" "sigs.k8s.io/kustomize/kyaml/kio" "sigs.k8s.io/kustomize/kyaml/kio/kioutil" @@ -111,9 +109,6 @@ func (e *Renderer) Execute(ctx context.Context) (*fnresult.ResultList, error) { _, hydErr := hydrateFn(ctx, root, hctx) if hydErr != nil && !hctx.saveOnRenderFailure { - if e.Output == nil { - updateRenderStatus(hctx, hydErr) - } _ = e.saveFnResults(ctx, hctx.fnResults) return hctx.fnResults, errors.E(op, root.pkg.UniquePath, hydErr) } @@ -178,20 +173,11 @@ func (e *Renderer) Execute(ctx context.Context) (*fnresult.ResultList, error) { } if hydErr != nil { - if e.Output == nil { - updateRenderStatus(hctx, hydErr) - } _ = e.saveFnResults(ctx, hctx.fnResults) // Ignore save error to avoid masking hydration error return hctx.fnResults, errors.E(op, root.pkg.UniquePath, hydErr) } - saveErr := e.saveFnResults(ctx, hctx.fnResults) - - if e.Output == nil { - updateRenderStatus(hctx, saveErr) - } - - return hctx.fnResults, saveErr + return hctx.fnResults, e.saveFnResults(ctx, hctx.fnResults) } func (e *Renderer) printPipelineExecutionSummary(pr printer.Printer, hctx hydrationContext, hydErr error) { @@ -206,47 +192,6 @@ func (e *Renderer) printPipelineExecutionSummary(pr printer.Printer, hctx hydrat } } -// updateRenderStatus writes a Rendered status condition to the root Kptfile. -// On success, the root package gets a True condition. -// On failure, the root package gets a False condition with the error message. -func updateRenderStatus(hctx *hydrationContext, hydErr error) { - if hctx.fileSystem == nil { - return - } - - rootPath := hctx.root.pkg.UniquePath.String() - conditionStatus := kptfilev1.ConditionTrue - reason := kptfilev1.ReasonRenderSuccess - message := "" - if hydErr != nil { - conditionStatus = kptfilev1.ConditionFalse - reason = kptfilev1.ReasonRenderFailed - message = strings.ReplaceAll(hydErr.Error(), rootPath, ".") - } - setRenderCondition(hctx.fileSystem, rootPath, kptfilev1.NewRenderedCondition(conditionStatus, reason, message)) -} - -// setRenderCondition reads the Kptfile at pkgPath, sets the Rendered condition, and writes it back. -func setRenderCondition(fs filesys.FileSystem, pkgPath string, condition kptfilev1.Condition) { - fsOrDisk := filesys.FileSystemOrOnDisk{FileSystem: fs} - kf, err := kptfileutil.ReadKptfile(fsOrDisk, pkgPath) - if err != nil { - klog.V(3).Infof("failed to read Kptfile for render status update at %s: %v", pkgPath, err) - return - } - if kf.Status == nil { - kf.Status = &kptfilev1.Status{} - } - // Replace any existing Rendered condition - kf.Status.Conditions = slices.DeleteFunc(kf.Status.Conditions, func(c kptfilev1.Condition) bool { - return c.Type == kptfilev1.ConditionTypeRendered - }) - kf.Status.Conditions = append(kf.Status.Conditions, condition) - if err := kptfileutil.WriteKptfileToFS(fs, pkgPath, kf); err != nil { - klog.V(3).Infof("failed to write render status condition to Kptfile at %s: %v", pkgPath, err) - } -} - func (e *Renderer) saveFnResults(ctx context.Context, fnResults *fnresult.ResultList) error { e.fnResultsList = fnResults resultsFile, err := fnruntime.SaveResults(e.FileSystem, e.ResultsDirPath, fnResults) diff --git a/internal/util/render/executor_test.go b/internal/util/render/executor_test.go index e09b33bc50..2c8e253f54 100644 --- a/internal/util/render/executor_test.go +++ b/internal/util/render/executor_test.go @@ -25,8 +25,6 @@ import ( "github.com/kptdev/kpt/internal/fnruntime" "github.com/kptdev/kpt/internal/pkg" "github.com/kptdev/kpt/internal/types" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" - "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/printer" "github.com/stretchr/testify/assert" "sigs.k8s.io/kustomize/kyaml/filesys" @@ -34,7 +32,6 @@ import ( ) const rootString = "/root" -const subPkgString = "/root/subpkg" func TestPathRelToRoot(t *testing.T) { tests := []struct { @@ -252,7 +249,7 @@ func setupRendererTest(t *testing.T, renderBfs bool) (*Renderer, *bytes.Buffer, err := mockFileSystem.Mkdir(rootPkgPath) assert.NoError(t, err) - subPkgPath := subPkgString + subPkgPath := "/root/subpkg" err = mockFileSystem.Mkdir(subPkgPath) assert.NoError(t, err) @@ -413,7 +410,7 @@ func TestHydrateBfsOrder_ErrorCases(t *testing.T) { err := mockFileSystem.Mkdir(rootPkgPath) assert.NoError(t, err) - subPkgPath := subPkgString + subPkgPath := "/root/subpkg" err = mockFileSystem.Mkdir(subPkgPath) assert.NoError(t, err) @@ -575,161 +572,6 @@ func TestRenderer_PrintPipelineExecutionSummary(t *testing.T) { } } -func TestUpdateRenderStatus_Success(t *testing.T) { - mockFS := filesys.MakeFsInMemory() - rootPath := rootString - assert.NoError(t, mockFS.Mkdir(rootPath)) - - assert.NoError(t, mockFS.WriteFile(filepath.Join(rootPath, "Kptfile"), []byte(` -apiVersion: kpt.dev/v1 -kind: Kptfile -metadata: - name: root-package -`))) - - rootPkg, err := pkg.New(mockFS, rootPath) - assert.NoError(t, err) - - hctx := &hydrationContext{ - root: &pkgNode{pkg: rootPkg}, - pkgs: map[types.UniquePath]*pkgNode{}, - fileSystem: mockFS, - } - hctx.pkgs[rootPkg.UniquePath] = &pkgNode{pkg: rootPkg} - - updateRenderStatus(hctx, nil) - - rootKf, err := kptfileutil.ReadKptfile(mockFS, rootPath) - assert.NoError(t, err) - assert.NotNil(t, rootKf.Status) - assert.Len(t, rootKf.Status.Conditions, 1) - assert.Equal(t, kptfilev1.ConditionTypeRendered, rootKf.Status.Conditions[0].Type) - assert.Equal(t, kptfilev1.ConditionTrue, rootKf.Status.Conditions[0].Status) - assert.Equal(t, kptfilev1.ReasonRenderSuccess, rootKf.Status.Conditions[0].Reason) -} - -func TestUpdateRenderStatus_Failure(t *testing.T) { - mockFS := filesys.MakeFsInMemory() - rootPath := rootString - assert.NoError(t, mockFS.Mkdir(rootPath)) - - assert.NoError(t, mockFS.WriteFile(filepath.Join(rootPath, "Kptfile"), []byte(` -apiVersion: kpt.dev/v1 -kind: Kptfile -metadata: - name: root-package -`))) - - rootPkg, err := pkg.New(mockFS, rootPath) - assert.NoError(t, err) - - hctx := &hydrationContext{ - root: &pkgNode{pkg: rootPkg}, - pkgs: map[types.UniquePath]*pkgNode{}, - fileSystem: mockFS, - } - hctx.pkgs[rootPkg.UniquePath] = &pkgNode{pkg: rootPkg} - - updateRenderStatus(hctx, fmt.Errorf("set-annotations failed: some error")) - - rootKf, err := kptfileutil.ReadKptfile(mockFS, rootPath) - assert.NoError(t, err) - assert.NotNil(t, rootKf.Status) - assert.Len(t, rootKf.Status.Conditions, 1) - assert.Equal(t, kptfilev1.ConditionFalse, rootKf.Status.Conditions[0].Status) - assert.Equal(t, kptfilev1.ReasonRenderFailed, rootKf.Status.Conditions[0].Reason) - assert.Contains(t, rootKf.Status.Conditions[0].Message, "set-annotations failed") -} - -func TestUpdateRenderStatus_ReplacesExistingCondition(t *testing.T) { - mockFS := filesys.MakeFsInMemory() - rootPath := rootString - assert.NoError(t, mockFS.Mkdir(rootPath)) - - // Kptfile with an existing Rendered condition from a previous run - assert.NoError(t, mockFS.WriteFile(filepath.Join(rootPath, "Kptfile"), []byte(` -apiVersion: kpt.dev/v1 -kind: Kptfile -metadata: - name: root-package -status: - conditions: - - type: Rendered - status: "False" - reason: RenderFailed - message: "old error" -`))) - - rootPkg, err := pkg.New(mockFS, rootPath) - assert.NoError(t, err) - - hctx := &hydrationContext{ - root: &pkgNode{pkg: rootPkg}, - pkgs: map[types.UniquePath]*pkgNode{}, - fileSystem: mockFS, - } - hctx.pkgs[rootPkg.UniquePath] = &pkgNode{pkg: rootPkg} - - updateRenderStatus(hctx, nil) - - rootKf, err := kptfileutil.ReadKptfile(mockFS, rootPath) - assert.NoError(t, err) - assert.NotNil(t, rootKf.Status) - assert.Len(t, rootKf.Status.Conditions, 1) - assert.Equal(t, kptfilev1.ConditionTrue, rootKf.Status.Conditions[0].Status) - assert.Equal(t, kptfilev1.ReasonRenderSuccess, rootKf.Status.Conditions[0].Reason) - assert.Empty(t, rootKf.Status.Conditions[0].Message) -} - -func TestUpdateRenderStatus_OnlyUpdatesRootKptfile(t *testing.T) { - mockFS := filesys.MakeFsInMemory() - rootPath := rootString - assert.NoError(t, mockFS.Mkdir(rootPath)) - - subPkgPath := subPkgString - assert.NoError(t, mockFS.Mkdir(subPkgPath)) - - assert.NoError(t, mockFS.WriteFile(filepath.Join(rootPath, "Kptfile"), []byte(` -apiVersion: kpt.dev/v1 -kind: Kptfile -metadata: - name: root-package -`))) - assert.NoError(t, mockFS.WriteFile(filepath.Join(subPkgPath, "Kptfile"), []byte(` -apiVersion: kpt.dev/v1 -kind: Kptfile -metadata: - name: sub-package -`))) - - rootPkg, err := pkg.New(mockFS, rootPath) - assert.NoError(t, err) - subPkg, err := pkg.New(mockFS, subPkgPath) - assert.NoError(t, err) - - hctx := &hydrationContext{ - root: &pkgNode{pkg: rootPkg}, - pkgs: map[types.UniquePath]*pkgNode{}, - fileSystem: mockFS, - } - hctx.pkgs[rootPkg.UniquePath] = &pkgNode{pkg: rootPkg} - hctx.pkgs[subPkg.UniquePath] = &pkgNode{pkg: subPkg} - - updateRenderStatus(hctx, nil) - - // Root should have the condition - rootKf, err := kptfileutil.ReadKptfile(mockFS, rootPath) - assert.NoError(t, err) - assert.NotNil(t, rootKf.Status) - assert.Len(t, rootKf.Status.Conditions, 1) - assert.Equal(t, kptfilev1.ConditionTrue, rootKf.Status.Conditions[0].Status) - - // Subpackage should NOT have any condition - subKf, err := kptfileutil.ReadKptfile(mockFS, subPkgPath) - assert.NoError(t, err) - assert.True(t, subKf.Status == nil || len(subKf.Status.Conditions) == 0) -} - func TestPkgNode_ClearAnnotationsOnMutFailure(t *testing.T) { tests := []struct { name string diff --git a/pkg/lib/kptops/fs_test.go b/pkg/lib/kptops/fs_test.go index d989f2fe15..5f24ca61eb 100644 --- a/pkg/lib/kptops/fs_test.go +++ b/pkg/lib/kptops/fs_test.go @@ -84,7 +84,6 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom - namespace: staging labels: tier: backend spec: @@ -181,7 +180,6 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom - namespace: staging labels: tier: db spec: diff --git a/pkg/test/runner/runner.go b/pkg/test/runner/runner.go index 6bbb82b76d..4c58b64998 100644 --- a/pkg/test/runner/runner.go +++ b/pkg/test/runner/runner.go @@ -38,11 +38,11 @@ type Runner struct { } func getKptBin() (string, error) { - p, err := exec.Command("which", "kpt").CombinedOutput() + p, err := exec.LookPath("kpt") if err != nil { return "", fmt.Errorf("cannot find command 'kpt' in $PATH: %w", err) } - return strings.TrimSpace(string(p)), nil + return filepath.Abs(p) } const ( diff --git a/pkg/test/runner/util.go b/pkg/test/runner/util.go index 39af18d537..60e7a649ed 100644 --- a/pkg/test/runner/util.go +++ b/pkg/test/runner/util.go @@ -21,6 +21,8 @@ import ( "os/exec" "path/filepath" "strings" + + otiai10copy "github.com/otiai10/copy" ) func runCommand(cmd *exec.Cmd) (string, string, error) { @@ -39,8 +41,7 @@ func getCommand(pwd, name string, arg []string) *exec.Cmd { } func copyDir(src, dst string) error { - _, _, err := runCommand(getCommand("", "cp", []string{"-r", src, dst})) - return err + return otiai10copy.Copy(src, dst) } func gitInit(d string) error {