Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Oct 13, 2021
1 parent 4f3db3c commit 60d2b11
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 3 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ require (
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9
sigs.k8s.io/cli-utils v0.25.1-0.20210702190410-c1a7c2d0409d
sigs.k8s.io/kustomize/api v0.8.10
sigs.k8s.io/kustomize/kyaml v0.12.0
sigs.k8s.io/kustomize/kyaml v0.12.1-0.20211012224254-55ac9ca88db9
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -999,8 +999,8 @@ sigs.k8s.io/kustomize/cmd/config v0.9.10/go.mod h1:Mrby0WnRH7hA6OwOYnYpfpiY0WJIM
sigs.k8s.io/kustomize/kustomize/v4 v4.1.2/go.mod h1:PxBvo4WGYlCLeRPL+ziT64wBXqbgfcalOS/SXa/tcyo=
sigs.k8s.io/kustomize/kyaml v0.10.17/go.mod h1:mlQFagmkm1P+W4lZJbJ/yaxMd8PqMRSC4cPcfUVt5Hg=
sigs.k8s.io/kustomize/kyaml v0.10.20/go.mod h1:TYWhGwW9vjoRh3rWqBwB/ZOXyEGRVWe7Ggc3+KZIO+c=
sigs.k8s.io/kustomize/kyaml v0.12.0 h1:k08l8SLwnKa/eXXB5GW2/OnEc/4gJF90VDFebsOwqw4=
sigs.k8s.io/kustomize/kyaml v0.12.0/go.mod h1:FTJxEZ86ScK184NpGSAQcfEqee0nul8oLCK30D47m4E=
sigs.k8s.io/kustomize/kyaml v0.12.1-0.20211012224254-55ac9ca88db9 h1:YsD7ModmQptMeuSZW/ZOeV2/LLQaOYNUA3sx3yZQTa0=
sigs.k8s.io/kustomize/kyaml v0.12.1-0.20211012224254-55ac9ca88db9/go.mod h1:FTJxEZ86ScK184NpGSAQcfEqee0nul8oLCK30D47m4E=
sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
sigs.k8s.io/structured-merge-diff/v4 v4.1.0 h1:C4r9BgJ98vrKnnVCjwCSXcWjWe0NKcUQkmzDXZXGwH8=
sigs.k8s.io/structured-merge-diff/v4 v4.1.0/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
Expand Down

0 comments on commit 60d2b11

Please sign in to comment.