Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Oct 6, 2021
1 parent 4f3db3c commit 2a73a75
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/x.yaml b/y.yaml
similarity index 100%
rename from x.yaml
rename to y.yaml
index 7a494c9..e284e52 100644
--- 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 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,10 +24,3 @@ metadata:
name: nginx-deployment
spec:
replicas: 3
----
-apiVersion: custom.io/v1
-kind: Custom
-metadata:
- name: custom
-spec:
- image: nginx:1.2.3
1 change: 1 addition & 0 deletions e2e/testdata/fn-render/mutate-legacy-path-index/.krmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.expected
8 changes: 8 additions & 0 deletions e2e/testdata/fn-render/mutate-legacy-path-index/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: app
pipeline:
mutators:
- image: gcr.io/kpt-fn/starlark:v0.2.1
configPath: starlark-mutate-path-index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2021 Google LLC
#
# 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: |-
def change_path_index(resources):
for r in resources:
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"])
26 changes: 26 additions & 0 deletions e2e/testdata/fn-render/mutate-legacy-path-index/x.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2021 Google LLC
#
# 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
29 changes: 29 additions & 0 deletions e2e/testdata/fn-render/mutate-path-index/.expected/diff.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/x.yaml b/y.yaml
similarity index 100%
rename from x.yaml
rename to y.yaml
index 7a494c9..e284e52 100644
--- 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 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,10 +24,3 @@ metadata:
name: nginx-deployment
spec:
replicas: 3
----
-apiVersion: custom.io/v1
-kind: Custom
-metadata:
- name: custom
-spec:
- image: nginx:1.2.3
1 change: 1 addition & 0 deletions e2e/testdata/fn-render/mutate-path-index/.krmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.expected
8 changes: 8 additions & 0 deletions e2e/testdata/fn-render/mutate-path-index/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: app
pipeline:
mutators:
- image: gcr.io/kpt-fn/starlark:v0.2.1
configPath: starlark-mutate-path-index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2021 Google LLC
#
# 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: |-
def change_path_index(resources):
for r in resources:
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"])
26 changes: 26 additions & 0 deletions e2e/testdata/fn-render/mutate-path-index/x.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2021 Google LLC
#
# 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

0 comments on commit 2a73a75

Please sign in to comment.