Skip to content

Commit e25b507

Browse files
test(fn-render): update fn render E2E tests to use :latest set-namespace
This PR updates the kpt fn render 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 pipeline references from pinned set-namespace image tags to :latest (ghcr.io/kptdev/krm-functions/set-namespace:latest) - Update .expected/ golden files and diff.patch 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 and internal/util/render/executor_test.go Part 2 of 2 from the original PR #4420 (fn-render portion). Signed-off-by: Surbhi <agarwalsurbhi1807@gmail.com>
1 parent bebee38 commit e25b507

149 files changed

Lines changed: 7377 additions & 2478 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Set default behavior to automatically normalize line endings
2+
* text=auto
3+
4+
# Force bash scripts to always use LF line endings
5+
*.sh text eol=lf
6+
7+
# Force batch scripts to always use CRLF line endings
8+
*.bat text eol=crlf
9+
*.cmd text eol=crlf

e2e/testdata/fn-render/all-resource-deletion/.expected/diff.patch

Lines changed: 78 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,92 @@
11
diff --git a/Kptfile b/Kptfile
2-
index 3c93e9e..fe0bc96 100644
2+
index 20fac6a..7f10467 100644
33
--- a/Kptfile
44
+++ b/Kptfile
5-
@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1
6-
kind: Kptfile
7-
metadata:
8-
name: app
9-
+ namespace: staging
5+
@@ -1,14 +1,16 @@
6+
-apiVersion: kpt.dev/v1
7+
-kind: Kptfile
8+
-metadata:
9+
- name: app
10+
-pipeline:
11+
- mutators:
12+
- - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest
13+
- configPath: delete-all.yaml
14+
- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest
15+
- configMap:
16+
- namespace: staging
17+
- - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5
18+
- configMap:
19+
- tier: backend
20+
+apiVersion: kpt.dev/v1
21+
+kind: Kptfile
22+
+metadata:
23+
+ name: app
1024
+ labels:
1125
+ tier: backend
12-
pipeline:
13-
mutators:
14-
- image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest
15-
@@ -12,3 +15,8 @@ pipeline:
16-
- image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5
17-
configMap:
18-
tier: backend
19-
+status:
20-
+ conditions:
21-
+ - type: Rendered
22-
+ status: "True"
23-
+ reason: RenderSuccess
26+
+pipeline:
27+
+ mutators:
28+
+ - image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest
29+
+ configPath: delete-all.yaml
30+
+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest
31+
+ configMap:
32+
+ namespace: staging
33+
+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5
34+
+ configMap:
35+
+ tier: backend
2436
diff --git a/delete-all.yaml b/delete-all.yaml
25-
index 3c86d8b..6754b0a 100644
37+
index 9ddbbe2..bea1693 100644
2638
--- a/delete-all.yaml
2739
+++ b/delete-all.yaml
28-
@@ -17,6 +17,9 @@ metadata:
29-
name: delete-all
30-
annotations:
31-
config.kubernetes.io/local-config: "true"
32-
+ namespace: staging
40+
@@ -1,22 +1,24 @@
41+
-# Copyright 2021 The kpt Authors
42+
-#
43+
-# Licensed under the Apache License, Version 2.0 (the "License");
44+
-# you may not use this file except in compliance with the License.
45+
-# You may obtain a copy of the License at
46+
-#
47+
-# http://www.apache.org/licenses/LICENSE-2.0
48+
-#
49+
-# Unless required by applicable law or agreed to in writing, software
50+
-# distributed under the License is distributed on an "AS IS" BASIS,
51+
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
52+
-# See the License for the specific language governing permissions and
53+
-# limitations under the License.
54+
-apiVersion: fn.kpt.dev/v1alpha1
55+
-kind: StarlarkRun
56+
-metadata:
57+
- name: delete-all
58+
- annotations:
59+
- config.kubernetes.io/local-config: "true"
60+
-source: |-
61+
- # delete all resources
62+
- ctx.resource_list["items"] = [x for x in ctx.resource_list["items"] if x["kind"] in ["Kptfile", "StarlarkRun"]]
63+
+# Copyright 2021 The kpt Authors
64+
+#
65+
+# Licensed under the Apache License, Version 2.0 (the "License");
66+
+# you may not use this file except in compliance with the License.
67+
+# You may obtain a copy of the License at
68+
+#
69+
+# http://www.apache.org/licenses/LICENSE-2.0
70+
+#
71+
+# Unless required by applicable law or agreed to in writing, software
72+
+# distributed under the License is distributed on an "AS IS" BASIS,
73+
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
74+
+# See the License for the specific language governing permissions and
75+
+# limitations under the License.
76+
+apiVersion: fn.kpt.dev/v1alpha1
77+
+kind: StarlarkRun
78+
+metadata:
79+
+ name: delete-all
80+
+ annotations:
81+
+ config.kubernetes.io/local-config: "true"
3382
+ labels:
3483
+ tier: backend
35-
source: |-
36-
# delete all resources
37-
ctx.resource_list["items"] = [x for x in ctx.resource_list["items"] if x["kind"] in ["Kptfile", "StarlarkRun"]]
84+
+source: |-
85+
+ # delete all resources
86+
+ ctx.resource_list["items"] = [x for x in ctx.resource_list["items"] if x["kind"] in ["Kptfile", "StarlarkRun"]]
3887
diff --git a/deployment.yaml b/deployment.yaml
3988
deleted file mode 100644
40-
index 990ca9b..0000000
89+
index 73d3f5e..0000000
4190
--- a/deployment.yaml
4291
+++ /dev/null
4392
@@ -1,24 +0,0 @@
@@ -67,7 +116,7 @@ index 990ca9b..0000000
67116
- image: kennethreitz/httpbin
68117
diff --git a/resources.yaml b/resources.yaml
69118
deleted file mode 100644
70-
index 239f0d6..0000000
119+
index 027731c..0000000
71120
--- a/resources.yaml
72121
+++ /dev/null
73122
@@ -1,19 +0,0 @@

