Skip to content

Commit 974dd0a

Browse files
Sink should create dir, update docs for output flag of eval, render (#2215)
* Sink should create dir, update docs for output flag of eval, render * Reconcile e2e tests * Fix oop tests * fix test * Error if directory already exists * Fix e2e tests * Add more e2e tests * Update book * Make directory check preRun * Update generated docs * Update r.dest * Update hydrated name * Separate sink tests
1 parent 95c5019 commit 974dd0a

File tree

45 files changed

+566
-227
lines changed

Some content is hidden

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

45 files changed

+566
-227
lines changed

e2e/fn_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func TestFnEval(t *testing.T) {
3131
runAllTests(t, filepath.Join(".", "testdata", "fn-eval"))
3232
}
3333

34+
func TestFnSink(t *testing.T) {
35+
runAllTests(t, filepath.Join(".", "testdata", "fn-sink"))
36+
}
37+
3438
// runTests will scan test cases in 'path', run the command
3539
// on all of the packages in path, and test that
3640
// the diff between the results and the original package is as
Lines changed: 32 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,34 @@
1-
diff --git a/Kptfile b/Kptfile
2-
deleted file mode 100644
3-
index 39dec05..0000000
4-
--- a/Kptfile
5-
+++ /dev/null
6-
@@ -1,8 +0,0 @@
7-
-apiVersion: kpt.dev/v1alpha2
8-
-kind: Kptfile
9-
-metadata:
10-
- name: app
11-
-pipeline:
12-
- mutators:
13-
- - image: gcr.io/kpt-fn/set-labels:v0.1.4
14-
- configPath: labelconfig.yaml
15-
diff --git a/labelconfig.yaml b/labelconfig.yaml
16-
deleted file mode 100644
17-
index 7ef9890..0000000
18-
--- a/labelconfig.yaml
19-
+++ /dev/null
20-
@@ -1,19 +0,0 @@
21-
-# Copyright 2021 Google LLC
22-
-#
23-
-# Licensed under the Apache License, Version 2.0 (the "License");
24-
-# you may not use this file except in compliance with the License.
25-
-# You may obtain a copy of the License at
26-
-#
27-
-# http://www.apache.org/licenses/LICENSE-2.0
28-
-#
29-
-# Unless required by applicable law or agreed to in writing, software
30-
-# distributed under the License is distributed on an "AS IS" BASIS,
31-
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32-
-# See the License for the specific language governing permissions and
33-
-# limitations under the License.
34-
-apiVersion: v1
35-
-kind: ConfigMap
36-
-metadata:
37-
- name: label-config
38-
-data:
39-
- tier: app
40-
diff --git a/resources.yaml b/resources.yaml
41-
index 7a494c9..254b9cd 100644
42-
--- a/resources.yaml
43-
+++ b/resources.yaml
44-
@@ -15,6 +15,7 @@ apiVersion: apps/v1
45-
kind: Deployment
46-
metadata:
47-
name: nginx-deployment
1+
diff --git a/out/resources.yaml b/out/resources.yaml
2+
new file mode 100644
3+
index 0000000..254b9cd
4+
--- /dev/null
5+
+++ b/out/resources.yaml
6+
@@ -0,0 +1,28 @@
7+
+# Copyright 2021 Google LLC
8+
+#
9+
+# Licensed under the Apache License, Version 2.0 (the "License");
10+
+# you may not use this file except in compliance with the License.
11+
+# You may obtain a copy of the License at
12+
+#
13+
+# http://www.apache.org/licenses/LICENSE-2.0
14+
+#
15+
+# Unless required by applicable law or agreed to in writing, software
16+
+# distributed under the License is distributed on an "AS IS" BASIS,
17+
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
+# See the License for the specific language governing permissions and
19+
+# limitations under the License.
20+
+apiVersion: apps/v1
21+
+kind: Deployment
22+
+metadata:
23+
+ name: nginx-deployment
4824
+ namespace: staging
49-
spec:
50-
replicas: 3
51-
---
52-
@@ -22,5 +23,6 @@ apiVersion: custom.io/v1
53-
kind: Custom
54-
metadata:
55-
name: custom
25+
+spec:
26+
+ replicas: 3
27+
+---
28+
+apiVersion: custom.io/v1
29+
+kind: Custom
30+
+metadata:
31+
+ name: custom
5632
+ namespace: staging
57-
spec:
58-
image: nginx:1.2.3
33+
+spec:
34+
+ image: nginx:1.2.3

e2e/testdata/fn-eval/fn-source/exclude-meta-resources-by-default-out-of-place/.expected/exec.sh

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,8 @@
1515

1616
set -eo pipefail
1717

18-
# create a temporary directory
19-
TEMP_DIR=$(mktemp -d)
18+
rm -rf out
2019

2120
kpt fn source\
2221
| kpt fn eval - --image gcr.io/kpt-fn/set-namespace:v0.1.3 -- namespace=staging \
23-
| kpt fn sink $TEMP_DIR
24-
25-
# copy back the resources
26-
rm -r ./*
27-
cp $TEMP_DIR/* .
28-
29-
# remove temporary directory
30-
rm -r $TEMP_DIR
22+
| kpt fn sink out
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.expected
2+
out
Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
1-
diff --git a/resources.yaml b/resources.yaml
2-
index 7a494c9..254b9cd 100644
3-
--- a/resources.yaml
4-
+++ b/resources.yaml
5-
@@ -15,6 +15,7 @@ apiVersion: apps/v1
6-
kind: Deployment
7-
metadata:
8-
name: nginx-deployment
1+
diff --git a/out/resources.yaml b/out/resources.yaml
2+
new file mode 100644
3+
index 0000000..254b9cd
4+
--- /dev/null
5+
+++ b/out/resources.yaml
6+
@@ -0,0 +1,28 @@
7+
+# Copyright 2021 Google LLC
8+
+#
9+
+# Licensed under the Apache License, Version 2.0 (the "License");
10+
+# you may not use this file except in compliance with the License.
11+
+# You may obtain a copy of the License at
12+
+#
13+
+# http://www.apache.org/licenses/LICENSE-2.0
14+
+#
15+
+# Unless required by applicable law or agreed to in writing, software
16+
+# distributed under the License is distributed on an "AS IS" BASIS,
17+
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
+# See the License for the specific language governing permissions and
19+
+# limitations under the License.
20+
+apiVersion: apps/v1
21+
+kind: Deployment
22+
+metadata:
23+
+ name: nginx-deployment
924
+ namespace: staging
10-
spec:
11-
replicas: 3
12-
---
13-
@@ -22,5 +23,6 @@ apiVersion: custom.io/v1
14-
kind: Custom
15-
metadata:
16-
name: custom
25+
+spec:
26+
+ replicas: 3
27+
+---
28+
+apiVersion: custom.io/v1
29+
+kind: Custom
30+
+metadata:
31+
+ name: custom
1732
+ namespace: staging
18-
spec:
19-
image: nginx:1.2.3
33+
+spec:
34+
+ image: nginx:1.2.3

e2e/testdata/fn-eval/fn-source/exclude-meta-resources-by-default/.expected/exec.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
set -eo pipefail
1717

18+
rm -rf out
19+
1820
kpt fn source \
1921
| kpt fn eval - --image gcr.io/kpt-fn/set-namespace:v0.1.3 -- namespace=staging \
20-
| kpt fn sink
22+
| kpt fn sink out
Lines changed: 71 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,75 @@
1-
diff --git a/Kptfile b/Kptfile
2-
index 39dec05..47f7bf4 100644
3-
--- a/Kptfile
4-
+++ b/Kptfile
5-
@@ -2,6 +2,7 @@ apiVersion: kpt.dev/v1alpha2
6-
kind: Kptfile
7-
metadata:
8-
name: app
1+
diff --git a/out/Kptfile b/out/Kptfile
2+
new file mode 100644
3+
index 0000000..47f7bf4
4+
--- /dev/null
5+
+++ b/out/Kptfile
6+
@@ -0,0 +1,9 @@
7+
+apiVersion: kpt.dev/v1alpha2
8+
+kind: Kptfile
9+
+metadata:
10+
+ name: app
911
+ namespace: staging
10-
pipeline:
11-
mutators:
12-
- image: gcr.io/kpt-fn/set-labels:v0.1.4
13-
diff --git a/labelconfig.yaml b/labelconfig.yaml
14-
index 7ef9890..f3a8b49 100644
15-
--- a/labelconfig.yaml
16-
+++ b/labelconfig.yaml
17-
@@ -15,5 +15,6 @@ apiVersion: v1
18-
kind: ConfigMap
19-
metadata:
20-
name: label-config
12+
+pipeline:
13+
+ mutators:
14+
+ - image: gcr.io/kpt-fn/set-labels:v0.1.4
15+
+ configPath: labelconfig.yaml
16+
diff --git a/out/labelconfig.yaml b/out/labelconfig.yaml
17+
new file mode 100644
18+
index 0000000..f3a8b49
19+
--- /dev/null
20+
+++ b/out/labelconfig.yaml
21+
@@ -0,0 +1,20 @@
22+
+# Copyright 2021 Google LLC
23+
+#
24+
+# Licensed under the Apache License, Version 2.0 (the "License");
25+
+# you may not use this file except in compliance with the License.
26+
+# You may obtain a copy of the License at
27+
+#
28+
+# http://www.apache.org/licenses/LICENSE-2.0
29+
+#
30+
+# Unless required by applicable law or agreed to in writing, software
31+
+# distributed under the License is distributed on an "AS IS" BASIS,
32+
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33+
+# See the License for the specific language governing permissions and
34+
+# limitations under the License.
35+
+apiVersion: v1
36+
+kind: ConfigMap
37+
+metadata:
38+
+ name: label-config
2139
+ namespace: staging
22-
data:
23-
tier: app
24-
diff --git a/resources.yaml b/resources.yaml
25-
index 7a494c9..254b9cd 100644
26-
--- a/resources.yaml
27-
+++ b/resources.yaml
28-
@@ -15,6 +15,7 @@ apiVersion: apps/v1
29-
kind: Deployment
30-
metadata:
31-
name: nginx-deployment
40+
+data:
41+
+ tier: app
42+
diff --git a/out/resources.yaml b/out/resources.yaml
43+
new file mode 100644
44+
index 0000000..254b9cd
45+
--- /dev/null
46+
+++ b/out/resources.yaml
47+
@@ -0,0 +1,28 @@
48+
+# Copyright 2021 Google LLC
49+
+#
50+
+# Licensed under the Apache License, Version 2.0 (the "License");
51+
+# you may not use this file except in compliance with the License.
52+
+# You may obtain a copy of the License at
53+
+#
54+
+# http://www.apache.org/licenses/LICENSE-2.0
55+
+#
56+
+# Unless required by applicable law or agreed to in writing, software
57+
+# distributed under the License is distributed on an "AS IS" BASIS,
58+
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
59+
+# See the License for the specific language governing permissions and
60+
+# limitations under the License.
61+
+apiVersion: apps/v1
62+
+kind: Deployment
63+
+metadata:
64+
+ name: nginx-deployment
3265
+ namespace: staging
33-
spec:
34-
replicas: 3
35-
---
36-
@@ -22,5 +23,6 @@ apiVersion: custom.io/v1
37-
kind: Custom
38-
metadata:
39-
name: custom
66+
+spec:
67+
+ replicas: 3
68+
+---
69+
+apiVersion: custom.io/v1
70+
+kind: Custom
71+
+metadata:
72+
+ name: custom
4073
+ namespace: staging
41-
spec:
42-
image: nginx:1.2.3
74+
+spec:
75+
+ image: nginx:1.2.3

e2e/testdata/fn-eval/fn-source/include-meta-resource-out-of-place/.expected/exec.sh

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,8 @@
1515

1616
set -eo pipefail
1717

18-
# create a temporary directory
19-
TEMP_DIR=$(mktemp -d)
18+
rm -rf out
2019

2120
kpt fn source --include-meta-resources\
2221
| kpt fn eval - --image gcr.io/kpt-fn/set-namespace:v0.1.3 -- namespace=staging \
23-
| kpt fn sink $TEMP_DIR
24-
25-
# copy back the resources
26-
rm -r ./*
27-
cp $TEMP_DIR/* .
28-
29-
# remove temporary directory
30-
rm -r $TEMP_DIR
22+
| kpt fn sink out
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.expected
2+
out

0 commit comments

Comments
 (0)