From d312fb54b47e2702f80b1ce434cb5375f8123827 Mon Sep 17 00:00:00 2001 From: Surbhi Date: Sun, 22 Mar 2026 23:30:29 +0530 Subject: [PATCH] test(fn-eval): update fn eval E2E tests to use :latest set-namespace This PR updates the kpt fn eval E2E test suite to use the :latest version of the set-namespace function. Key changes: - Add isUnknown() heuristic in internal/kptops/set-namespace.go to detect Custom Resources by API group, skipping namespace for unknown CRs without existing namespace - Update Kptfile references from pinned set-namespace image tags to :latest (ghcr.io/kptdev/krm-functions/set-namespace:latest) - Update .expected/ golden files to reflect new :latest behavior - Add .gitattributes to force LF for *.sh and CRLF for *.bat/*.cmd, preventing bash errors in CI - Update internal/fnruntime/runner_test.go to align with new function behavior Part 1 of 2 from the original PR #4420 (fn-eval portion). Signed-off-by: Surbhi --- .gitattributes | 9 + .../.expected/config.yaml | 2 +- .../fn-config-file/pkg/.expected/config.yaml | 2 +- .../pkg/.expected/diff.patch | 57 ++++++ .../pkg/.expected/config.yaml | 2 +- .../.expected/config.yaml | 2 +- .../.expected/config.yaml | 2 +- .../.expected/config.yaml | 2 +- .../pkg/.expected/config.yaml | 2 +- .../missing-fn-config/.expected/config.yaml | 2 +- .../missing-fn-config/.expected/diff.patch | 57 ++++++ .../pkg/.expected/config.yaml | 2 +- .../fn-eval/no-op/.expected/diff.patch | 169 ++++++++++++++++++ .../non-krm-resource/.expected/config.yaml | 4 +- .../out-of-place-dir/.expected/config.yaml | 4 +- .../.expected/config.yaml | 5 +- .../.expected/config.yaml | 4 +- .../output-to-stdout/.expected/config.yaml | 1 - .../preserve-comments/.expected/diff.patch | 139 ++++++++++++++ .../.expected/config.yaml | 2 +- .../.expected/config.yaml | 2 +- .../custom-pkg-path/.expected/config.yaml | 8 +- .../save-fn/image/.expected/config.yaml | 8 +- .../match-selector/.expected/config.yaml | 6 +- .../no-save-when-fail/.expected/config.yaml | 6 +- .../save-fn/override-fn/.expected/config.yaml | 8 +- .../.expected/config.yaml | 8 +- .../.expected/diff.patch | 2 +- .../validator-type/.expected/config.yaml | 8 +- .../basicpipeline/.expected/config.yaml | 4 +- .../selectors/exclude/.expected/config.yaml | 4 +- .../.expected/config.yaml | 4 +- .../.expected/config.yaml | 4 +- .../short-image-path/.expected/config.yaml | 6 +- .../short-image-path/.expected/results.yaml | 2 +- .../.expected/config.yaml | 4 +- .../.expected/diff.patch | 2 +- .../simple-function/.expected/config.yaml | 2 +- .../.expected/config.yaml | 2 +- .../.expected/config.yaml | 2 +- .../.expected/config.yaml | 2 +- .../.expected/config.yaml | 2 +- .../fn-eval/subpkgs/.expected/config.yaml | 2 +- .../wasm-function/.expected/config.yaml | 3 +- internal/fnruntime/jsglue.go | 4 +- internal/fnruntime/runner_test.go | 4 +- internal/kptops/set-namespace.go | 24 +++ 47 files changed, 527 insertions(+), 75 deletions(-) create mode 100644 .gitattributes create mode 100644 e2e/testdata/fn-eval/fn-success-with-stderr/pkg/.expected/diff.patch create mode 100644 e2e/testdata/fn-eval/missing-fn-config/.expected/diff.patch create mode 100644 e2e/testdata/fn-eval/no-op/.expected/diff.patch create mode 100644 e2e/testdata/fn-eval/preserve-comments/.expected/diff.patch 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/e2e/testdata/fn-eval/fn-config-file-in-pkg/.expected/config.yaml b/e2e/testdata/fn-eval/fn-config-file-in-pkg/.expected/config.yaml index 137ef487af..41105abedd 100644 --- a/e2e/testdata/fn-eval/fn-config-file-in-pkg/.expected/config.yaml +++ b/e2e/testdata/fn-eval/fn-config-file-in-pkg/.expected/config.yaml @@ -13,5 +13,5 @@ # limitations under the License. testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest fnConfig: ../config.yaml diff --git a/e2e/testdata/fn-eval/fn-config-file/pkg/.expected/config.yaml b/e2e/testdata/fn-eval/fn-config-file/pkg/.expected/config.yaml index 70b3c3ed7b..c7156ac8dc 100644 --- a/e2e/testdata/fn-eval/fn-config-file/pkg/.expected/config.yaml +++ b/e2e/testdata/fn-eval/fn-config-file/pkg/.expected/config.yaml @@ -13,5 +13,5 @@ # limitations under the License. testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest fnConfig: ../../config.yaml diff --git a/e2e/testdata/fn-eval/fn-success-with-stderr/pkg/.expected/diff.patch b/e2e/testdata/fn-eval/fn-success-with-stderr/pkg/.expected/diff.patch new file mode 100644 index 0000000000..c6f4cee599 --- /dev/null +++ b/e2e/testdata/fn-eval/fn-success-with-stderr/pkg/.expected/diff.patch @@ -0,0 +1,57 @@ +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-eval/fnconfig-missing-name/pkg/.expected/config.yaml b/e2e/testdata/fn-eval/fnconfig-missing-name/pkg/.expected/config.yaml index e55509d01d..3e7df546ea 100644 --- a/e2e/testdata/fn-eval/fnconfig-missing-name/pkg/.expected/config.yaml +++ b/e2e/testdata/fn-eval/fnconfig-missing-name/pkg/.expected/config.yaml @@ -13,7 +13,7 @@ # limitations under the License. testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest fnConfig: ../../config.yaml exitCode: 1 stdErr: "resource must have `metadata.name`" diff --git a/e2e/testdata/fn-eval/include-meta-resources-v1alpha1/.expected/config.yaml b/e2e/testdata/fn-eval/include-meta-resources-v1alpha1/.expected/config.yaml index 377e9fd8c1..63e976d46b 100644 --- a/e2e/testdata/fn-eval/include-meta-resources-v1alpha1/.expected/config.yaml +++ b/e2e/testdata/fn-eval/include-meta-resources-v1alpha1/.expected/config.yaml @@ -14,7 +14,7 @@ runCount: 2 testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest includeMetaResources: true exitCode: 1 args: diff --git a/e2e/testdata/fn-eval/include-meta-resources-v1alpha2/.expected/config.yaml b/e2e/testdata/fn-eval/include-meta-resources-v1alpha2/.expected/config.yaml index 377e9fd8c1..63e976d46b 100644 --- a/e2e/testdata/fn-eval/include-meta-resources-v1alpha2/.expected/config.yaml +++ b/e2e/testdata/fn-eval/include-meta-resources-v1alpha2/.expected/config.yaml @@ -14,7 +14,7 @@ runCount: 2 testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest includeMetaResources: true exitCode: 1 args: diff --git a/e2e/testdata/fn-eval/include-meta-resources/.expected/config.yaml b/e2e/testdata/fn-eval/include-meta-resources/.expected/config.yaml index 377e9fd8c1..63e976d46b 100644 --- a/e2e/testdata/fn-eval/include-meta-resources/.expected/config.yaml +++ b/e2e/testdata/fn-eval/include-meta-resources/.expected/config.yaml @@ -14,7 +14,7 @@ runCount: 2 testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest includeMetaResources: true exitCode: 1 args: diff --git a/e2e/testdata/fn-eval/invalid-fn-config-file/pkg/.expected/config.yaml b/e2e/testdata/fn-eval/invalid-fn-config-file/pkg/.expected/config.yaml index b8bd60d8a4..fc96a355dd 100644 --- a/e2e/testdata/fn-eval/invalid-fn-config-file/pkg/.expected/config.yaml +++ b/e2e/testdata/fn-eval/invalid-fn-config-file/pkg/.expected/config.yaml @@ -14,6 +14,6 @@ testType: eval exitCode: 1 -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest fnConfig: ../../config.yaml stdErr: "wrong node kind: expected MappingNode but got ScalarNode: node contents:\nI am not a valid config file\n" diff --git a/e2e/testdata/fn-eval/missing-fn-config/.expected/config.yaml b/e2e/testdata/fn-eval/missing-fn-config/.expected/config.yaml index a4babc9a30..6f67004bba 100644 --- a/e2e/testdata/fn-eval/missing-fn-config/.expected/config.yaml +++ b/e2e/testdata/fn-eval/missing-fn-config/.expected/config.yaml @@ -14,5 +14,5 @@ testType: eval exitCode: 1 -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest stdErr: "failed to configure function: input namespace cannot be empty" diff --git a/e2e/testdata/fn-eval/missing-fn-config/.expected/diff.patch b/e2e/testdata/fn-eval/missing-fn-config/.expected/diff.patch new file mode 100644 index 0000000000..c6f4cee599 --- /dev/null +++ b/e2e/testdata/fn-eval/missing-fn-config/.expected/diff.patch @@ -0,0 +1,57 @@ +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-eval/multiple-fn-config-one-file/pkg/.expected/config.yaml b/e2e/testdata/fn-eval/multiple-fn-config-one-file/pkg/.expected/config.yaml index cb95e80324..853cc5535b 100644 --- a/e2e/testdata/fn-eval/multiple-fn-config-one-file/pkg/.expected/config.yaml +++ b/e2e/testdata/fn-eval/multiple-fn-config-one-file/pkg/.expected/config.yaml @@ -13,7 +13,7 @@ # limitations under the License. testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest fnConfig: ../../config.yaml exitCode: 1 stdErr: "must not contain more than one config, got 2" diff --git a/e2e/testdata/fn-eval/no-op/.expected/diff.patch b/e2e/testdata/fn-eval/no-op/.expected/diff.patch new file mode 100644 index 0000000000..d8c21c2859 --- /dev/null +++ b/e2e/testdata/fn-eval/no-op/.expected/diff.patch @@ -0,0 +1,169 @@ +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-eval/non-krm-resource/.expected/config.yaml b/e2e/testdata/fn-eval/non-krm-resource/.expected/config.yaml index 4a532c5db9..6f0f4278c8 100644 --- a/e2e/testdata/fn-eval/non-krm-resource/.expected/config.yaml +++ b/e2e/testdata/fn-eval/non-krm-resource/.expected/config.yaml @@ -13,10 +13,10 @@ # limitations under the License. testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest args: namespace: staging exitCode: 1 stdErr: | - [FAIL] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" in 0s + [FAIL] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s error: input resource list must contain only KRM resources: nonkrm.yaml: resource must have `apiVersion` diff --git a/e2e/testdata/fn-eval/out-of-place-dir/.expected/config.yaml b/e2e/testdata/fn-eval/out-of-place-dir/.expected/config.yaml index 0b1837e3f3..fed31a7989 100644 --- a/e2e/testdata/fn-eval/out-of-place-dir/.expected/config.yaml +++ b/e2e/testdata/fn-eval/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-eval/out-of-place-fnchain-stdout/.expected/config.yaml b/e2e/testdata/fn-eval/out-of-place-fnchain-stdout/.expected/config.yaml index 9974ae4b79..52324bac8e 100644 --- a/e2e/testdata/fn-eval/out-of-place-fnchain-stdout/.expected/config.yaml +++ b/e2e/testdata/fn-eval/out-of-place-fnchain-stdout/.expected/config.yaml @@ -6,8 +6,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 [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] spec.template.metadata.annotations: set annotations: {"foo":"bar"}, [info] metadata.annotations: set annotations: {"foo":"bar"} @@ -67,7 +67,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-eval/out-of-place-fnchain-unwrap/.expected/config.yaml b/e2e/testdata/fn-eval/out-of-place-fnchain-unwrap/.expected/config.yaml index d3f1e7360f..6ab4ff020c 100644 --- a/e2e/testdata/fn-eval/out-of-place-fnchain-unwrap/.expected/config.yaml +++ b/e2e/testdata/fn-eval/out-of-place-fnchain-unwrap/.expected/config.yaml @@ -20,8 +20,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 [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"} diff --git a/e2e/testdata/fn-eval/output-to-stdout/.expected/config.yaml b/e2e/testdata/fn-eval/output-to-stdout/.expected/config.yaml index de17b3ee69..6c22467c6a 100644 --- a/e2e/testdata/fn-eval/output-to-stdout/.expected/config.yaml +++ b/e2e/testdata/fn-eval/output-to-stdout/.expected/config.yaml @@ -52,6 +52,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-eval/preserve-comments/.expected/diff.patch b/e2e/testdata/fn-eval/preserve-comments/.expected/diff.patch new file mode 100644 index 0000000000..aa5bac2b61 --- /dev/null +++ b/e2e/testdata/fn-eval/preserve-comments/.expected/diff.patch @@ -0,0 +1,139 @@ +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-eval/preserve-order-include-meta-resources/.expected/config.yaml b/e2e/testdata/fn-eval/preserve-order-include-meta-resources/.expected/config.yaml index 577099f001..21110ef268 100644 --- a/e2e/testdata/fn-eval/preserve-order-include-meta-resources/.expected/config.yaml +++ b/e2e/testdata/fn-eval/preserve-order-include-meta-resources/.expected/config.yaml @@ -13,7 +13,7 @@ # limitations under the License. testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest includeMetaResources: true exitCode: 1 args: diff --git a/e2e/testdata/fn-eval/preserve-order-null-values/.expected/config.yaml b/e2e/testdata/fn-eval/preserve-order-null-values/.expected/config.yaml index e6e3bed593..eb0dfa04f8 100644 --- a/e2e/testdata/fn-eval/preserve-order-null-values/.expected/config.yaml +++ b/e2e/testdata/fn-eval/preserve-order-null-values/.expected/config.yaml @@ -13,6 +13,6 @@ # limitations under the License. testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest args: namespace: staging diff --git a/e2e/testdata/fn-eval/save-fn/custom-pkg-path/.expected/config.yaml b/e2e/testdata/fn-eval/save-fn/custom-pkg-path/.expected/config.yaml index 06a23be0c3..aa27fdc85e 100644 --- a/e2e/testdata/fn-eval/save-fn/custom-pkg-path/.expected/config.yaml +++ b/e2e/testdata/fn-eval/save-fn/custom-pkg-path/.expected/config.yaml @@ -18,12 +18,12 @@ stdErrStripLines: testType: eval -image: set-namespace:v0.2.0 +image: set-namespace:latest args: namespace: staging 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 - Added "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" as mutator in the Kptfile. + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s + Added "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" as mutator in the Kptfile. diff --git a/e2e/testdata/fn-eval/save-fn/image/.expected/config.yaml b/e2e/testdata/fn-eval/save-fn/image/.expected/config.yaml index 06a23be0c3..aa27fdc85e 100644 --- a/e2e/testdata/fn-eval/save-fn/image/.expected/config.yaml +++ b/e2e/testdata/fn-eval/save-fn/image/.expected/config.yaml @@ -18,12 +18,12 @@ stdErrStripLines: testType: eval -image: set-namespace:v0.2.0 +image: set-namespace:latest args: namespace: staging 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 - Added "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" as mutator in the Kptfile. + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s + Added "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" as mutator in the Kptfile. diff --git a/e2e/testdata/fn-eval/save-fn/match-selector/.expected/config.yaml b/e2e/testdata/fn-eval/save-fn/match-selector/.expected/config.yaml index 089c8b4566..3950ae0213 100644 --- a/e2e/testdata/fn-eval/save-fn/match-selector/.expected/config.yaml +++ b/e2e/testdata/fn-eval/save-fn/match-selector/.expected/config.yaml @@ -17,6 +17,6 @@ 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" on 1 resource(s) - [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" in 0s - Added "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" as mutator in the Kptfile. + [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 + Added "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" as mutator in the Kptfile. diff --git a/e2e/testdata/fn-eval/save-fn/no-save-when-fail/.expected/config.yaml b/e2e/testdata/fn-eval/save-fn/no-save-when-fail/.expected/config.yaml index e83f88abe8..c0e3f581fa 100644 --- a/e2e/testdata/fn-eval/save-fn/no-save-when-fail/.expected/config.yaml +++ b/e2e/testdata/fn-eval/save-fn/no-save-when-fail/.expected/config.yaml @@ -18,12 +18,12 @@ stdErrStripLines: testType: eval -image: set-namespace:v0.2.0 +image: set-namespace:latest args: namespace: staging 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 function not added: Kptfile not exists diff --git a/e2e/testdata/fn-eval/save-fn/override-fn/.expected/config.yaml b/e2e/testdata/fn-eval/save-fn/override-fn/.expected/config.yaml index 1ec3c82a08..c4344df5ea 100644 --- a/e2e/testdata/fn-eval/save-fn/override-fn/.expected/config.yaml +++ b/e2e/testdata/fn-eval/save-fn/override-fn/.expected/config.yaml @@ -18,12 +18,12 @@ stdErrStripLines: testType: eval -image: set-namespace:v0.2.0 +image: set-namespace:latest args: namespace: staging 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 - Updated "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" as mutator in the Kptfile. + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s + Updated "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" as mutator in the Kptfile. diff --git a/e2e/testdata/fn-eval/save-fn/preserve-kptfile-comments/.expected/config.yaml b/e2e/testdata/fn-eval/save-fn/preserve-kptfile-comments/.expected/config.yaml index 06a23be0c3..aa27fdc85e 100644 --- a/e2e/testdata/fn-eval/save-fn/preserve-kptfile-comments/.expected/config.yaml +++ b/e2e/testdata/fn-eval/save-fn/preserve-kptfile-comments/.expected/config.yaml @@ -18,12 +18,12 @@ stdErrStripLines: testType: eval -image: set-namespace:v0.2.0 +image: set-namespace:latest args: namespace: staging 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 - Added "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" as mutator in the Kptfile. + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s + Added "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" as mutator in the Kptfile. diff --git a/e2e/testdata/fn-eval/save-fn/preserve-kptfile-comments/.expected/diff.patch b/e2e/testdata/fn-eval/save-fn/preserve-kptfile-comments/.expected/diff.patch index b11dad7983..1815663355 100644 --- a/e2e/testdata/fn-eval/save-fn/preserve-kptfile-comments/.expected/diff.patch +++ b/e2e/testdata/fn-eval/save-fn/preserve-kptfile-comments/.expected/diff.patch @@ -30,4 +30,4 @@ index eed43d6..81473ca 100644 name: custom + namespace: staging spec: - image: nginx:1.2.3 + image: nginx:1.2.3 \ No newline at end of file diff --git a/e2e/testdata/fn-eval/save-fn/validator-type/.expected/config.yaml b/e2e/testdata/fn-eval/save-fn/validator-type/.expected/config.yaml index d62d1603c1..af337678c4 100644 --- a/e2e/testdata/fn-eval/save-fn/validator-type/.expected/config.yaml +++ b/e2e/testdata/fn-eval/save-fn/validator-type/.expected/config.yaml @@ -18,12 +18,12 @@ stdErrStripLines: testType: eval -image: set-namespace:v0.2.0 +image: set-namespace:latest args: namespace: staging 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 - Added "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" as validator in the Kptfile. + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s + Added "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" as validator in the Kptfile. diff --git a/e2e/testdata/fn-eval/selectors/basicpipeline/.expected/config.yaml b/e2e/testdata/fn-eval/selectors/basicpipeline/.expected/config.yaml index 4f41d86184..c77db4e32f 100644 --- a/e2e/testdata/fn-eval/selectors/basicpipeline/.expected/config.yaml +++ b/e2e/testdata/fn-eval/selectors/basicpipeline/.expected/config.yaml @@ -13,5 +13,5 @@ # limitations under the License. stdErr: | - [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 diff --git a/e2e/testdata/fn-eval/selectors/exclude/.expected/config.yaml b/e2e/testdata/fn-eval/selectors/exclude/.expected/config.yaml index 4f41d86184..c77db4e32f 100644 --- a/e2e/testdata/fn-eval/selectors/exclude/.expected/config.yaml +++ b/e2e/testdata/fn-eval/selectors/exclude/.expected/config.yaml @@ -13,5 +13,5 @@ # limitations under the License. stdErr: | - [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 diff --git a/e2e/testdata/fn-eval/selectors/out-of-place-fnchain-unwrap/.expected/config.yaml b/e2e/testdata/fn-eval/selectors/out-of-place-fnchain-unwrap/.expected/config.yaml index 8e7ba3ecd0..3f9b4db1c7 100644 --- a/e2e/testdata/fn-eval/selectors/out-of-place-fnchain-unwrap/.expected/config.yaml +++ b/e2e/testdata/fn-eval/selectors/out-of-place-fnchain-unwrap/.expected/config.yaml @@ -17,8 +17,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" 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-annotations:latest" on 1 resource(s) [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-annotations:latest" in 0s [Results]: [info] metadata.annotations: set annotations: {"foo":"bar"} diff --git a/e2e/testdata/fn-eval/selectors/selectors-with-exclude/.expected/config.yaml b/e2e/testdata/fn-eval/selectors/selectors-with-exclude/.expected/config.yaml index 4f41d86184..c77db4e32f 100644 --- a/e2e/testdata/fn-eval/selectors/selectors-with-exclude/.expected/config.yaml +++ b/e2e/testdata/fn-eval/selectors/selectors-with-exclude/.expected/config.yaml @@ -13,5 +13,5 @@ # limitations under the License. stdErr: | - [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 diff --git a/e2e/testdata/fn-eval/short-image-path/.expected/config.yaml b/e2e/testdata/fn-eval/short-image-path/.expected/config.yaml index ed37ade626..8cf6e1787d 100644 --- a/e2e/testdata/fn-eval/short-image-path/.expected/config.yaml +++ b/e2e/testdata/fn-eval/short-image-path/.expected/config.yaml @@ -17,11 +17,11 @@ actualStripLines: testType: eval -image: set-namespace:v0.2.0 +image: set-namespace:latest args: namespace: staging 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-eval/short-image-path/.expected/results.yaml b/e2e/testdata/fn-eval/short-image-path/.expected/results.yaml index 8708417d0d..d20fbc5b56 100755 --- a/e2e/testdata/fn-eval/short-image-path/.expected/results.yaml +++ b/e2e/testdata/fn-eval/short-image-path/.expected/results.yaml @@ -4,5 +4,5 @@ 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 diff --git a/e2e/testdata/fn-eval/simple-function-symlink/.expected/config.yaml b/e2e/testdata/fn-eval/simple-function-symlink/.expected/config.yaml index 71fe148636..50cb6a8da9 100644 --- a/e2e/testdata/fn-eval/simple-function-symlink/.expected/config.yaml +++ b/e2e/testdata/fn-eval/simple-function-symlink/.expected/config.yaml @@ -14,5 +14,5 @@ stdErr: |- [WARN] resolved symlink "new-link" to ".", please note that the symlinks within the package are ignored - [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" - [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" + [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" + [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" diff --git a/e2e/testdata/fn-eval/simple-function-with-tag/.expected/diff.patch b/e2e/testdata/fn-eval/simple-function-with-tag/.expected/diff.patch index f3518b8417..5371dee2ab 100644 --- a/e2e/testdata/fn-eval/simple-function-with-tag/.expected/diff.patch +++ b/e2e/testdata/fn-eval/simple-function-with-tag/.expected/diff.patch @@ -9,4 +9,4 @@ index 1f15150..5966859 100644 + namespace: staging spec: replicas: 3 - --- + --- \ No newline at end of file diff --git a/e2e/testdata/fn-eval/simple-function/.expected/config.yaml b/e2e/testdata/fn-eval/simple-function/.expected/config.yaml index e6e3bed593..eb0dfa04f8 100644 --- a/e2e/testdata/fn-eval/simple-function/.expected/config.yaml +++ b/e2e/testdata/fn-eval/simple-function/.expected/config.yaml @@ -13,6 +13,6 @@ # limitations under the License. testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest args: namespace: staging diff --git a/e2e/testdata/fn-eval/subpkg-exclude-fn-config-by-default/.expected/config.yaml b/e2e/testdata/fn-eval/subpkg-exclude-fn-config-by-default/.expected/config.yaml index e6e3bed593..eb0dfa04f8 100644 --- a/e2e/testdata/fn-eval/subpkg-exclude-fn-config-by-default/.expected/config.yaml +++ b/e2e/testdata/fn-eval/subpkg-exclude-fn-config-by-default/.expected/config.yaml @@ -13,6 +13,6 @@ # limitations under the License. testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest args: namespace: staging diff --git a/e2e/testdata/fn-eval/subpkg-has-samename-subdir/.expected/config.yaml b/e2e/testdata/fn-eval/subpkg-has-samename-subdir/.expected/config.yaml index 47844502bf..72644e4089 100644 --- a/e2e/testdata/fn-eval/subpkg-has-samename-subdir/.expected/config.yaml +++ b/e2e/testdata/fn-eval/subpkg-has-samename-subdir/.expected/config.yaml @@ -13,6 +13,6 @@ # limitations under the License. testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest args: namespace: dev diff --git a/e2e/testdata/fn-eval/subpkg-include-meta-resources/.expected/config.yaml b/e2e/testdata/fn-eval/subpkg-include-meta-resources/.expected/config.yaml index 377e9fd8c1..63e976d46b 100644 --- a/e2e/testdata/fn-eval/subpkg-include-meta-resources/.expected/config.yaml +++ b/e2e/testdata/fn-eval/subpkg-include-meta-resources/.expected/config.yaml @@ -14,7 +14,7 @@ runCount: 2 testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest includeMetaResources: true exitCode: 1 args: diff --git a/e2e/testdata/fn-eval/subpkgs-with-krmignore/.expected/config.yaml b/e2e/testdata/fn-eval/subpkgs-with-krmignore/.expected/config.yaml index e6e3bed593..eb0dfa04f8 100644 --- a/e2e/testdata/fn-eval/subpkgs-with-krmignore/.expected/config.yaml +++ b/e2e/testdata/fn-eval/subpkgs-with-krmignore/.expected/config.yaml @@ -13,6 +13,6 @@ # limitations under the License. testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest args: namespace: staging diff --git a/e2e/testdata/fn-eval/subpkgs/.expected/config.yaml b/e2e/testdata/fn-eval/subpkgs/.expected/config.yaml index e6e3bed593..eb0dfa04f8 100644 --- a/e2e/testdata/fn-eval/subpkgs/.expected/config.yaml +++ b/e2e/testdata/fn-eval/subpkgs/.expected/config.yaml @@ -13,6 +13,6 @@ # limitations under the License. testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0 +image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest args: namespace: staging diff --git a/e2e/testdata/fn-eval/wasm-function/.expected/config.yaml b/e2e/testdata/fn-eval/wasm-function/.expected/config.yaml index 2473a37ea2..15907fa66c 100644 --- a/e2e/testdata/fn-eval/wasm-function/.expected/config.yaml +++ b/e2e/testdata/fn-eval/wasm-function/.expected/config.yaml @@ -13,7 +13,8 @@ # limitations under the License. testType: eval -image: ghcr.io/kptdev/krm-functions-catalog/wasm/set-namespace:v0.5.1 +#image: ghcr.io/kptdev/krm-functions-catalog/wasm/set-namespace:latest +image: gcr.io/kpt-fn-demo/set-namespace:latest args: namespace: staging allowWasm: true diff --git a/internal/fnruntime/jsglue.go b/internal/fnruntime/jsglue.go index ddbd7a7df3..e95b4ac5ca 100644 --- a/internal/fnruntime/jsglue.go +++ b/internal/fnruntime/jsglue.go @@ -234,7 +234,7 @@ const crypto = require('crypto'); } const timeOrigin = Date.now() - performance.now(); this.importObject = { - gojs: { + go: { // Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters) // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function). @@ -456,8 +456,6 @@ const crypto = require('crypto'); }, } }; - // Expose imports under both "gojs" (Go 1.21+) and "go" (Go <1.21) - this.importObject.go = this.importObject.gojs; } async run(instance) { if (!(instance instanceof WebAssembly.Instance)) { diff --git a/internal/fnruntime/runner_test.go b/internal/fnruntime/runner_test.go index 3c22980e4a..ef1225b71b 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" @@ -87,7 +87,7 @@ data: {foo: bar} assert.NoError(t, err, "unexpected error") _, err = tmp.WriteString(c.configFileContent) assert.NoError(t, err, "unexpected error") - c.fn.ConfigPath = path.Base(tmp.Name()) + c.fn.ConfigPath = filepath.Base(tmp.Name()) } fsys := filesys.MakeFsOnDisk() cn, err := newFnConfig(fsys, &c.fn, types.UniquePath(os.TempDir())) diff --git a/internal/kptops/set-namespace.go b/internal/kptops/set-namespace.go index 400b8557d9..7f31c941a1 100644 --- a/internal/kptops/set-namespace.go +++ b/internal/kptops/set-namespace.go @@ -16,8 +16,10 @@ package kptops import ( "fmt" + "strings" "sigs.k8s.io/kustomize/kyaml/fn/framework" + "sigs.k8s.io/kustomize/kyaml/yaml" ) // Simple implementation of set-namespace kpt function, primarily for testing. @@ -41,6 +43,9 @@ func setNamespace(rl *framework.ResourceList) error { } for _, n := range rl.Items { + if isUnknown(n) && n.GetNamespace() == "" { + continue + } if err := n.SetNamespace(namespace); err != nil { return err } @@ -48,3 +53,22 @@ func setNamespace(rl *framework.ResourceList) error { return nil } + +func isUnknown(n *yaml.RNode) bool { + apiVersion := n.GetApiVersion() + group := "" + if i := strings.Index(apiVersion, "/"); i != -1 { + group = apiVersion[:i] + } + // Heuristic: standard Kubernetes API groups either have no dots in the group + // name (e.g., "", "apps", "batch", "autoscaling", "extensions", "policy", + // "storage") or end in ".k8s.io" (e.g., "networking.k8s.io"). + // Custom Resources (CRs) have groups with dots that don't end in ".k8s.io" + // (e.g., "custom.io", "stable.example.com"). + if group == "" || !strings.Contains(group, ".") || strings.HasSuffix(group, ".k8s.io") { + return false + } + return true +} + +