Skip to content

Commit

Permalink
add tests to exercise modify path annotation (#2586)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mengqi Yu committed Nov 16, 2021
1 parent 9a88ae7 commit 1ebda55
Show file tree
Hide file tree
Showing 20 changed files with 264 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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.

testType: eval
image: gcr.io/kpt-fn/starlark:v0.3
fnConfig: ../starlark-fn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
diff --git a/deployment.yaml b/newfilename.yaml
similarity index 100%
rename from deployment.yaml
rename to newfilename.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.expected
35 changes: 35 additions & 0 deletions e2e/testdata/fn-eval/modify-legacy-path-annotation/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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:
labels:
foo: bar
name: my-nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx:1.14.2
name: nginx
ports:
- containerPort: 80
protocol: TCP
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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: update-path
source: |
for r in ctx.resource_list["items"]:
if r["kind"] == "Deployment":
r["metadata"]["annotations"]["config.kubernetes.io/path"] = "newfilename.yaml"
17 changes: 17 additions & 0 deletions e2e/testdata/fn-eval/modify-path-annotation/.expected/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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.

testType: eval
image: gcr.io/kpt-fn/starlark:v0.3
fnConfig: ../starlark-fn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
diff --git a/deployment.yaml b/newfilename.yaml
similarity index 100%
rename from deployment.yaml
rename to newfilename.yaml
1 change: 1 addition & 0 deletions e2e/testdata/fn-eval/modify-path-annotation/.krmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.expected
35 changes: 35 additions & 0 deletions e2e/testdata/fn-eval/modify-path-annotation/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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:
labels:
foo: bar
name: my-nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx:1.14.2
name: nginx
ports:
- containerPort: 80
protocol: TCP
21 changes: 21 additions & 0 deletions e2e/testdata/fn-eval/modify-path-annotation/starlark-fn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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: update-path
source: |
for r in ctx.resource_list["items"]:
if r["kind"] == "Deployment":
r["metadata"]["annotations"]["internal.config.kubernetes.io/path"] = "newfilename.yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
diff --git a/deployment.yaml b/newfilename.yaml
similarity index 100%
rename from deployment.yaml
rename to newfilename.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.expected
8 changes: 8 additions & 0 deletions e2e/testdata/fn-render/modify-legacy-path-annotation/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.3.0
configPath: starlark-fn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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: update-path
source: |
for r in ctx.resource_list["items"]:
if r["kind"] == "Deployment":
r["metadata"]["annotations"]["config.kubernetes.io/path"] = "newfilename.yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
diff --git a/deployment.yaml b/newfilename.yaml
similarity index 100%
rename from deployment.yaml
rename to newfilename.yaml
1 change: 1 addition & 0 deletions e2e/testdata/fn-render/modify-path-annotation/.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/modify-path-annotation/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.3.0
configPath: starlark-fn.yaml
19 changes: 19 additions & 0 deletions e2e/testdata/fn-render/modify-path-annotation/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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
22 changes: 22 additions & 0 deletions e2e/testdata/fn-render/modify-path-annotation/starlark-fn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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: update-path
source: |
for r in ctx.resource_list["items"]:
if r["kind"] == "Deployment":
r["metadata"]["annotations"]["internal.config.kubernetes.io/path"] = "newfilename.yaml"

0 comments on commit 1ebda55

Please sign in to comment.