e2e/testdata/fn-render/all-resource-deletion/Kptfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pipeline:
66
mutators:
77
- image: ghcr.io/kptdev/krm-functions-catalog/starlark:latest
88
configPath: delete-all.yaml
9-
- image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0
9+
- image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest
1010
configMap:
1111
namespace: staging
1212
- image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5

e2e/testdata/fn-render/basicpipeline-out-of-place/Kptfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: app
55
pipeline:
66
mutators:
7-
- image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0
7+
- image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest
88
configMap:
99
namespace: staging
1010
- image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5
Lines changed: 84 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,100 @@
11
diff --git a/Kptfile b/Kptfile
2-
index 2336da4..eae3be3 100644
2+
index 68ea4fc..85f42f5 100644
33
--- a/Kptfile
44
+++ b/Kptfile
5-
@@ -2,13 +2,20 @@ apiVersion: kpt.dev/v1
6-
kind: Kptfile
7-
metadata:
8-
name: app
9-
+ labels:
10-
+ tier: backend
11-
pipeline:
12-
mutators:
13-
- image: ghcr.io/kptdev/krm-functions-catalog/set-namespace
5+
@@ -1,14 +1,16 @@
6+
-apiVersion: kpt.dev/v1
7+
-kind: Kptfile
8+
-metadata:
9+
- name: app
10+
-pipeline:
11+
- mutators:
12+
- - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace
1413
- tag: "0.4.1 - 0.4.3"
15-
configMap:
16-
namespace: staging
17-
+ tag: 0.4.1 - 0.4.3
18-
- image: ghcr.io/kptdev/krm-functions-catalog/set-labels
14+
- configMap:
15+
- namespace: staging
16+
- - image: ghcr.io/kptdev/krm-functions-catalog/set-labels
1917
- tag: "~0.2"
20-
configMap:
21-
tier: backend
22-
+ tag: ~0.2
23-
+status:
24-
+ conditions:
25-
+ - type: Rendered
26-
+ status: "True"
27-
+ reason: RenderSuccess
18+
- configMap:
19+
- tier: backend
20+
+apiVersion: kpt.dev/v1
21+
+kind: Kptfile
22+
+metadata:
23+
+ name: app
24+
+ labels:
25+
+ tier: backend
26+
+pipeline:
27+
+ mutators:
28+
+ - image: ghcr.io/kptdev/krm-functions-catalog/set-namespace
29+
+ tag: "0.4.1 - 0.4.3"
30+
+ configMap:
31+
+ namespace: staging
32+
+ - image: ghcr.io/kptdev/krm-functions-catalog/set-labels
33+
+ tag: "~0.2"
34+
+ configMap:
35+
+ tier: backend
2836
diff --git a/resources.yaml b/resources.yaml
29-
index 1f15150..936d957 100644
37+
index ffbb3d7..936d957 100644
3038
--- a/resources.yaml
3139
+++ b/resources.yaml
32-
@@ -15,12 +15,20 @@ apiVersion: apps/v1
33-
kind: Deployment
34-
metadata:
35-
name: nginx-deployment
40+
@@ -1,26 +1,34 @@
41+
-# Copyright 2026 The kpt Authors
42+
-#
43+
-# Licensed under the Apache License, Version 2.0 (the "License");
44+
-# you may not use this file except in compliance with the License.
45+
-# You may obtain a copy of the License at
46+
-#
47+
-# http://www.apache.org/licenses/LICENSE-2.0
48+
-#
49+
-# Unless required by applicable law or agreed to in writing, software
50+
-# distributed under the License is distributed on an "AS IS" BASIS,
51+
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
52+
-# See the License for the specific language governing permissions and
53+
-# limitations under the License.
54+
-apiVersion: apps/v1
55+
-kind: Deployment
56+
-metadata:
57+
- name: nginx-deployment
58+
-spec:
59+
- replicas: 3
60+
----
61+
-apiVersion: custom.io/v1
62+
-kind: Custom
63+
-metadata:
64+
- name: custom
65+
-spec:
66+
- image: nginx:1.2.3
67+
+# Copyright 2026 The kpt Authors
68+
+#
69+
+# Licensed under the Apache License, Version 2.0 (the "License");
70+
+# you may not use this file except in compliance with the License.
71+
+# You may obtain a copy of the License at
72+
+#
73+
+# http://www.apache.org/licenses/LICENSE-2.0
74+
+#
75+
+# Unless required by applicable law or agreed to in writing, software
76+
+# distributed under the License is distributed on an "AS IS" BASIS,
77+
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
78+
+# See the License for the specific language governing permissions and
79+
+# limitations under the License.
80+
+apiVersion: apps/v1
81+
+kind: Deployment
82+
+metadata:
83+
+ name: nginx-deployment
3684
+ namespace: staging
3785
+ labels:
3886
+ tier: backend
39-
spec:
40-
replicas: 3
87+
+spec:
88+
+ replicas: 3
4189
+ selector:
4290
+ matchLabels:
4391
+ tier: backend
44-
---
45-
apiVersion: custom.io/v1
46-
kind: Custom
47-
metadata:
48-
name: custom
92+
+---
93+
+apiVersion: custom.io/v1
94+
+kind: Custom
95+
+metadata:
96+
+ name: custom
4997
+ labels:
5098
+ tier: backend
51-
spec:
52-
image: nginx:1.2.3
99+
+spec:
100+
+ image: nginx:1.2.3

