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/.github/workflows/go.yml b/.github/workflows/go.yml index 353e866689..979d3d89ee 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -58,6 +58,9 @@ jobs: with: go-version-file: go/src/github.com/kptdev/kpt/go.mod cache: true + cache-dependency-path: | + go/src/github.com/kptdev/kpt/go.sum + go/src/github.com/kptdev/kpt/go.mod - name: Build, Test, Lint working-directory: ${{ env.GOPATH }}/src/github.com/kptdev/kpt run: | @@ -80,6 +83,9 @@ jobs: with: go-version-file: go/src/github.com/kptdev/kpt/go.mod cache: true + cache-dependency-path: | + go/src/github.com/kptdev/kpt/go.sum + go/src/github.com/kptdev/kpt/go.mod - name: Build working-directory: ${{ env.GOPATH }}/src/github.com/kptdev/kpt run: | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6dc19ecf3c..511a9f5697 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -57,14 +57,6 @@ All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. Consult [GitHub Help] for more information on using pull requests. -Process for code reviews. Before requesting human review, a PR must: - -* All tests passing -* All linting passing -* Meeting project code quality requirements, including passing all configured static analysis / SonarCloud quality gates and not reducing automated test coverage for the affected components -* The comments from the first run of automatically generated comments (AI generated comments, SonarCloud comments, bot generated comments, etc.) of the PR are addressed (addressing further re-runs of AI are optional) -* If it is not possible to resolve an automatic comment, please add a sub-comment indicating why the automated comment cannot be resolved or ask for help in resolving the comment - ## Community Guidelines This project follows a [Code of Conduct]. @@ -134,7 +126,7 @@ It's usually a good idea to test locally for the following: #### Update docs -Docs are under [documentation/](documentation/). Refer to the [README.md](documentation/README.md) in the folder for details about +Docs are under [documentation/]. Refer to (the README,md)[documentation/README.md] in the folder to details about documentation contributions. 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 7d2838c497..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,51 +1,92 @@ diff --git a/Kptfile b/Kptfile -index 3c93e9e..5404a5a 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,16 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 ++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 @@ @@ -75,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 e1c701ed7b..51852137e3 100644 --- a/e2e/testdata/fn-render/basicpipeline-semver/.expected/diff.patch +++ b/e2e/testdata/fn-render/basicpipeline-semver/.expected/diff.patch @@ -1,66 +1,100 @@ diff --git a/Kptfile b/Kptfile -index 2336da4..ca2bcea 100644 +index 68ea4fc..85f42f5 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,13 +2,34 @@ 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 -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.4.3 -+ exitCode: 0 -+ results: -+ - message: namespace [default] updated to "staging", 1 value(s) changed -+ severity: info -+ - message: all `depends-on` annotations are up-to-date. no `namespace` changed -+ severity: info -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.2.4 -+ exitCode: 0 -+ results: -+ - message: set 4 labels in total -+ severity: info +- 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 114ed718fa..44ed6cfcfb 100644 --- a/e2e/testdata/fn-render/basicpipeline-symlink/.expected/diff.patch +++ b/e2e/testdata/fn-render/basicpipeline-symlink/.expected/diff.patch @@ -1,5 +1,9 @@ diff --git a/Kptfile b/Kptfile +<<<<<<< HEAD +index 1307fb5..3a2c718 100644 +======= index 1307fb5..fee64dc 100644 +>>>>>>> origin/main --- a/Kptfile +++ b/Kptfile @@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 @@ -12,6 +16,8 @@ index 1307fb5..fee64dc 100644 pipeline: mutators: - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +<<<<<<< HEAD +======= @@ -10,3 +13,14 @@ pipeline: - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 configMap: @@ -27,6 +33,7 @@ index 1307fb5..fee64dc 100644 + exitCode: 0 + - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 + exitCode: 0 +>>>>>>> origin/main 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 19a2818f6c..d964fe8822 100644 --- a/e2e/testdata/fn-render/basicpipeline-wasm/.expected/diff.patch +++ b/e2e/testdata/fn-render/basicpipeline-wasm/.expected/diff.patch @@ -1,35 +1,8 @@ -diff --git a/Kptfile b/Kptfile -index 17a7822..98fa855 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -12,3 +12,22 @@ 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 -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/wasm/set-namespace:v0.5.1 -+ exitCode: 0 -+ results: -+ - message: namespace [default] updated to "staging", 1 value(s) changed -+ severity: info -+ - message: all `depends-on` annotations are up-to-date. no `namespace` changed -+ severity: info -+ - image: ghcr.io/kptdev/krm-functions-catalog/wasm/set-labels:v0.2.4 -+ exitCode: 0 -+ results: -+ - message: set 4 labels in total -+ severity: info 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 @@ -38,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/.expected/diff.patch b/e2e/testdata/fn-render/basicpipeline/.expected/diff.patch index 114ed718fa..679e31b313 100644 --- a/e2e/testdata/fn-render/basicpipeline/.expected/diff.patch +++ b/e2e/testdata/fn-render/basicpipeline/.expected/diff.patch @@ -1,37 +1,21 @@ diff --git a/Kptfile b/Kptfile -index 1307fb5..fee64dc 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,14 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 + - 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 @@ -40,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 114ed718fa..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..fee64dc 100644 +index 1307fb5..3a2c718 100644 --- a/Kptfile +++ b/Kptfile @@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 @@ -12,21 +12,6 @@ index 1307fb5..fee64dc 100644 pipeline: mutators: - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -@@ -10,3 +13,14 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 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 99cec3474c..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,44 +1,3 @@ -diff --git a/Kptfile b/Kptfile -index 6f2fe11..c0c66f5 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -4,4 +4,35 @@ 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 -+ renderStatus: -+ mutationSteps: -+ - exec: ./testdata/fn-render/exec-function-stderr/function.sh -+ stderr: | -+ Hello world 0! -+ Hello world 1! -+ Hello world 2! -+ Hello world 3! -+ Hello world 4! -+ Hello world 5! -+ Hello world 6! -+ Hello world 7! -+ Hello world 8! -+ Hello world 9! -+ Hello world 10! -+ Hello world 11! -+ Hello world 12! -+ Hello world 13! -+ Hello world 14! -+ Hello world 15! -+ Hello world 16! -+ Hello world 17! -+ Hello world 18! -+ Hello world 19! -+ Hello world 20! -+ exitCode: 0 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 04bdc6d2ec..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,40 +1,80 @@ diff --git a/Kptfile b/Kptfile -index 0d98dbb..2f7e1c4 100644 +index 5628a13..23bd061 100644 --- a/Kptfile +++ b/Kptfile -@@ -4,4 +4,13 @@ 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 -+ renderStatus: -+ mutationSteps: -+ - exec: sed -e 's/foo/bar/' -+ exitCode: 0 ++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 2c13164fa5..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,18 +1,123 @@ diff --git a/Kptfile b/Kptfile -index f591880..1a3d92d 100644 +index ff38bf9..f591880 100644 --- a/Kptfile +++ b/Kptfile -@@ -6,3 +6,13 @@ pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: function succeeded, reporting it on stderr -+ exitCode: 0 +@@ -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 6d24d30dcf..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,39 +1,13 @@ -diff --git a/Kptfile b/Kptfile -index dbab15c..3eab648 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -2,8 +2,20 @@ 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 -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 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 @@ -51,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 @@ -63,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 @@ -82,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 55da6d2f41..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..f4fdf26 100644 +index 0bfdbb0..69acc11 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,7 +2,18 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: app-with-db @@ -11,16 +11,6 @@ index 0bfdbb0..f4fdf26 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 -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 diff --git a/db/labelconfig.yaml b/db/labelconfig.yaml index 22d2de2..19e0746 100644 --- a/db/labelconfig.yaml @@ -34,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 @@ -45,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 d6a1725cb7..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..d0bbc91 100644 +index c2cf3ba..81422f3 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,7 +2,18 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: app-with-db @@ -11,16 +11,6 @@ index c2cf3ba..d0bbc91 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 -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 diff --git a/confs/labelconfig.yaml b/confs/labelconfig.yaml index 22d2de2..19e0746 100644 --- a/confs/labelconfig.yaml @@ -34,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 @@ -45,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 d67f7198e0..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,111 +1,200 @@ diff --git a/Kptfile b/Kptfile -index 950565f..d9be19c 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,19 @@ 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 -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.4.1 -+ exitCode: 0 -+ results: -+ - message: namespace "example" updated to "frontend", 2 value(s) changed -+ severity: info -+ - image: ghcr.io/kptdev/krm-functions-catalog/apply-replacements:latest -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 ++ 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 84130da1fc..7d763462fc 100644 --- a/e2e/testdata/fn-render/fnconfig/.expected/diff.patch +++ b/e2e/testdata/fn-render/fnconfig/.expected/diff.patch @@ -1,56 +1,35 @@ diff --git a/Kptfile b/Kptfile -index 043dcac..58ddc42 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,18 @@ 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 -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 + - 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 @@ -60,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 @@ -83,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 @@ -95,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 1b9752610b..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,36 +1,125 @@ diff --git a/Kptfile b/Kptfile -index 3c63ab9..775911c 100644 +index cb38e78..3c63ab9 100644 --- a/Kptfile +++ b/Kptfile -@@ -6,3 +6,18 @@ 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 -+ renderStatus: -+ mutationSteps: -+ - 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 +@@ -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 100644 --- 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 998b5cf90b..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,40 +1,3 @@ -diff --git a/Kptfile b/Kptfile -index dbab15c..3ab935c 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -2,8 +2,20 @@ 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 -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -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 451e75f312..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,20 +1,24 @@ diff --git a/Kptfile b/Kptfile -index 714d078..84b97ca 100644 +index ab9d7ec..714d078 100644 --- a/Kptfile +++ b/Kptfile -@@ -6,3 +6,12 @@ pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-httpbin.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ exitCode: 0 +@@ -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 @@ -34,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 93843baaf1..0dda46d207 100644 --- a/e2e/testdata/fn-render/generator/.expected/diff.patch +++ b/e2e/testdata/fn-render/generator/.expected/diff.patch @@ -1,53 +1,70 @@ diff --git a/Kptfile b/Kptfile -index 8050168..a201e2b 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,20 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: db -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 ++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 @@ -80,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 @@ -103,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 @@ -137,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 3c45e99dc8..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..30b4376 100644 +index 2985a1a..3dfdcf6 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,8 +2,19 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: app @@ -11,17 +11,6 @@ index 2985a1a..30b4376 100644 pipeline: mutators: - image: set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 diff --git a/kustomization.yaml b/kustomization.yaml index f3f0207..6c517af 100644 --- a/kustomization.yaml @@ -38,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 @@ -49,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/.expected/diff.patch b/e2e/testdata/fn-render/missing-fn-image/.expected/diff.patch index c772c52649..b34b260136 100644 --- a/e2e/testdata/fn-render/missing-fn-image/.expected/diff.patch +++ b/e2e/testdata/fn-render/missing-fn-image/.expected/diff.patch @@ -1,5 +1,5 @@ diff --git a/Kptfile b/Kptfile -index 11012de..a0f4634 100644 +index 11012de..9fadb6e 100644 --- a/Kptfile +++ b/Kptfile @@ -7,6 +7,26 @@ pipeline: @@ -22,11 +22,11 @@ index 11012de..a0f4634 100644 + mutationSteps: + - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 + exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/dne:latest ++ - image: ghcr.io/kptdev/krm-functions-catalog/dne + stderr: |- + docker: Error response from daemon: error from registry: denied + denied + + Run 'docker run --help' for more information + exitCode: 125 -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/dne:latest: exit code 125' ++ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/dne: exit code 125' 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 47f2a43559..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,25 +1,118 @@ diff --git a/Kptfile b/Kptfile -index 5d377d4..4c721ab 100644 +index b83e710..5d377d4 100644 --- a/Kptfile +++ b/Kptfile -@@ -4,5 +4,14 @@ 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 -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ exitCode: 0 ++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 8c70da6113..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,37 +1,117 @@ diff --git a/Kptfile b/Kptfile -index 5d377d4..4c721ab 100644 +index b83e710..5d377d4 100644 --- a/Kptfile +++ b/Kptfile -@@ -4,5 +4,14 @@ 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 -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ exitCode: 0 ++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 1edd0d8e8c..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,42 +1,134 @@ diff --git a/Kptfile b/Kptfile -index 894ad57..2b9cbb7 100644 +index e3ad4cc..894ad57 100644 --- a/Kptfile +++ b/Kptfile -@@ -6,3 +6,12 @@ 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 -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ exitCode: 0 +@@ -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 @@ -44,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 1edd0d8e8c..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,42 +1,134 @@ diff --git a/Kptfile b/Kptfile -index 894ad57..2b9cbb7 100644 +index e3ad4cc..894ad57 100644 --- a/Kptfile +++ b/Kptfile -@@ -6,3 +6,12 @@ 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 -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ exitCode: 0 +@@ -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 @@ -44,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 e2651c15a5..ac9da91b90 100644 --- a/e2e/testdata/fn-render/no-fnconfig/.expected/diff.patch +++ b/e2e/testdata/fn-render/no-fnconfig/.expected/diff.patch @@ -1,30 +1,12 @@ -diff --git a/Kptfile b/Kptfile -index f2d1249..6772376 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -8,3 +8,25 @@ 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 -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ stderr: '[error] : failed to configure function: `functionConfig` must be either a `ConfigMap` or `SetLabels`' -+ exitCode: 1 -+ results: -+ - message: 'failed to configure function: `functionConfig` must be either a `ConfigMap` or `SetLabels`' -+ severity: error -+ errorResults: -+ - message: 'failed to configure function: `functionConfig` must be either a `ConfigMap` or `SetLabels`' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5: exit code 1' +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 36cb50a2e7..7f48e6c0e2 100644 --- a/e2e/testdata/fn-render/no-op/.expected/diff.patch +++ b/e2e/testdata/fn-render/no-op/.expected/diff.patch @@ -1,17 +1,188 @@ diff --git a/Kptfile b/Kptfile -index a7a2d0b..3dbfee4 100644 +index 1e0e356..a7a2d0b 100644 --- a/Kptfile +++ b/Kptfile -@@ -5,3 +5,12 @@ metadata: - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/no-op -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/no-op:latest -+ exitCode: 0 +@@ -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 abdd0e61c8..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,48 +1,31 @@ diff --git a/Kptfile b/Kptfile -index 1307fb5..fee64dc 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,14 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 + - 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 @@ -51,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 89078f13a1..8968363a2d 100644 --- a/e2e/testdata/fn-render/no-resources/.expected/diff.patch +++ b/e2e/testdata/fn-render/no-resources/.expected/diff.patch @@ -1,20 +1,24 @@ diff --git a/Kptfile b/Kptfile -index 714d078..84b97ca 100644 +index ab9d7ec..714d078 100644 --- a/Kptfile +++ b/Kptfile -@@ -6,3 +6,12 @@ pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-httpbin.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ exitCode: 0 +@@ -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 @@ -48,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 23c1ab2538..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,20 +1,24 @@ diff --git a/Kptfile b/Kptfile -index 0f5d7db..3ac3611 100644 +index 9033153..0f5d7db 100644 --- a/Kptfile +++ b/Kptfile -@@ -6,3 +6,12 @@ pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-httpbin-gen.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ exitCode: 0 +@@ -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 @@ -34,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 73b4916a12..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,20 +1,37 @@ diff --git a/Kptfile b/Kptfile -index 0f5d7db..3ac3611 100644 +index 9033153..0f5d7db 100644 --- a/Kptfile +++ b/Kptfile -@@ -6,3 +6,12 @@ pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-httpbin-gen.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ exitCode: 0 +@@ -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 @@ -34,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 10a702f706..a76fde8ceb 100644 --- a/e2e/testdata/fn-render/preserve-comments/.expected/diff.patch +++ b/e2e/testdata/fn-render/preserve-comments/.expected/diff.patch @@ -1,17 +1,158 @@ diff --git a/Kptfile b/Kptfile -index 828d292..7502f3c 100644 +index 7b85c09..828d292 100644 --- a/Kptfile +++ b/Kptfile -@@ -5,3 +5,12 @@ metadata: - pipeline: - mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/drop-comments:v0.1 -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/drop-comments:v0.1 -+ exitCode: 0 +@@ -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 7d2dc06add..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,37 +1,21 @@ diff --git a/Kptfile b/Kptfile -index 1307fb5..fee64dc 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,14 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 + - 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 @@ -40,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 04b6c91dd9..802d7faa29 100644 --- a/e2e/testdata/fn-render/resource-deletion/.expected/diff.patch +++ b/e2e/testdata/fn-render/resource-deletion/.expected/diff.patch @@ -1,37 +1,41 @@ diff --git a/Kptfile b/Kptfile -index 364e274..f17e769 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,16 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 ++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 @@ @@ -72,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 @@ -91,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 0b6b2bfd84..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,199 +1,399 @@ diff --git a/Kptfile b/Kptfile -index 21d9773..da35b9b 100644 +index e2f4e83..66b7fc9 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,8 +2,102 @@ 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 -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:latest -+ exitCode: 0 -+ results: -+ - message: 'set annotations: {"foo":"bar"}' -+ field: -+ path: metadata.annotations -+ file: -+ path: Kptfile -+ - message: 'set annotations: {"foo":"bar"}' -+ field: -+ path: metadata.annotations -+ file: -+ path: mysql-deployment.yaml -+ - message: 'set annotations: {"foo":"bar"}' -+ field: -+ path: metadata.annotations -+ file: -+ path: mysql-deployment.yaml -+ index: 1 -+ - message: 'set annotations: {"foo":"bar"}' -+ field: -+ path: metadata.annotations -+ file: -+ path: mysql-deployment.yaml -+ index: 2 -+ - message: 'set annotations: {"foo":"bar"}' -+ field: -+ path: spec.template.metadata.annotations -+ file: -+ path: mysql-deployment.yaml -+ index: 2 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:latest -+ exitCode: 0 -+ results: -+ - message: 'set annotations: {"abc":"def"}' -+ field: -+ path: metadata.annotations -+ file: -+ path: Kptfile -+ - message: 'set annotations: {"abc":"def"}' -+ field: -+ path: metadata.annotations -+ file: -+ path: mysql-deployment.yaml -+ - message: 'set annotations: {"abc":"def"}' -+ field: -+ path: metadata.annotations -+ file: -+ path: mysql-deployment.yaml -+ index: 1 -+ - message: 'set annotations: {"abc":"def"}' -+ field: -+ path: metadata.annotations -+ file: -+ path: mysql-deployment.yaml -+ index: 2 -+ - message: 'set annotations: {"abc":"def"}' -+ field: -+ path: spec.template.metadata.annotations -+ file: -+ path: mysql-deployment.yaml -+ index: 2 -+ - message: 'set annotations: {"abc":"def"}' -+ field: -+ path: metadata.annotations -+ file: -+ path: wordpress-deployment.yaml -+ - message: 'set annotations: {"abc":"def"}' -+ field: -+ path: metadata.annotations -+ file: -+ path: wordpress-deployment.yaml -+ index: 1 -+ - message: 'set annotations: {"abc":"def"}' -+ field: -+ path: metadata.annotations -+ file: -+ path: wordpress-deployment.yaml -+ index: 2 -+ - message: 'set annotations: {"abc":"def"}' -+ field: -+ path: spec.template.metadata.annotations -+ file: -+ path: wordpress-deployment.yaml -+ index: 2 ++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/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/bfs-basicpipeline/.expected/config.yaml index f6237512ca..2eba311bad 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-basicpipeline/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-basicpipeline/.expected/config.yaml @@ -1 +1,2 @@ exitCode: 1 +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 402f36c76f..e9382ce252 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,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index 8e0454e..f230a89 100644 +index ec2c042..50c2a18 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,18 +1,43 @@ +@@ -1,18 +1,28 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: @@ -21,17 +21,18 @@ index 8e0454e..f230a89 100644 - - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 - configMap: - app: myapp -- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -- configPath: starlark-fn-failure.yaml -- +- - 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: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ configPath: starlark-fn-failure.yaml ++ - image: invalid-image:v0.0.0 ++ configMap: ++ tier: backend +status: + conditions: + - type: Rendered @@ -40,22 +41,6 @@ index 8e0454e..f230a89 100644 + message: |- + pkg.render: pkg .: + pipeline.run: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: 'failed to evaluate function: error: function failure' -+ exitCode: 1 -+ results: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorResults: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/starlark:latest: exit code 1' diff --git a/resources.yaml b/resources.yaml index 0848ba0..7eece9b 100644 --- a/resources.yaml @@ -73,17 +58,3 @@ index 0848ba0..7eece9b 100644 + metadata: + annotations: + app: myapp -diff --git a/starlark-fn-failure.yaml b/starlark-fn-failure.yaml -index 55ceaae..d2841c7 100644 ---- a/starlark-fn-failure.yaml -+++ b/starlark-fn-failure.yaml -@@ -2,6 +2,9 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: always-fail -+ annotations: -+ app: myapp -+ namespace: staging - source: | - def fail_fn(items): - fail("intentional failure for testing") 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 8e0454e8d8..ec2c042dc7 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 @@ -13,6 +13,6 @@ pipeline: - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 configMap: app: myapp - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml - + - image: invalid-image:v0.0.0 + configMap: + tier: backend diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-deep-nested-middle-fails/.expected/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/bfs-deep-nested-middle-fails/.expected/config.yaml index f6237512ca..2eba311bad 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-deep-nested-middle-fails/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-deep-nested-middle-fails/.expected/config.yaml @@ -1 +1,2 @@ exitCode: 1 +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 fbcacec6b2..0544ac3be1 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,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index dbd6541..ad87335 100644 +index dbd6541..915dd4b 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,14 +1,41 @@ +@@ -1,14 +1,24 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: @@ -29,23 +29,6 @@ index dbd6541..ad87335 100644 + message: |- + pkg.render: pkg .: + pipeline.run: pkg ./level1: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ validationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: 'failed to evaluate function: error: function failure' -+ exitCode: 1 -+ results: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorResults: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/starlark:latest: exit code 1' diff --git a/configmap.yaml b/configmap.yaml index 59bb817..19a7ead 100644 --- a/configmap.yaml @@ -59,7 +42,7 @@ index 59bb817..19a7ead 100644 data: level: root diff --git a/level1/Kptfile b/level1/Kptfile -index 2bc48be..ec5f5a7 100644 +index b5960dd..b42f153 100644 --- a/level1/Kptfile +++ b/level1/Kptfile @@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 @@ -113,16 +96,3 @@ index ab7d3fa..1eeeaed 100644 + level: level1 data: level: level2 -diff --git a/level1/starlark-fn-failure.yaml b/level1/starlark-fn-failure.yaml -index 55ceaae..34c320f 100644 ---- a/level1/starlark-fn-failure.yaml -+++ b/level1/starlark-fn-failure.yaml -@@ -2,6 +2,8 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: always-fail -+ labels: -+ level: level1 - source: | - def fail_fn(items): - fail("intentional failure for testing") diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-deep-nested-middle-fails/level1/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/bfs-deep-nested-middle-fails/level1/Kptfile index 2bc48be98e..b5960dd7a7 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-deep-nested-middle-fails/level1/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-deep-nested-middle-fails/level1/Kptfile @@ -10,5 +10,4 @@ pipeline: configMap: level: level1 validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-multiple-subpkgs-one-fails/.expected/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/bfs-multiple-subpkgs-one-fails/.expected/config.yaml index f6237512ca..2eba311bad 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-multiple-subpkgs-one-fails/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-multiple-subpkgs-one-fails/.expected/config.yaml @@ -1 +1,2 @@ exitCode: 1 +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 425955484a..8ddd89fefa 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,5 +1,5 @@ diff --git a/Kptfile b/Kptfile -index e9fad85..b0d2fb6 100644 +index e9fad85..48186b1 100644 --- a/Kptfile +++ b/Kptfile @@ -1,10 +1,12 @@ @@ -16,7 +16,7 @@ index e9fad85..b0d2fb6 100644 info: description: BFS - Multiple subpackages, sub2 fails pipeline: -@@ -12,3 +14,30 @@ pipeline: +@@ -12,3 +14,11 @@ pipeline: - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 configMap: pkg: root @@ -28,25 +28,6 @@ index e9fad85..b0d2fb6 100644 + message: |- + pkg.render: pkg .: + pipeline.run: pkg ./sub2: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ validationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: 'failed to evaluate function: error: function failure' -+ exitCode: 1 -+ results: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorResults: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/starlark:latest: exit code 1' diff --git a/service.yaml b/service.yaml index 9148b9b..2e551c8 100644 --- a/service.yaml @@ -95,7 +76,7 @@ index 2f649ba..c2245a9 100644 + labels: + pkg: sub1 diff --git a/sub2/Kptfile b/sub2/Kptfile -index 853d3f0..89cfa33 100644 +index 792277c..6412843 100644 --- a/sub2/Kptfile +++ b/sub2/Kptfile @@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 @@ -126,19 +107,6 @@ index 20375ea..7290360 100644 + metadata: + labels: + pkg: sub2 -diff --git a/sub2/starlark-fn-failure.yaml b/sub2/starlark-fn-failure.yaml -index 55ceaae..5b9cf38 100644 ---- a/sub2/starlark-fn-failure.yaml -+++ b/sub2/starlark-fn-failure.yaml -@@ -2,6 +2,8 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: always-fail -+ labels: -+ pkg: sub2 - source: | - def fail_fn(items): - fail("intentional failure for testing") diff --git a/sub3/Kptfile b/sub3/Kptfile index ff35b98..958a351 100644 --- a/sub3/Kptfile diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-multiple-subpkgs-one-fails/sub2/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/bfs-multiple-subpkgs-one-fails/sub2/Kptfile index 853d3f0df5..792277c2b0 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-multiple-subpkgs-one-fails/sub2/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-multiple-subpkgs-one-fails/sub2/Kptfile @@ -8,5 +8,4 @@ pipeline: configMap: pkg: sub2 validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-and-subpkg-both-fail/.expected/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-and-subpkg-both-fail/.expected/config.yaml index f6237512ca..2eba311bad 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-and-subpkg-both-fail/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-and-subpkg-both-fail/.expected/config.yaml @@ -1 +1,2 @@ exitCode: 1 +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 3512029e33..e5e2e83e81 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,12 +1,14 @@ diff --git a/Kptfile b/Kptfile -index 867a54b..6ccc3b8 100644 +index cbe756f..8ce300c 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,10 +1,10 @@ +@@ -1,10 +1,12 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: + name: bfs-parent-and-subpkg-both-fail ++ labels: ++ pkg: root annotations: kpt.dev/bfs-rendering: "true" kpt.dev/save-on-render-failure: "true" @@ -14,10 +16,10 @@ index 867a54b..6ccc3b8 100644 info: description: BFS - Both parent and subpackage fail pipeline: -@@ -15,3 +15,23 @@ pipeline: +@@ -14,3 +16,11 @@ pipeline: + pkg: root validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 +status: + conditions: + - type: Rendered @@ -26,15 +28,43 @@ index 867a54b..6ccc3b8 100644 + message: |- + pkg.render: pkg .: + pipeline.run: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ stderr: '[error] : failed to run function: may not add resource with an already registered id: fn.kpt.dev_v1alpha1_StarlarkRun|~X|always-fail' -+ exitCode: 1 -+ results: -+ - message: 'failed to run function: may not add resource with an already registered id: fn.kpt.dev_v1alpha1_StarlarkRun|~X|always-fail' -+ severity: error -+ errorResults: -+ - message: 'failed to run function: may not add resource with an already registered id: fn.kpt.dev_v1alpha1_StarlarkRun|~X|always-fail' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5: exit code 1' +diff --git a/configmap.yaml b/configmap.yaml +index 8594873..a591ceb 100644 +--- a/configmap.yaml ++++ b/configmap.yaml +@@ -2,5 +2,7 @@ apiVersion: v1 + kind: ConfigMap + metadata: + name: root-config ++ labels: ++ pkg: root + data: + pkg: root +diff --git a/subpkg/Kptfile b/subpkg/Kptfile +index a332cf5..2a3f05c 100644 +--- a/subpkg/Kptfile ++++ b/subpkg/Kptfile +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 + kind: Kptfile + metadata: + name: subpkg ++ labels: ++ pkg: root + info: + description: Subpackage that also fails + pipeline: +diff --git a/subpkg/service.yaml b/subpkg/service.yaml +index 276bf9e..d6424da 100644 +--- a/subpkg/service.yaml ++++ b/subpkg/service.yaml +@@ -2,6 +2,10 @@ apiVersion: v1 + kind: Service + metadata: + name: sub-service ++ labels: ++ pkg: root + spec: + ports: + - port: 80 ++ selector: ++ pkg: root diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-and-subpkg-both-fail/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-and-subpkg-both-fail/Kptfile index 867a54b0af..cbe756f987 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-and-subpkg-both-fail/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-and-subpkg-both-fail/Kptfile @@ -13,5 +13,4 @@ pipeline: configMap: pkg: root validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-and-subpkg-both-fail/subpkg/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-and-subpkg-both-fail/subpkg/Kptfile index 492902c112..a332cf57ab 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-and-subpkg-both-fail/subpkg/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-and-subpkg-both-fail/subpkg/Kptfile @@ -10,5 +10,4 @@ pipeline: configMap: pkg: subpkg validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-mutator-fails/.expected/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-mutator-fails/.expected/config.yaml index f6237512ca..2eba311bad 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-mutator-fails/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-mutator-fails/.expected/config.yaml @@ -1 +1,2 @@ exitCode: 1 +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 54fb5dc5f4..f7cc0a511a 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,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index 2c67980..0e92246 100644 +index c80b904..d0bc053 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,16 +1,40 @@ +@@ -1,15 +1,25 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: @@ -21,8 +21,7 @@ index 2c67980..0e92246 100644 configMap: - test: "parent-mutator-fail" + test: parent-mutator-fail - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 +status: + conditions: + - type: Rendered @@ -31,20 +30,6 @@ index 2c67980..0e92246 100644 + message: |- + pkg.render: pkg .: + pipeline.run: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: 'failed to evaluate function: error: function failure' -+ exitCode: 1 -+ results: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorResults: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/starlark:latest: exit code 1' diff --git a/configmap.yaml b/configmap.yaml index 20a54f6..a46a12b 100644 --- a/configmap.yaml @@ -57,19 +42,6 @@ index 20a54f6..a46a12b 100644 + test: parent-mutator-fail data: key: value -diff --git a/starlark-fn-failure.yaml b/starlark-fn-failure.yaml -index 55ceaae..f589633 100644 ---- a/starlark-fn-failure.yaml -+++ b/starlark-fn-failure.yaml -@@ -2,6 +2,8 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: always-fail -+ labels: -+ test: parent-mutator-fail - source: | - def fail_fn(items): - fail("intentional failure for testing") diff --git a/subpkg/Kptfile b/subpkg/Kptfile index e940ae8..e6e678c 100644 --- a/subpkg/Kptfile diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-mutator-fails/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-mutator-fails/Kptfile index 2c679804e2..c80b904236 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-mutator-fails/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-mutator-fails/Kptfile @@ -12,5 +12,4 @@ pipeline: - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 configMap: test: "parent-mutator-fail" - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-validator-fails/.expected/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-validator-fails/.expected/config.yaml index f6237512ca..2eba311bad 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-validator-fails/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-validator-fails/.expected/config.yaml @@ -1 +1,2 @@ exitCode: 1 +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 eeb2047bf0..77a376f85e 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,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index 17ef3d8..93810be 100644 +index 491b12e..28e400c 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,17 +1,42 @@ +@@ -1,16 +1,26 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: @@ -22,8 +22,7 @@ index 17ef3d8..93810be 100644 - test: "parent-fail" + test: parent-fail validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 +status: + conditions: + - type: Rendered @@ -32,21 +31,6 @@ index 17ef3d8..93810be 100644 + message: |- + pkg.render: pkg .: + pipeline.run: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ validationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: 'failed to evaluate function: error: function failure' -+ exitCode: 1 -+ results: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorResults: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/starlark:latest: exit code 1' diff --git a/configmap.yaml b/configmap.yaml index 20a54f6..ad595de 100644 --- a/configmap.yaml @@ -59,19 +43,6 @@ index 20a54f6..ad595de 100644 + test: parent-fail data: key: value -diff --git a/starlark-fn-failure.yaml b/starlark-fn-failure.yaml -index 55ceaae..eb4b975 100644 ---- a/starlark-fn-failure.yaml -+++ b/starlark-fn-failure.yaml -@@ -2,6 +2,8 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: always-fail -+ labels: -+ test: parent-fail - source: | - def fail_fn(items): - fail("intentional failure for testing") diff --git a/subpkg/Kptfile b/subpkg/Kptfile index e940ae8..88a8d4e 100644 --- a/subpkg/Kptfile diff --git a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-validator-fails/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-validator-fails/Kptfile index 17ef3d8c51..491b12e732 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-validator-fails/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-parent-validator-fails/Kptfile @@ -13,5 +13,4 @@ pipeline: configMap: test: "parent-fail" validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - 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-mutator-fails/.expected/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-mutator-fails/.expected/config.yaml index f6237512ca..2eba311bad 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-mutator-fails/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-mutator-fails/.expected/config.yaml @@ -1 +1,2 @@ exitCode: 1 +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 4d85263c73..b4d487a414 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,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index 84b93a6..f9f5122 100644 +index 84b93a6..4ae9f17 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,14 +1,40 @@ +@@ -1,14 +1,24 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: @@ -29,22 +29,6 @@ index 84b93a6..f9f5122 100644 + message: |- + pkg.render: pkg .: + pipeline.run: pkg ./subpkg: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: 'failed to evaluate function: error: function failure' -+ exitCode: 1 -+ results: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorResults: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/starlark:latest: exit code 1' diff --git a/deployment.yaml b/deployment.yaml index cc866f6..6ed4201 100644 --- a/deployment.yaml @@ -65,7 +49,7 @@ index cc866f6..6ed4201 100644 + labels: + test: mutator-fail diff --git a/subpkg/Kptfile b/subpkg/Kptfile -index 7b4318a..5b35311 100644 +index ec4ce38..82fcf74 100644 --- a/subpkg/Kptfile +++ b/subpkg/Kptfile @@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1 @@ -98,17 +82,3 @@ index 302322e..546fe5c 100644 + metadata: + labels: + test: mutator-fail -diff --git a/subpkg/starlark-fn-failure.yaml b/subpkg/starlark-fn-failure.yaml -index 55ceaae..026f2e5 100644 ---- a/subpkg/starlark-fn-failure.yaml -+++ b/subpkg/starlark-fn-failure.yaml -@@ -2,6 +2,9 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: always-fail -+ labels: -+ test: mutator-fail -+ namespace: subpkg-ns - source: | - def fail_fn(items): - fail("intentional failure for testing") 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 7b4318a971..ec4ce38547 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 @@ -9,5 +9,4 @@ pipeline: - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 configMap: namespace: subpkg-ns - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - 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/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-validator-fails/.expected/config.yaml index f6237512ca..2eba311bad 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-validator-fails/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/bfs-subpkg-validator-fails/.expected/config.yaml @@ -1 +1,2 @@ exitCode: 1 +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 798c6c5f7a..18a748ab0c 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,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index 86dbe13..755cbd3 100644 +index 86dbe13..f0c67c4 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,15 +1,43 @@ +@@ -1,15 +1,26 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: @@ -32,23 +32,6 @@ index 86dbe13..755cbd3 100644 + message: |- + pkg.render: pkg .: + pipeline.run: pkg ./subpkg: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ validationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: 'failed to evaluate function: error: function failure' -+ exitCode: 1 -+ results: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorResults: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/starlark:latest: exit code 1' diff --git a/deployment.yaml b/deployment.yaml index 7123634..4db6211 100644 --- a/deployment.yaml @@ -72,7 +55,7 @@ index 7123634..4db6211 100644 + level: root + test: subpkg-fail diff --git a/subpkg/Kptfile b/subpkg/Kptfile -index 271c9a5..445ddf4 100644 +index f147d84..15fd450 100644 --- a/subpkg/Kptfile +++ b/subpkg/Kptfile @@ -2,6 +2,10 @@ apiVersion: kpt.dev/v1 @@ -109,18 +92,3 @@ index 302322e..dfe3056 100644 + labels: + level: root + test: subpkg-fail -diff --git a/subpkg/starlark-fn-failure.yaml b/subpkg/starlark-fn-failure.yaml -index 55ceaae..4d01f35 100644 ---- a/subpkg/starlark-fn-failure.yaml -+++ b/subpkg/starlark-fn-failure.yaml -@@ -2,6 +2,10 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: always-fail -+ labels: -+ level: root -+ test: subpkg-fail -+ namespace: subpkg-ns - source: | - def fail_fn(items): - fail("intentional failure for testing") 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 271c9a592c..f147d84027 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 @@ -10,5 +10,4 @@ pipeline: configMap: namespace: subpkg-ns validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-basicpipeline/.expected/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/dfs-basicpipeline/.expected/config.yaml index f6237512ca..2eba311bad 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-basicpipeline/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-basicpipeline/.expected/config.yaml @@ -1 +1,2 @@ exitCode: 1 +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 a493730499..3234bb19c8 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,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index ed88ddf..a1d57f0 100644 +index c6fc0c5..620b80e 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,16 +1,42 @@ +@@ -1,17 +1,27 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: @@ -20,16 +20,18 @@ index ed88ddf..a1d57f0 100644 - - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 - configMap: - app: myapp -- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -- configPath: starlark-fn-failure.yaml +- - 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: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ configPath: starlark-fn-failure.yaml ++ - image: invalid-image:v0.0.0 ++ configMap: ++ tier: backend +status: + conditions: + - type: Rendered @@ -38,22 +40,6 @@ index ed88ddf..a1d57f0 100644 + message: |- + pkg.render: pkg .: + pipeline.run: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: 'failed to evaluate function: error: function failure' -+ exitCode: 1 -+ results: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorResults: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/starlark:latest: exit code 1' diff --git a/resources.yaml b/resources.yaml index 0848ba0..7eece9b 100644 --- a/resources.yaml @@ -71,17 +57,3 @@ index 0848ba0..7eece9b 100644 + metadata: + annotations: + app: myapp -diff --git a/starlark-fn-failure.yaml b/starlark-fn-failure.yaml -index 55ceaae..d2841c7 100644 ---- a/starlark-fn-failure.yaml -+++ b/starlark-fn-failure.yaml -@@ -2,6 +2,9 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: always-fail -+ annotations: -+ app: myapp -+ namespace: staging - source: | - def fail_fn(items): - fail("intentional failure for testing") 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 ed88ddfc6e..c6fc0c546a 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 @@ -12,5 +12,6 @@ pipeline: - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 configMap: app: myapp - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: invalid-image:v0.0.0 + configMap: + tier: backend diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-deep-nested-middle-fails/.expected/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/dfs-deep-nested-middle-fails/.expected/config.yaml index f6237512ca..2eba311bad 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-deep-nested-middle-fails/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-deep-nested-middle-fails/.expected/config.yaml @@ -1 +1,2 @@ exitCode: 1 +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 ef9119f97b..14f98d3f02 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,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index 4047d27..02908a2 100644 +index 4047d27..e7ca740 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,13 +1,38 @@ +@@ -1,13 +1,21 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: @@ -26,25 +26,8 @@ index 4047d27..02908a2 100644 + message: |- + pkg.render: pkg ./level1: + pipeline.run: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ validationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: 'failed to evaluate function: error: function failure' -+ exitCode: 1 -+ results: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorResults: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/starlark:latest: exit code 1' diff --git a/level1/Kptfile b/level1/Kptfile -index 2bc48be..ec5f5a7 100644 +index b5960dd..b42f153 100644 --- a/level1/Kptfile +++ b/level1/Kptfile @@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 @@ -98,16 +81,3 @@ index ab7d3fa..1eeeaed 100644 + level: level1 data: level: level2 -diff --git a/level1/starlark-fn-failure.yaml b/level1/starlark-fn-failure.yaml -index 55ceaae..34c320f 100644 ---- a/level1/starlark-fn-failure.yaml -+++ b/level1/starlark-fn-failure.yaml -@@ -2,6 +2,8 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: always-fail -+ labels: -+ level: level1 - source: | - def fail_fn(items): - fail("intentional failure for testing") diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-deep-nested-middle-fails/level1/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/dfs-deep-nested-middle-fails/level1/Kptfile index 2bc48be98e..b5960dd7a7 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-deep-nested-middle-fails/level1/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-deep-nested-middle-fails/level1/Kptfile @@ -10,5 +10,4 @@ pipeline: configMap: level: level1 validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-multiple-subpkgs-one-fails/.expected/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/dfs-multiple-subpkgs-one-fails/.expected/config.yaml index f6237512ca..2eba311bad 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-multiple-subpkgs-one-fails/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-multiple-subpkgs-one-fails/.expected/config.yaml @@ -1 +1,2 @@ exitCode: 1 +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 7512f2967d..582f70fc72 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,5 +1,5 @@ diff --git a/Kptfile b/Kptfile -index c47c90d..0ad6086 100644 +index c47c90d..1b7e920 100644 --- a/Kptfile +++ b/Kptfile @@ -1,9 +1,9 @@ @@ -13,7 +13,7 @@ index c47c90d..0ad6086 100644 info: description: DFS - Multiple subpackages, sub2 fails pipeline: -@@ -11,3 +11,28 @@ pipeline: +@@ -11,3 +11,11 @@ pipeline: - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 configMap: pkg: root @@ -25,23 +25,6 @@ index c47c90d..0ad6086 100644 + message: |- + pkg.render: pkg ./sub2: + pipeline.run: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ validationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: 'failed to evaluate function: error: function failure' -+ exitCode: 1 -+ results: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorResults: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/starlark:latest: exit code 1' diff --git a/sub1/Kptfile b/sub1/Kptfile index 2d62077..0f03268 100644 --- a/sub1/Kptfile @@ -75,7 +58,7 @@ index 2f649ba..c2245a9 100644 + labels: + pkg: sub1 diff --git a/sub2/Kptfile b/sub2/Kptfile -index 853d3f0..89cfa33 100644 +index 792277c..6412843 100644 --- a/sub2/Kptfile +++ b/sub2/Kptfile @@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 @@ -106,16 +89,3 @@ index 20375ea..7290360 100644 + metadata: + labels: + pkg: sub2 -diff --git a/sub2/starlark-fn-failure.yaml b/sub2/starlark-fn-failure.yaml -index 55ceaae..5b9cf38 100644 ---- a/sub2/starlark-fn-failure.yaml -+++ b/sub2/starlark-fn-failure.yaml -@@ -2,6 +2,8 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: always-fail -+ labels: -+ pkg: sub2 - source: | - def fail_fn(items): - fail("intentional failure for testing") diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-multiple-subpkgs-one-fails/sub2/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/dfs-multiple-subpkgs-one-fails/sub2/Kptfile index 853d3f0df5..792277c2b0 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-multiple-subpkgs-one-fails/sub2/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-multiple-subpkgs-one-fails/sub2/Kptfile @@ -8,5 +8,4 @@ pipeline: configMap: pkg: sub2 validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-and-subpkg-both-fail/.expected/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-and-subpkg-both-fail/.expected/config.yaml index f6237512ca..2eba311bad 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-and-subpkg-both-fail/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-and-subpkg-both-fail/.expected/config.yaml @@ -1 +1,2 @@ exitCode: 1 +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 16042c11a8..f0105bbf0f 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,5 +1,5 @@ diff --git a/Kptfile b/Kptfile -index 2e71448..1a82d1e 100644 +index e4d630d..c8d5efb 100644 --- a/Kptfile +++ b/Kptfile @@ -1,9 +1,9 @@ @@ -13,10 +13,10 @@ index 2e71448..1a82d1e 100644 info: description: DFS - Both parent and subpackage fail pipeline: -@@ -14,3 +14,26 @@ pipeline: +@@ -13,3 +13,11 @@ pipeline: + pkg: root validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 +status: + conditions: + - type: Rendered @@ -25,23 +25,8 @@ index 2e71448..1a82d1e 100644 + message: |- + pkg.render: pkg ./subpkg: + pipeline.run: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ validationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: 'failed to evaluate function: error: function failure' -+ exitCode: 1 -+ results: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorResults: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/starlark:latest: exit code 1' diff --git a/subpkg/Kptfile b/subpkg/Kptfile -index 492902c..3cb271d 100644 +index a332cf5..cb45834 100644 --- a/subpkg/Kptfile +++ b/subpkg/Kptfile @@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 @@ -68,16 +53,3 @@ index 276bf9e..7b26a8d 100644 - port: 80 + selector: + pkg: subpkg -diff --git a/subpkg/starlark-fn-failure.yaml b/subpkg/starlark-fn-failure.yaml -index 55ceaae..1a57ad9 100644 ---- a/subpkg/starlark-fn-failure.yaml -+++ b/subpkg/starlark-fn-failure.yaml -@@ -2,6 +2,8 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: always-fail -+ labels: -+ pkg: subpkg - source: | - def fail_fn(items): - fail("intentional failure for testing") diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-and-subpkg-both-fail/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-and-subpkg-both-fail/Kptfile index 2e71448f59..e4d630ddc7 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-and-subpkg-both-fail/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-and-subpkg-both-fail/Kptfile @@ -12,5 +12,4 @@ pipeline: configMap: pkg: root validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-and-subpkg-both-fail/subpkg/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-and-subpkg-both-fail/subpkg/Kptfile index 492902c112..a332cf57ab 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-and-subpkg-both-fail/subpkg/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-and-subpkg-both-fail/subpkg/Kptfile @@ -10,5 +10,4 @@ pipeline: configMap: pkg: subpkg validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-mutator-fails/.expected/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-mutator-fails/.expected/config.yaml index f6237512ca..2eba311bad 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-mutator-fails/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-mutator-fails/.expected/config.yaml @@ -1 +1,2 @@ exitCode: 1 +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 1e8f8a9ac8..eecfacca1c 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,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index 207a7ca..c351a54 100644 +index c134b37..a48d9bb 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,15 +1,41 @@ +@@ -1,14 +1,24 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: @@ -20,8 +20,7 @@ index 207a7ca..c351a54 100644 configMap: - test: "parent-mutator-fail" + test: parent-mutator-fail - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 +status: + conditions: + - type: Rendered @@ -30,22 +29,6 @@ index 207a7ca..c351a54 100644 + message: |- + pkg.render: pkg .: + pipeline.run: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: 'failed to evaluate function: error: function failure' -+ exitCode: 1 -+ results: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorResults: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/starlark:latest: exit code 1' diff --git a/configmap.yaml b/configmap.yaml index 20a54f6..a46a12b 100644 --- a/configmap.yaml @@ -58,19 +41,6 @@ index 20a54f6..a46a12b 100644 + test: parent-mutator-fail data: key: value -diff --git a/starlark-fn-failure.yaml b/starlark-fn-failure.yaml -index 55ceaae..f589633 100644 ---- a/starlark-fn-failure.yaml -+++ b/starlark-fn-failure.yaml -@@ -2,6 +2,8 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: always-fail -+ labels: -+ test: parent-mutator-fail - source: | - def fail_fn(items): - fail("intentional failure for testing") diff --git a/subpkg/Kptfile b/subpkg/Kptfile index e940ae8..9b73f07 100644 --- a/subpkg/Kptfile diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-mutator-fails/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-mutator-fails/Kptfile index 207a7ca14e..c134b37717 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-mutator-fails/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-mutator-fails/Kptfile @@ -11,5 +11,4 @@ pipeline: - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 configMap: test: "parent-mutator-fail" - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-validator-fails/.expected/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-validator-fails/.expected/config.yaml index f6237512ca..2eba311bad 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-validator-fails/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-validator-fails/.expected/config.yaml @@ -1 +1,2 @@ exitCode: 1 +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 5a2ace3204..0d65d79302 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,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index b402aed..04ef8db 100644 +index 94a7a73..8965faa 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,16 +1,43 @@ +@@ -1,15 +1,25 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: @@ -21,8 +21,7 @@ index b402aed..04ef8db 100644 - test: "parent-fail" + test: parent-fail validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 +status: + conditions: + - type: Rendered @@ -31,23 +30,6 @@ index b402aed..04ef8db 100644 + message: |- + pkg.render: pkg .: + pipeline.run: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ validationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: 'failed to evaluate function: error: function failure' -+ exitCode: 1 -+ results: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorResults: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/starlark:latest: exit code 1' diff --git a/configmap.yaml b/configmap.yaml index 20a54f6..ad595de 100644 --- a/configmap.yaml @@ -60,19 +42,6 @@ index 20a54f6..ad595de 100644 + test: parent-fail data: key: value -diff --git a/starlark-fn-failure.yaml b/starlark-fn-failure.yaml -index 55ceaae..eb4b975 100644 ---- a/starlark-fn-failure.yaml -+++ b/starlark-fn-failure.yaml -@@ -2,6 +2,8 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: always-fail -+ labels: -+ test: parent-fail - source: | - def fail_fn(items): - fail("intentional failure for testing") diff --git a/subpkg/Kptfile b/subpkg/Kptfile index e940ae8..a2fe9c5 100644 --- a/subpkg/Kptfile diff --git a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-validator-fails/Kptfile b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-validator-fails/Kptfile index b402aedaab..94a7a73ca7 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-validator-fails/Kptfile +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-parent-validator-fails/Kptfile @@ -12,5 +12,4 @@ pipeline: configMap: test: "parent-fail" validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - 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-mutator-fails/.expected/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-mutator-fails/.expected/config.yaml index f6237512ca..2eba311bad 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-mutator-fails/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-mutator-fails/.expected/config.yaml @@ -1 +1,2 @@ exitCode: 1 +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 97fe2e0b95..514a0dde24 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,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index 80aa788..77f5c7b 100644 +index 80aa788..0fca116 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,13 +1,35 @@ +@@ -1,13 +1,21 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: @@ -26,22 +26,8 @@ index 80aa788..77f5c7b 100644 + message: |- + pkg.render: pkg ./subpkg: + pipeline.run: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: 'failed to evaluate function: error: function failure' -+ exitCode: 1 -+ results: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorResults: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/starlark:latest: exit code 1' diff --git a/subpkg/Kptfile b/subpkg/Kptfile -index 7b4318a..2c39656 100644 +index ec4ce38..d7ac408 100644 --- a/subpkg/Kptfile +++ b/subpkg/Kptfile @@ -2,6 +2,7 @@ apiVersion: kpt.dev/v1 @@ -63,15 +49,3 @@ index 302322e..98ff830 100644 + namespace: subpkg-ns spec: replicas: 2 -diff --git a/subpkg/starlark-fn-failure.yaml b/subpkg/starlark-fn-failure.yaml -index 55ceaae..3a4003f 100644 ---- a/subpkg/starlark-fn-failure.yaml -+++ b/subpkg/starlark-fn-failure.yaml -@@ -2,6 +2,7 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: always-fail -+ namespace: subpkg-ns - source: | - def fail_fn(items): - fail("intentional failure for testing") 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 7b4318a971..ec4ce38547 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 @@ -9,5 +9,4 @@ pipeline: - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 configMap: namespace: subpkg-ns - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - 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/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-validator-fails/.expected/config.yaml index f6237512ca..2eba311bad 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-validator-fails/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/dfs-subpkg-validator-fails/.expected/config.yaml @@ -1 +1,2 @@ exitCode: 1 +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 480b643eef..4dbe465e7d 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,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index 7c3b09a..2b496da 100644 +index 7c3b09a..6bc279b 100644 --- a/Kptfile +++ b/Kptfile -@@ -1,14 +1,37 @@ +@@ -1,14 +1,22 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: @@ -28,23 +28,8 @@ index 7c3b09a..2b496da 100644 + message: |- + pkg.render: pkg ./subpkg: + pipeline.run: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ validationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: 'failed to evaluate function: error: function failure' -+ exitCode: 1 -+ results: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorResults: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/starlark:latest: exit code 1' diff --git a/subpkg/Kptfile b/subpkg/Kptfile -index 271c9a5..cbd2fa4 100644 +index f147d84..b3c532e 100644 --- a/subpkg/Kptfile +++ b/subpkg/Kptfile @@ -2,6 +2,7 @@ apiVersion: kpt.dev/v1 @@ -66,15 +51,3 @@ index 302322e..98ff830 100644 + namespace: subpkg-ns spec: replicas: 2 -diff --git a/subpkg/starlark-fn-failure.yaml b/subpkg/starlark-fn-failure.yaml -index 55ceaae..3a4003f 100644 ---- a/subpkg/starlark-fn-failure.yaml -+++ b/subpkg/starlark-fn-failure.yaml -@@ -2,6 +2,7 @@ apiVersion: fn.kpt.dev/v1alpha1 - kind: StarlarkRun - metadata: - name: always-fail -+ namespace: subpkg-ns - source: | - def fail_fn(items): - fail("intentional failure for testing") 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 271c9a592c..f147d84027 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 @@ -10,5 +10,4 @@ pipeline: configMap: namespace: subpkg-ns validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: ghcr.io/kptdev/krm-functions-catalog/invalid-image:v0.0.0 diff --git a/e2e/testdata/fn-render/save-on-render-failure/no-save-on-render-failure/.expected/config.yaml b/e2e/testdata/fn-render/save-on-render-failure/no-save-on-render-failure/.expected/config.yaml index 320d1ac52c..66f4b9726b 100644 --- a/e2e/testdata/fn-render/save-on-render-failure/no-save-on-render-failure/.expected/config.yaml +++ b/e2e/testdata/fn-render/save-on-render-failure/no-save-on-render-failure/.expected/config.yaml @@ -1,2 +1,3 @@ exitCode: 1 allowNetwork: true +StdErrRegEx: "(docker: Error response from daemon: Head.*denied|Error.*initializing source docker)" 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 1bc17362b6..187669d407 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,8 +1,8 @@ diff --git a/Kptfile b/Kptfile -index 8a2f9e1..49b7fb6 100644 +index 6e26cd3..fb2aa71 100644 --- a/Kptfile +++ b/Kptfile -@@ -4,11 +4,35 @@ metadata: +@@ -4,12 +4,20 @@ metadata: name: no-save-on-render-failure pipeline: mutators: @@ -12,16 +12,18 @@ index 8a2f9e1..49b7fb6 100644 - - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 - configMap: - app: myapp -- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -- configPath: starlark-fn-failure.yaml +- - 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: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ configPath: starlark-fn-failure.yaml ++ - image: invalid-image:v0.0.0 ++ configMap: ++ tier: backend +status: + conditions: + - type: Rendered @@ -30,19 +32,3 @@ index 8a2f9e1..49b7fb6 100644 + message: |- + pkg.render: pkg .: + pipeline.run: already handled error -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ stderr: 'failed to evaluate function: error: function failure' -+ exitCode: 1 -+ results: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorResults: -+ - message: 'fail: intentional failure for testing' -+ severity: error -+ errorSummary: 'ghcr.io/kptdev/krm-functions-catalog/starlark:latest: exit code 1' 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 8a2f9e1430..6e26cd3f3e 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 @@ -10,5 +10,6 @@ pipeline: - image: ghcr.io/kptdev/krm-functions-catalog/set-annotations:v0.1.4 configMap: app: myapp - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-fn-failure.yaml + - image: invalid-image:v0.0.0 + configMap: + tier: backend 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 ef1154af5a..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..251ecc4 100644 +index 351f2fe..e322be3 100644 --- a/Kptfile +++ b/Kptfile -@@ -2,14 +2,27 @@ apiVersion: kpt.dev/v1 +@@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: app @@ -10,33 +10,12 @@ index abc7b97..251ecc4 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 -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 + - 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 @@ -45,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 320d1e7658..5164251518 100644 --- a/e2e/testdata/fn-render/selectors/exclude/.expected/diff.patch +++ b/e2e/testdata/fn-render/selectors/exclude/.expected/diff.patch @@ -1,36 +1,8 @@ -diff --git a/Kptfile b/Kptfile -index 266b33a..4be3f73 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -8,10 +8,21 @@ 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 -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 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 +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 79d26c77b0..c8f6f65d25 100644 --- a/e2e/testdata/fn-render/selectors/generator/.expected/diff.patch +++ b/e2e/testdata/fn-render/selectors/generator/.expected/diff.patch @@ -1,28 +1,81 @@ diff --git a/Kptfile b/Kptfile -index eb2f084..10441e5 100644 +index 8b11afc..15df83b 100644 --- a/Kptfile +++ b/Kptfile -@@ -14,3 +14,20 @@ pipeline: - tier: db - selectors: - - name: httpbin -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 +@@ -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 @@ -54,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 d10b112118..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..1fd5efb 100644 +index bc10671..d8897bb 100644 --- a/Kptfile +++ b/Kptfile @@ -2,6 +2,8 @@ apiVersion: kpt.dev/v1 @@ -10,27 +10,12 @@ index c16cdca..1fd5efb 100644 + tier: backend pipeline: mutators: - - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -@@ -15,3 +17,14 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 + - 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 @@ -38,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 5d0f6b9ea7..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,37 +1,21 @@ diff --git a/Kptfile b/Kptfile -index d4e5935..24022da 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,14 @@ pipeline: - - image: set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 + - 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 @@ -40,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 031c210bcd..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,34 +1,5 @@ -diff --git a/Kptfile b/Kptfile -index 701e0a1..63952e8 100644 ---- a/Kptfile -+++ b/Kptfile -@@ -4,3 +4,12 @@ metadata: - name: root-pkg - info: - description: sample description -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -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 @@ -39,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 aef01a905e..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,60 +1,79 @@ diff --git a/Kptfile b/Kptfile -index 364e274..79d669a 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,22 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 ++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"); @@ -75,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 @@ @@ -143,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 @@ -163,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 fa040eaaab..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,56 +1,35 @@ diff --git a/Kptfile b/Kptfile -index 82686a8..7570107 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,18 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: db -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 + - 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 @@ -60,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 @@ -82,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 fa040eaaab..915926857d 100644 --- a/e2e/testdata/fn-render/subpkgs/.expected/diff.patch +++ b/e2e/testdata/fn-render/subpkgs/.expected/diff.patch @@ -1,56 +1,35 @@ diff --git a/Kptfile b/Kptfile -index 82686a8..7570107 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,18 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: db -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 + - 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 @@ -60,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 @@ -82,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 114ed718fa..679e31b313 100644 --- a/e2e/testdata/fn-render/success-stdout/.expected/diff.patch +++ b/e2e/testdata/fn-render/success-stdout/.expected/diff.patch @@ -1,37 +1,21 @@ diff --git a/Kptfile b/Kptfile -index 1307fb5..fee64dc 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,14 @@ pipeline: - - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 - configMap: - tier: backend -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 -+ exitCode: 0 -+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5 -+ exitCode: 0 + - 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 @@ -40,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 8632a3fdd2..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,23 +1,30 @@ diff --git a/Kptfile b/Kptfile -index b2432a4..aab20f0 100644 +index 5c1d9fa..b2432a4 100644 --- a/Kptfile +++ b/Kptfile -@@ -9,3 +9,15 @@ pipeline: - validators: - - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest - configPath: starlark-httpbin-val.yaml -+status: -+ conditions: -+ - type: Rendered -+ status: "True" -+ reason: RenderSuccess -+ renderStatus: -+ mutationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ exitCode: 0 -+ validationSteps: -+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest -+ exitCode: 0 +@@ -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 @@ -37,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/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/container.go b/internal/fnruntime/container.go index cd675e0d7a..2b2dc0cee2 100644 --- a/internal/fnruntime/container.go +++ b/internal/fnruntime/container.go @@ -80,6 +80,7 @@ type ContainerFn struct { // Image is the container image to run Image string + Tag string // ImagePullPolicy controls the image pulling behavior. ImagePullPolicy runneroptions.ImagePullPolicy // Container function will be killed after this timeour. @@ -151,6 +152,21 @@ func (f *ContainerFn) Run(reader io.Reader, writer io.Writer) error { return err } + if f.Tag != "" { + tagResolver := &TagResolver{ + lister: &RegClientLister{ + client: regclient.New( + regclient.WithUserAgent(UserAgent), + regclient.WithDockerCreds(), + ), + }, + } + f.Image, err = tagResolver.ResolveFunctionImage(f.Ctx, f.Image, f.Tag) + if err != nil { + return err + } + } + switch runtime { case Podman: return f.runCLI(reader, writer, podmanBin, filterPodmanCLIOutput) diff --git a/internal/fnruntime/jsglue.go b/internal/fnruntime/jsglue.go index ddbd7a7df3..098b0044ad 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,9 @@ const crypto = require('crypto'); }, } }; - // Expose imports under both "gojs" (Go 1.21+) and "go" (Go <1.21) - this.importObject.go = this.importObject.gojs; + // Expose imports under both "go" and "gojs" to support + // wasm_exec.js expectations across supported Go versions. + this.importObject.gojs = this.importObject.go; } async run(instance) { if (!(instance instanceof WebAssembly.Instance)) { diff --git a/internal/fnruntime/runner.go b/internal/fnruntime/runner.go index 035e8ad701..ca9c968b81 100644 --- a/internal/fnruntime/runner.go +++ b/internal/fnruntime/runner.go @@ -35,7 +35,6 @@ import ( "github.com/kptdev/kpt/pkg/lib/errors" "github.com/kptdev/kpt/pkg/lib/runneroptions" "github.com/kptdev/kpt/pkg/printer" - "github.com/regclient/regclient" "sigs.k8s.io/kustomize/kyaml/filesys" "sigs.k8s.io/kustomize/kyaml/fn/framework" "sigs.k8s.io/kustomize/kyaml/fn/runtime/runtimeutil" @@ -61,23 +60,6 @@ func NewRunner( if f.Image != "" { img := opts.ResolveToImage(f.Image) f.Image = img - - if f.Tag != "" { - tagResolver := &TagResolver{ - lister: &RegClientLister{ - client: regclient.New( - regclient.WithUserAgent(UserAgent), - regclient.WithDockerCreds(), - ), - }, - } - f.Image, err = tagResolver.ResolveFunctionImage(ctx, f.Image, f.Tag) - if err != nil { - return nil, err - } - } else if !hasTagOrDigest(f.Image) { - f.Image += ":latest" - } } fnResult := &fnresult.Result{ @@ -121,6 +103,7 @@ func NewRunner( } else { cfn := &ContainerFn{ Image: f.Image, + Tag: f.Tag, ImagePullPolicy: opts.ImagePullPolicy, Perm: ContainerFnPermission{ AllowNetwork: opts.AllowNetwork, @@ -522,15 +505,3 @@ func newFnConfig(fsys filesys.FileSystem, f *kptfilev1.Function, pkgPath types.U // no need to return ConfigMap if no config given return nil, nil } - -// hasTagOrDigest reports whether the image reference contains an explicit tag or digest. -func hasTagOrDigest(image string) bool { - if strings.Contains(image, "@") { - return true - } - lastSlash := strings.LastIndex(image, "/") - if lastSlash == -1 { - return strings.Contains(image, ":") - } - return strings.Contains(image[lastSlash:], ":") -} diff --git a/internal/fnruntime/runner_test.go b/internal/fnruntime/runner_test.go index 0c009b7f97..9e0e6819e3 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,19 @@ 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()) + tmp.Close() // Close file handle + defer os.Remove(tmp.Name()) // Clean up temp file + 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") @@ -658,38 +662,3 @@ func getExpectedPrefix(prefix string) string { } return prefix } - -func TestHasTagOrDigest(t *testing.T) { - tests := []struct { - name string - image string - want bool - }{ - // With explicit tag - {"tag", "nginx:1.25", true}, - {"latest tag", "nginx:latest", true}, - {"full path with tag", "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5", true}, - - // With digest - {"digest only", "nginx@sha256:abc123", true}, - {"full path with digest", "ghcr.io/kptdev/krm-functions-catalog/set-labels@sha256:abc123", true}, - {"tag and digest", "nginx:1.25@sha256:abc123", true}, - - // Without tag or digest - {"bare image", "nginx", false}, - {"full path no tag", "ghcr.io/kptdev/krm-functions-catalog/set-labels", false}, - {"two-part no tag", "library/nginx", false}, - - // Registry with port (should not confuse port colon with tag colon) - {"registry port no tag", "localhost:5000/myimage", false}, - {"registry port with tag", "localhost:5000/myimage:v1", true}, - {"registry port with digest", "localhost:5000/myimage@sha256:abc123", true}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := hasTagOrDigest(tt.image); got != tt.want { - t.Errorf("hasTagOrDigest(%q) = %v, want %v", tt.image, got, tt.want) - } - }) - } -} diff --git a/internal/kptops/functions.go b/internal/kptops/functions.go index b7dda286f2..a32da38d4f 100644 --- a/internal/kptops/functions.go +++ b/internal/kptops/functions.go @@ -19,9 +19,13 @@ 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:v0.4.1": setNamespace, + "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..8d8122dbe7 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,20 @@ 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 10406fd6e5..eb83469e25 100644 --- a/internal/util/render/executor.go +++ b/internal/util/render/executor.go @@ -37,7 +37,6 @@ import ( "github.com/kptdev/kpt/pkg/printer" "k8s.io/klog/v2" "sigs.k8s.io/kustomize/kyaml/filesys" - "sigs.k8s.io/kustomize/kyaml/fn/framework" "sigs.k8s.io/kustomize/kyaml/kio" "sigs.k8s.io/kustomize/kyaml/kio/kioutil" "sigs.k8s.io/kustomize/kyaml/sets" @@ -122,16 +121,10 @@ func (e *Renderer) Execute(ctx context.Context) (*fnresult.ResultList, error) { // adjust the relative paths of the resources. err = adjustRelPath(hctx) if err != nil { - if e.Output == nil { - updateRenderStatus(hctx, err) - } return nil, err } if err = trackOutputFiles(hctx); err != nil { - if e.Output == nil { - updateRenderStatus(hctx, err) - } return nil, err } @@ -164,7 +157,6 @@ func (e *Renderer) Execute(ctx context.Context) (*fnresult.ResultList, error) { if hydErr == nil { if err = pruneResources(e.FileSystem, hctx); err != nil { - updateRenderStatus(hctx, err) return nil, err } } @@ -214,7 +206,7 @@ func (e *Renderer) printPipelineExecutionSummary(pr printer.Printer, hctx hydrat } } -// updateRenderStatus writes a Rendered status condition and RenderStatus to the root Kptfile. +// 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) { @@ -231,52 +223,11 @@ func updateRenderStatus(hctx *hydrationContext, hydErr error) { reason = kptfilev1.ReasonRenderFailed message = strings.ReplaceAll(hydErr.Error(), rootPath, ".") } - renderStatus := buildRenderStatus(hctx, hydErr) - setRenderStatus(hctx.fileSystem, rootPath, kptfilev1.NewRenderedCondition(conditionStatus, reason, message), renderStatus) + setRenderCondition(hctx.fileSystem, rootPath, kptfilev1.NewRenderedCondition(conditionStatus, reason, message)) } -// buildRenderStatus constructs a RenderStatus from the tracked pipeline step results. -func buildRenderStatus(hctx *hydrationContext, hydErr error) *kptfilev1.RenderStatus { - if len(hctx.mutationSteps) == 0 && len(hctx.validationSteps) == 0 { - return nil - } - rs := &kptfilev1.RenderStatus{ - MutationSteps: hctx.mutationSteps, - ValidationSteps: hctx.validationSteps, - } - if hydErr != nil { - var errLines []string - for _, s := range hctx.mutationSteps { - if s.ExecutionError != "" { - errLines = append(errLines, fmt.Sprintf("%s: %s", stepName(s), s.ExecutionError)) - } else if s.ExitCode != 0 { - errLines = append(errLines, fmt.Sprintf("%s: exit code %d", stepName(s), s.ExitCode)) - } - } - for _, s := range hctx.validationSteps { - if s.ExecutionError != "" { - errLines = append(errLines, fmt.Sprintf("%s: %s", stepName(s), s.ExecutionError)) - } else if s.ExitCode != 0 { - errLines = append(errLines, fmt.Sprintf("%s: exit code %d", stepName(s), s.ExitCode)) - } - } - rs.ErrorSummary = strings.Join(errLines, "\n") - } - return rs -} - -func stepName(s kptfilev1.PipelineStepResult) string { - if s.Name != "" { - return s.Name - } - if s.Image != "" { - return s.Image - } - return s.ExecPath -} - -// setRenderStatus reads the Kptfile at pkgPath, sets the Rendered condition and RenderStatus, and writes it back. -func setRenderStatus(fs filesys.FileSystem, pkgPath string, condition kptfilev1.Condition, renderStatus *kptfilev1.RenderStatus) { +// 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 { @@ -291,9 +242,8 @@ func setRenderStatus(fs filesys.FileSystem, pkgPath string, condition kptfilev1. return c.Type == kptfilev1.ConditionTypeRendered }) kf.Status.Conditions = append(kf.Status.Conditions, condition) - kf.Status.RenderStatus = renderStatus if err := kptfileutil.WriteKptfileToFS(fs, pkgPath, kf); err != nil { - klog.V(3).Infof("failed to write render status to Kptfile at %s: %v", pkgPath, err) + klog.V(3).Infof("failed to write render status condition to Kptfile at %s: %v", pkgPath, err) } } @@ -339,10 +289,6 @@ type hydrationContext struct { // should be saved when rendering fails. Read from the root Kptfile annotation. saveOnRenderFailure bool - // mutationSteps and validationSteps track per-function results for RenderStatus. - mutationSteps []kptfilev1.PipelineStepResult - validationSteps []kptfilev1.PipelineStepResult - runnerOptions runneroptions.RunnerOptions fileSystem filesys.FileSystem @@ -750,16 +696,12 @@ func (pn *pkgNode) runMutators(ctx context.Context, hctx *hydrationContext, inpu return input, nil } - mutators, failIdx, err := fnChain(ctx, hctx, pn.pkg.UniquePath, pl.Mutators) + mutators, err := fnChain(ctx, hctx, pn.pkg.UniquePath, pl.Mutators) if err != nil { - // Capture execution error (e.g. missing exec, image resolution failure) - hctx.mutationSteps = append(hctx.mutationSteps, preExecFailureStep(pl.Mutators[failIdx], err)) return nil, err } for i, mutator := range mutators { - resultCountBeforeExec := len(hctx.fnResults.Items) - if pl.Mutators[i].ConfigPath != "" { // functionConfigs are included in the function inputs during `render` // and as a result, they can be mutated during the `render`. @@ -809,11 +751,9 @@ func (pn *pkgNode) runMutators(ctx context.Context, hctx *hydrationContext, inpu err = mutation.Execute() if err != nil { clearAnnotationsOnMutFailure(input) - hctx.mutationSteps = append(hctx.mutationSteps, captureStepResult(pl.Mutators[i], hctx.fnResults, resultCountBeforeExec, err)) return input, err } hctx.executedFunctionCnt++ - hctx.mutationSteps = append(hctx.mutationSteps, captureStepResult(pl.Mutators[i], hctx.fnResults, resultCountBeforeExec, nil)) if len(selectors) > 0 || len(exclusions) > 0 { // merge the output resources with input resources @@ -846,7 +786,6 @@ func (pn *pkgNode) runValidators(ctx context.Context, hctx *hydrationContext, in for i := range pl.Validators { function := pl.Validators[i] - resultCountBeforeExec := len(hctx.fnResults.Items) // validators are run on a copy of mutated resources to ensure // resources are not mutated. selectedResources, err := fnruntime.SelectInput(input, function.Selectors, function.Exclusions, &fnruntime.SelectionContext{RootPackagePath: hctx.root.pkg.UniquePath}) @@ -859,7 +798,6 @@ func (pn *pkgNode) runValidators(ctx context.Context, hctx *hydrationContext, in displayResourceCount = true } if function.Exec != "" && !hctx.runnerOptions.AllowExec { - hctx.validationSteps = append(hctx.validationSteps, preExecFailureStep(function, errAllowedExecNotSpecified)) return errAllowedExecNotSpecified } opts := hctx.runnerOptions @@ -867,15 +805,12 @@ func (pn *pkgNode) runValidators(ctx context.Context, hctx *hydrationContext, in opts.DisplayResourceCount = displayResourceCount validator, err = fnruntime.NewRunner(ctx, hctx.fileSystem, &function, pn.pkg.UniquePath, hctx.fnResults, opts, hctx.runtime) if err != nil { - hctx.validationSteps = append(hctx.validationSteps, preExecFailureStep(function, err)) return err } if _, err = validator.Filter(cloneResources(selectedResources)); err != nil { - hctx.validationSteps = append(hctx.validationSteps, captureStepResult(function, hctx.fnResults, resultCountBeforeExec, err)) return err } hctx.executedFunctionCnt++ - hctx.validationSteps = append(hctx.validationSteps, captureStepResult(function, hctx.fnResults, resultCountBeforeExec, nil)) } return nil } @@ -977,28 +912,29 @@ func pathRelToRoot(rootPkgPath, subPkgPath, resourcePath string) (relativePath s } // fnChain returns a slice of function runners given a list of functions defined in pipeline. -func fnChain(ctx context.Context, hctx *hydrationContext, pkgPath types.UniquePath, fns []kptfilev1.Function) ([]*fnruntime.FunctionRunner, int, error) { +func fnChain(ctx context.Context, hctx *hydrationContext, pkgPath types.UniquePath, fns []kptfilev1.Function) ([]*fnruntime.FunctionRunner, error) { var runners []*fnruntime.FunctionRunner for i := range fns { var err error var runner *fnruntime.FunctionRunner + function := fns[i] displayResourceCount := false - if len(fns[i].Selectors) > 0 || len(fns[i].Exclusions) > 0 { + if len(function.Selectors) > 0 || len(function.Exclusions) > 0 { displayResourceCount = true } - if fns[i].Exec != "" && !hctx.runnerOptions.AllowExec { - return nil, i, errAllowedExecNotSpecified + if function.Exec != "" && !hctx.runnerOptions.AllowExec { + return nil, errAllowedExecNotSpecified } opts := hctx.runnerOptions opts.SetPkgPathAnnotation = true opts.DisplayResourceCount = displayResourceCount - runner, err = fnruntime.NewRunner(ctx, hctx.fileSystem, &fns[i], pkgPath, hctx.fnResults, opts, hctx.runtime) + runner, err = fnruntime.NewRunner(ctx, hctx.fileSystem, &function, pkgPath, hctx.fnResults, opts, hctx.runtime) if err != nil { - return nil, i, err + return nil, err } runners = append(runners, runner) } - return runners, -1, nil + return runners, nil } // trackInputFiles records file paths of input resources in the hydration context. @@ -1044,82 +980,3 @@ func pruneResources(fsys filesys.FileSystem, hctx *hydrationContext) error { } return nil } - -// captureStepResult builds a PipelineStepResult from the fnresult.Result items -// appended since resultCountBeforeExec. -func captureStepResult(fn kptfilev1.Function, fnResults *fnresult.ResultList, resultCountBeforeExec int, execErr error) kptfilev1.PipelineStepResult { - step := kptfilev1.PipelineStepResult{ - Name: fn.Name, - Image: fn.Image, - ExecPath: fn.Exec, - } - if resultCountBeforeExec < len(fnResults.Items) { - last := fnResults.Items[len(fnResults.Items)-1] - step.Stderr = last.Stderr - step.ExitCode = last.ExitCode - step.Results = frameworkResultsToItems(last.Results) - for _, ri := range step.Results { - if ri.Severity == string(framework.Error) { - step.ErrorResults = append(step.ErrorResults, ri) - } - } - } else if execErr != nil { - step.ExitCode = 1 - step.ExecutionError = execErr.Error() - } - return step -} - -// preExecFailureStep creates a PipelineStepResult for errors that occur before -// the function is executed (e.g. image pull failure, missing exec permission). -// ExitCode is set to 1 to indicate failure; the executionError field provides -// the specific reason the function could not be started. -func preExecFailureStep(fn kptfilev1.Function, err error) kptfilev1.PipelineStepResult { - return kptfilev1.PipelineStepResult{ - Name: fn.Name, - Image: fn.Image, - ExecPath: fn.Exec, - ExitCode: 1, - ExecutionError: err.Error(), - } -} - -// frameworkResultsToItems converts framework.Results to []ResultItem. -func frameworkResultsToItems(results framework.Results) []kptfilev1.ResultItem { - if len(results) == 0 { - return nil - } - items := make([]kptfilev1.ResultItem, len(results)) - for i, r := range results { - items[i] = kptfilev1.ResultItem{ - Message: r.Message, - Severity: string(r.Severity), - } - if r.ResourceRef != nil { - items[i].ResourceRef = &kptfilev1.ResourceRef{ - APIVersion: r.ResourceRef.APIVersion, - Kind: r.ResourceRef.Kind, - Name: r.ResourceRef.Name, - Namespace: r.ResourceRef.Namespace, - } - } - if r.Field != nil { - items[i].Field = &kptfilev1.FieldRef{ - Path: r.Field.Path, - } - if r.Field.CurrentValue != nil { - items[i].Field.CurrentValue = fmt.Sprintf("%v", r.Field.CurrentValue) - } - if r.Field.ProposedValue != nil { - items[i].Field.ProposedValue = fmt.Sprintf("%v", r.Field.ProposedValue) - } - } - if r.File != nil { - items[i].File = &kptfilev1.FileRef{ - Path: r.File.Path, - Index: r.File.Index, - } - } - } - return items -} diff --git a/internal/util/render/executor_test.go b/internal/util/render/executor_test.go index 9f4280a794..2c8e253f54 100644 --- a/internal/util/render/executor_test.go +++ b/internal/util/render/executor_test.go @@ -25,19 +25,13 @@ import ( "github.com/kptdev/kpt/internal/fnruntime" "github.com/kptdev/kpt/internal/pkg" "github.com/kptdev/kpt/internal/types" - fnresult "github.com/kptdev/kpt/pkg/api/fnresult/v1" - 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" - "sigs.k8s.io/kustomize/kyaml/fn/framework" "sigs.k8s.io/kustomize/kyaml/kio" - "sigs.k8s.io/kustomize/kyaml/yaml" ) const rootString = "/root" -const subPkgString = "/root/subpkg" func TestPathRelToRoot(t *testing.T) { tests := []struct { @@ -255,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) @@ -416,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) @@ -578,459 +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 TestBuildRenderStatus_NoSteps(t *testing.T) { - hctx := &hydrationContext{} - rs := buildRenderStatus(hctx, nil) - assert.Nil(t, rs) -} - -func TestBuildRenderStatus_SuccessWithMutationSteps(t *testing.T) { - hctx := &hydrationContext{ - mutationSteps: []kptfilev1.PipelineStepResult{ - {Image: "set-namespace:v1", ExitCode: 0}, - {Image: "set-annotations:v1", ExitCode: 0}, - }, - } - rs := buildRenderStatus(hctx, nil) - assert.NotNil(t, rs) - assert.Len(t, rs.MutationSteps, 2) - assert.Empty(t, rs.ValidationSteps) - assert.Empty(t, rs.ErrorSummary) -} - -func TestBuildRenderStatus_FailureWithErrorSummary(t *testing.T) { - hctx := &hydrationContext{ - mutationSteps: []kptfilev1.PipelineStepResult{ - {Image: "set-namespace:v1", ExitCode: 0}, - {Image: "bad-image:v1", ExitCode: 1}, - }, - validationSteps: []kptfilev1.PipelineStepResult{ - {Image: "gatekeeper:latest", ExecutionError: "image not found"}, - }, - } - rs := buildRenderStatus(hctx, fmt.Errorf("pipeline failed")) - assert.NotNil(t, rs) - assert.Contains(t, rs.ErrorSummary, "bad-image:v1: exit code 1") - assert.Contains(t, rs.ErrorSummary, "gatekeeper:latest: image not found") -} - -func TestBuildRenderStatus_UsesNameForErrorSummary(t *testing.T) { - hctx := &hydrationContext{ - mutationSteps: []kptfilev1.PipelineStepResult{ - {Name: "my-step", Image: "img:v1", ExitCode: 1}, - }, - } - rs := buildRenderStatus(hctx, fmt.Errorf("fail")) - assert.Equal(t, "my-step: exit code 1", rs.ErrorSummary) -} - -func TestBuildRenderStatus_UsesExecPathForErrorSummary(t *testing.T) { - hctx := &hydrationContext{ - mutationSteps: []kptfilev1.PipelineStepResult{ - {ExecPath: "/usr/bin/my-fn", ExecutionError: "not found"}, - }, - } - rs := buildRenderStatus(hctx, fmt.Errorf("fail")) - assert.Equal(t, "/usr/bin/my-fn: not found", rs.ErrorSummary) -} - -func TestCaptureStepResult_FromFnResults(t *testing.T) { - fnResults := fnresult.NewResultList() - fnResults.Items = append(fnResults.Items, fnresult.Result{ - Image: "gatekeeper:latest", - ExitCode: 1, - Stderr: "validation failed", - Results: framework.Results{ - {Message: "banned key found", Severity: framework.Error, - ResourceRef: &yaml.ResourceIdentifier{ - TypeMeta: yaml.TypeMeta{APIVersion: "v1", Kind: "ConfigMap"}, - NameMeta: yaml.NameMeta{Name: "my-cm", Namespace: "default"}, - }, - File: &framework.File{Path: "resources.yaml", Index: 2}, - }, - {Message: "missing label", Severity: framework.Warning}, - }, - }) - - fn := kptfilev1.Function{Name: "validate", Image: "gatekeeper:latest"} - step := captureStepResult(fn, fnResults, 0, nil) - - assert.Equal(t, "validate", step.Name) - assert.Equal(t, "gatekeeper:latest", step.Image) - assert.Equal(t, 1, step.ExitCode) - assert.Equal(t, "validation failed", step.Stderr) - assert.Len(t, step.Results, 2) - - // First result — error with full resource ref and file - assert.Equal(t, "banned key found", step.Results[0].Message) - assert.Equal(t, "error", step.Results[0].Severity) - assert.Equal(t, "v1", step.Results[0].ResourceRef.APIVersion) - assert.Equal(t, "ConfigMap", step.Results[0].ResourceRef.Kind) - assert.Equal(t, "my-cm", step.Results[0].ResourceRef.Name) - assert.Equal(t, "default", step.Results[0].ResourceRef.Namespace) - assert.Equal(t, "resources.yaml", step.Results[0].File.Path) - assert.Equal(t, 2, step.Results[0].File.Index) - - // Second result — warning, no resource ref - assert.Equal(t, "missing label", step.Results[1].Message) - assert.Equal(t, "warning", step.Results[1].Severity) - assert.Nil(t, step.Results[1].ResourceRef) - - // ErrorResults should only contain the error-severity item - assert.Len(t, step.ErrorResults, 1) - assert.Equal(t, "banned key found", step.ErrorResults[0].Message) -} - -func TestCaptureStepResult_NoNewItems(t *testing.T) { - fnResults := fnresult.NewResultList() - fn := kptfilev1.Function{Image: "set-namespace:v1"} - step := captureStepResult(fn, fnResults, 0, fmt.Errorf("output resource list must contain only KRM resources")) - - assert.Equal(t, "set-namespace:v1", step.Image) - assert.Equal(t, 1, step.ExitCode) - assert.Equal(t, "output resource list must contain only KRM resources", step.ExecutionError) - assert.Nil(t, step.Results) - assert.Nil(t, step.ErrorResults) -} - -func TestPreExecFailureStep(t *testing.T) { - fn := kptfilev1.Function{Name: "my-fn", Image: "bad-image:v1", Exec: ""} - step := preExecFailureStep(fn, fmt.Errorf("pull access denied")) - - assert.Equal(t, "my-fn", step.Name) - assert.Equal(t, "bad-image:v1", step.Image) - assert.Equal(t, "pull access denied", step.ExecutionError) - assert.Equal(t, 1, step.ExitCode) - assert.Nil(t, step.Results) -} - -func TestPreExecFailureStep_EmptyFn(t *testing.T) { - step := preExecFailureStep(kptfilev1.Function{}, fmt.Errorf("no functions")) - assert.Empty(t, step.Name) - assert.Empty(t, step.Image) - assert.Empty(t, step.ExecPath) - assert.Equal(t, "no functions", step.ExecutionError) -} - -func TestFrameworkResultsToItems_Nil(t *testing.T) { - items := frameworkResultsToItems(nil) - assert.Nil(t, items) -} - -func TestFrameworkResultsToItems_WithFieldRef(t *testing.T) { - results := framework.Results{ - { - Message: "wrong value", - Severity: framework.Error, - Field: &framework.Field{ - Path: ".spec.replicas", - CurrentValue: "invalid", - ProposedValue: 3, - }, - }, - } - items := frameworkResultsToItems(results) - assert.Len(t, items, 1) - assert.Equal(t, ".spec.replicas", items[0].Field.Path) - assert.Equal(t, "invalid", items[0].Field.CurrentValue) - assert.Equal(t, "3", items[0].Field.ProposedValue) -} - -func TestFrameworkResultsToItems_NilFieldValues(t *testing.T) { - results := framework.Results{ - { - Message: "field info", - Severity: framework.Info, - Field: &framework.Field{ - Path: ".spec.replicas", - }, - }, - } - items := frameworkResultsToItems(results) - assert.Len(t, items, 1) - assert.Equal(t, ".spec.replicas", items[0].Field.Path) - assert.Empty(t, items[0].Field.CurrentValue) - assert.Empty(t, items[0].Field.ProposedValue) -} - -func TestUpdateRenderStatus_WritesRenderStatus(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, - mutationSteps: []kptfilev1.PipelineStepResult{ - {Image: "set-namespace:v1", ExitCode: 0}, - }, - validationSteps: []kptfilev1.PipelineStepResult{ - {Image: "gatekeeper:latest", ExitCode: 1, Stderr: "failed"}, - }, - } - - updateRenderStatus(hctx, fmt.Errorf("validation failed")) - - rootKf, err := kptfileutil.ReadKptfile(mockFS, rootPath) - assert.NoError(t, err) - assert.NotNil(t, rootKf.Status) - - // Condition should be set - assert.Len(t, rootKf.Status.Conditions, 1) - assert.Equal(t, kptfilev1.ConditionFalse, rootKf.Status.Conditions[0].Status) - - // RenderStatus should be populated - rs := rootKf.Status.RenderStatus - assert.NotNil(t, rs) - assert.Len(t, rs.MutationSteps, 1) - assert.Equal(t, "set-namespace:v1", rs.MutationSteps[0].Image) - assert.Len(t, rs.ValidationSteps, 1) - assert.Equal(t, "gatekeeper:latest", rs.ValidationSteps[0].Image) - assert.Contains(t, rs.ErrorSummary, "gatekeeper:latest: exit code 1") -} - -func TestUpdateRenderStatus_NilRenderStatusWhenNoSteps(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, - } - - updateRenderStatus(hctx, nil) - - rootKf, err := kptfileutil.ReadKptfile(mockFS, rootPath) - assert.NoError(t, err) - assert.NotNil(t, rootKf.Status) - assert.Nil(t, rootKf.Status.RenderStatus) -} - -func TestUpdateRenderStatus_ClearsPreviousRenderStatus(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) - - // First render: failure with steps - hctx := &hydrationContext{ - root: &pkgNode{pkg: rootPkg}, - pkgs: map[types.UniquePath]*pkgNode{}, - fileSystem: mockFS, - mutationSteps: []kptfilev1.PipelineStepResult{ - {Image: "bad:v1", ExitCode: 1}, - }, - } - updateRenderStatus(hctx, fmt.Errorf("fail")) - - rootKf, err := kptfileutil.ReadKptfile(mockFS, rootPath) - assert.NoError(t, err) - assert.NotNil(t, rootKf.Status.RenderStatus) - - // Second render: success with no steps (empty pipeline) - hctx2 := &hydrationContext{ - root: &pkgNode{pkg: rootPkg}, - pkgs: map[types.UniquePath]*pkgNode{}, - fileSystem: mockFS, - } - updateRenderStatus(hctx2, nil) - - rootKf, err = kptfileutil.ReadKptfile(mockFS, rootPath) - assert.NoError(t, err) - assert.Nil(t, rootKf.Status.RenderStatus) -} - -func TestStepName(t *testing.T) { - assert.Equal(t, "my-step", stepName(kptfilev1.PipelineStepResult{Name: "my-step", Image: "img:v1"})) - assert.Equal(t, "img:v1", stepName(kptfilev1.PipelineStepResult{Image: "img:v1"})) - assert.Equal(t, "/usr/bin/fn", stepName(kptfilev1.PipelineStepResult{ExecPath: "/usr/bin/fn"})) - assert.Equal(t, "", stepName(kptfilev1.PipelineStepResult{})) -} - 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..532de94bbb 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: @@ -107,7 +106,7 @@ spec: Runtime: &runtime{}, } r.RunnerOptions.InitDefaults(runneroptions.GHCRImagePrefix) - r.RunnerOptions.ImagePullPolicy = runneroptions.IfNotPresentPull + r.RunnerOptions.ImagePullPolicy = runneroptions.NeverPull _, err := r.Execute(fake.CtxWithDefaultPrinter()) if err != nil { t.Errorf("Failed to render: %v", err) @@ -181,7 +180,6 @@ apiVersion: custom.io/v1 kind: Custom metadata: name: custom - namespace: staging labels: tier: db spec: @@ -221,7 +219,7 @@ spec: Runtime: &runtime{}, } r.RunnerOptions.InitDefaults(runneroptions.GHCRImagePrefix) - r.RunnerOptions.ImagePullPolicy = runneroptions.IfNotPresentPull + r.RunnerOptions.ImagePullPolicy = runneroptions.NeverPull _, err := r.Execute(fake.CtxWithDefaultPrinter()) if err != nil { diff --git a/pkg/test/runner/runner.go b/pkg/test/runner/runner.go index c6a4ed5a2a..dad1aa9492 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 {