e2e/testdata/fn-render/basicpipeline-symlink/.expected/config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ stdErrStripLines:
2222
stdErr: |-
2323
[WARN] resolved symlink "new-link" to ".", please note that the symlinks within the package are ignored
2424
Package: "basicpipeline-symlink"
25-
[RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0"
26-
[PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0" in 0s
25+
[RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest"
26+
[PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s
2727
[RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5"
2828
[PASS] "ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5" in 0s
2929
Successfully executed 2 function(s) in 1 package(s).

e2e/testdata/fn-render/basicpipeline-symlink/.expected/diff.patch

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/Kptfile b/Kptfile
2-
index 1307fb5..f645d75 100644
2+
index 1307fb5..3a2c718 100644
33
--- a/Kptfile
44
+++ b/Kptfile
55
@@ -2,6 +2,9 @@ apiVersion: kpt.dev/v1
@@ -12,15 +12,6 @@ index 1307fb5..f645d75 100644
1212
pipeline:
1313
mutators:
1414
- image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0
15-
@@ -10,3 +13,8 @@ pipeline:
16-
- image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5
17-
configMap:
18-
tier: backend
19-
+status:
20-
+ conditions:
21-
+ - type: Rendered
22-
+ status: "True"
23-
+ reason: RenderSuccess
2415
diff --git a/resources.yaml b/resources.yaml
2516
index f2eec52..84cfb26 100644
2617
--- a/resources.yaml

e2e/testdata/fn-render/basicpipeline-symlink/Kptfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: app
55
pipeline:
66
mutators:
7-
- image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0
7+
- image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest
88
configMap:
99
namespace: staging
1010
- image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5

e2e/testdata/fn-render/basicpipeline-v1alpha2/Kptfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: app
55
pipeline:
66
mutators:
7-
- image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:v0.2.0
7+
- image: ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest
88
configMap:
99
namespace: staging
1010
- image: ghcr.io/kptdev/krm-functions-catalog/set-labels:v0.1.5

e2e/testdata/fn-render/basicpipeline-wasm/.expected/diff.patch

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1-
diff --git a/Kptfile b/Kptfile
2-
index 17a7822..94b6f80 100644
3-
--- a/Kptfile
4-
+++ b/Kptfile
5-
@@ -12,3 +12,8 @@ pipeline:
6-
- image: ghcr.io/kptdev/krm-functions-catalog/wasm/set-labels:v0.2.4
7-
configMap:
8-
tier: backend
9-
+status:
10-
+ conditions:
11-
+ - type: Rendered
12-
+ status: "True"
13-
+ reason: RenderSuccess
141
diff --git a/resources.yaml b/resources.yaml
15-
index eed43d6..c1de2b0 100644
2+
index eed43d6..e76b00d 100644
163
--- a/resources.yaml
174
+++ b/resources.yaml
18-
@@ -15,12 +15,20 @@ apiVersion: apps/v1
5+
@@ -15,12 +15,24 @@ apiVersion: apps/v1
196
kind: Deployment
207
metadata:
218
name: nginx-deployment
@@ -27,6 +14,10 @@ index eed43d6..c1de2b0 100644
2714
+ selector:
2815
+ matchLabels:
2916
+ tier: backend
17+
+ template:
18+
+ metadata:
19+
+ labels:
20+
+ tier: backend
3021
---
3122
apiVersion: custom.io/v1
3223
kind: Custom

0 commit comments

Comments
 (0)