Skip to content

Commit

Permalink
Handle kpt fn behavior change (#796)
Browse files Browse the repository at this point in the history
* updated behavior and tests for ensure-name-substring

* adjusted fix-simple test to not specify include-meta-resources

* kubeval-simple: skip Kptfile validation

* adjusted starlark tests/examples to handle Kptfile and StarlarkRun files

* adjusted search-replace tests to match kpt behavior to include meta resources by default

* adjusted create-setters-simple test to match kpt behavior

* adjusted set-project-id to match the kpt fn behavior

* adjusted generate-kpt-pkg-docs-simple test to match kpt behavior

* adjusted set-annotations tests to match new kpt fn behavior

* adjusted set-labels test to match new kpt fn behavior

* adjusted the golden file for generate-folders function

* using kpt@main
  • Loading branch information
droot authored Apr 5, 2022
1 parent 9501ec9 commit e649e50
Show file tree
Hide file tree
Showing 33 changed files with 115 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
go-version: 1.17
- name: Install kpt
run: |
go install github.com/GoogleContainerTools/kpt@0faf830e9f0ca2742bf15f3bb4560763eaa5d489
go install github.com/GoogleContainerTools/kpt@main
- name: Build node and Go docker images
if: matrix.platform == 'ubuntu-latest'
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
set -eo pipefail

kpt fn eval -i gcr.io/kpt-fn-contrib/generate-kpt-pkg-docs:unstable --image-pull-policy never \
--include-meta-resources --mount type=bind,src="$(pwd)",dst=/tmp,rw=true --as-current-user -- readme-path=/tmp/GENERATED.md
--mount type=bind,src="$(pwd)",dst=/tmp,rw=true --as-current-user -- readme-path=/tmp/GENERATED.md
3 changes: 3 additions & 0 deletions examples/create-setters-simple/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ pipeline:
mutators:
- image: gcr.io/kpt-fn/create-setters:unstable
configPath: setters.yaml
selectors:
- kind: Deployment
- kind: MyKind
13 changes: 13 additions & 0 deletions examples/ensure-name-substring-advanced/.expected/diff.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
diff --git a/fn-config.yaml b/fn-config.yaml
index 12939e5..0ee2f64 100644
--- a/fn-config.yaml
+++ b/fn-config.yaml
@@ -1,7 +1,7 @@
apiVersion: fn.kpt.dev/v1alpha1
kind: EnsureNameSubstring
metadata:
- name: my-config
+ name: prod-my-config
additionalNameFields:
- kind: MyResource
group: dev.example.com
diff --git a/resources.yaml b/resources.yaml
index 8e037c3..ffd583b 100644
--- a/resources.yaml
Expand Down
1 change: 0 additions & 1 deletion examples/fix-simple/.expected/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
testType: eval
image: gcr.io/kpt-fn/fix:unstable
includeMetaResources: true
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
diff --git a/Kptfile b/Kptfile
index bfbf712..6dd3f52 100644
--- a/Kptfile
+++ b/Kptfile
@@ -4,4 +4,4 @@ metadata:
name: example
pipeline:
mutators:
- - image: gcr.io/kpt-fn/generate-folders:unstable
+ - image: 'gcr.io/kpt-fn/generate-folders:unstable'
diff --git a/folder_dev.team-2.yaml b/folder_dev.team-2.yaml
new file mode 100644
index 0000000..16b9af2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
diff --git a/Kptfile b/Kptfile
index bfbf712..6dd3f52 100644
--- a/Kptfile
+++ b/Kptfile
@@ -4,4 +4,4 @@ metadata:
name: example
pipeline:
mutators:
- - image: gcr.io/kpt-fn/generate-folders:unstable
+ - image: 'gcr.io/kpt-fn/generate-folders:unstable'
diff --git a/folder_dev.team-2.yaml b/folder_dev.team-2.yaml
new file mode 100644
index 0000000..16b9af2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
diff --git a/Kptfile b/Kptfile
index bfbf712..6dd3f52 100644
--- a/Kptfile
+++ b/Kptfile
@@ -4,4 +4,4 @@ metadata:
name: example
pipeline:
mutators:
- - image: gcr.io/kpt-fn/generate-folders:unstable
+ - image: 'gcr.io/kpt-fn/generate-folders:unstable'
diff --git a/folder_dev.team-2.yaml b/folder_dev.team-2.yaml
new file mode 100644
index 0000000..badf925
Expand Down
2 changes: 1 addition & 1 deletion examples/kubeval-simple/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pipeline:
- image: gcr.io/kpt-fn/kubeval:unstable
configMap:
strict: 'true'
skip_kinds: MyCustom
skip_kinds: MyCustom,Kptfile
3 changes: 3 additions & 0 deletions examples/set-annotations-advanced/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ pipeline:
mutators:
- image: gcr.io/kpt-fn/set-annotations:unstable
configPath: fn-config.yaml
selectors:
- kind: ConfigMap
- kind: MyResource
3 changes: 3 additions & 0 deletions examples/set-annotations-simple/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ pipeline:
configMap:
color: orange
fruit: apple
selectors:
- kind: ConfigMap
- kind: Namespace
3 changes: 3 additions & 0 deletions examples/set-labels-advanced/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ pipeline:
mutators:
- image: gcr.io/kpt-fn/set-labels:unstable
configPath: fn-config.yaml
selectors:
- kind: ConfigMap
- kind: MyResource
3 changes: 3 additions & 0 deletions examples/set-labels-simple/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ pipeline:
configMap:
color: orange
fruit: apple
selectors:
- kind: ConfigMap
- kind: MyResource
1 change: 0 additions & 1 deletion examples/set-project-id-advanced/.expected/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
testType: eval
includeMetaResources: true
image: gcr.io/kpt-fn/set-project-id:unstable
args:
project-id: foo
2 changes: 1 addition & 1 deletion examples/set-project-id-advanced/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/ex
Invoke the function with the following command:

```shell
kpt fn eval set-project-id-advanced --include-meta-resources --image gcr.io/kpt-fn/set-project-id:unstable -- 'project-id=foo'
kpt fn eval set-project-id-advanced --image gcr.io/kpt-fn/set-project-id:unstable -- 'project-id=foo'
```

### Expected result
Expand Down
1 change: 0 additions & 1 deletion examples/set-project-id-simple/.expected/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
testType: eval
includeMetaResources: true
image: gcr.io/kpt-fn/set-project-id:unstable
args:
project-id: foo
2 changes: 1 addition & 1 deletion examples/set-project-id-simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/ex
Invoke the function with the following command:

```shell
kpt fn eval set-project-id-simple --include-meta-resources --image gcr.io/kpt-fn/set-project-id:unstable -- 'project-id=foo'
kpt fn eval set-project-id-simple --image gcr.io/kpt-fn/set-project-id:unstable -- 'project-id=foo'
```

### Expected result
Expand Down
5 changes: 3 additions & 2 deletions examples/starlark-set-namespace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ metadata:
name: set-namespace-to-prod
annotations:
source: |
# set the namespace on all resources
# set the namespace on all resources except StarlarkRun and Kptfile kind.
def setnamespace(resources, namespace):
for resource in resources:
# mutate the resource
resource["metadata"]["namespace"] = namespace
if resource["kind"] not in ["StarlarkRun", "Kptfile"]:
resource["metadata"]["namespace"] = namespace
setnamespace(ctx.resource_list["items"], "prod")
```
Expand Down
5 changes: 3 additions & 2 deletions examples/starlark-set-namespace/fn-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ kind: StarlarkRun
metadata:
name: set-namespace-to-prod
source: |
# set the namespace on all resources
# set the namespace on all resources except Kptfile and StarlarkRun kind.
for resource in ctx.resource_list["items"]:
# mutate the resource
resource["metadata"]["namespace"] = "prod"
if resource.get("kind") not in ["StarlarkRun", "Kptfile"]:
resource["metadata"]["namespace"] = "prod"
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ var prefixSuffixFieldSpecsToSkip = types.FsSlice{
{Gvk: resid.Gvk{Kind: "CustomResourceDefinition"}},
{Gvk: resid.Gvk{Group: "apiregistration.k8s.io", Kind: "APIService"}},
{Gvk: resid.Gvk{Kind: "Namespace"}},
{Gvk: resid.Gvk{Group: "kpt.dev", Kind: "Kptfile"}},
}

func shouldSkip(id resid.ResId) bool {
Expand Down
2 changes: 0 additions & 2 deletions functions/go/ensure-name-substring/generated/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/ensure-name-substring/legacy-config/.expected/diff.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
diff --git a/fn-config.yaml b/fn-config.yaml
index 84f999f..9915f86 100644
--- a/fn-config.yaml
+++ b/fn-config.yaml
@@ -1,7 +1,7 @@
apiVersion: fn.kpt.dev/v1alpha1
kind: EnsureNameSubstring
metadata:
- name: my-config
+ name: prod-my-config
editMode: prepend
fieldSpecs:
- kind: MyResource
diff --git a/resources.yaml b/resources.yaml
index 8e037c3..ffd583b 100644
--- a/resources.yaml
Expand Down
13 changes: 13 additions & 0 deletions tests/ensure-name-substring/local-config/.expected/diff.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
diff --git a/fn-config.yaml b/fn-config.yaml
index d25180f..5842b05 100644
--- a/fn-config.yaml
+++ b/fn-config.yaml
@@ -1,7 +1,7 @@
apiVersion: fn.kpt.dev/v1alpha1
kind: EnsureNameSubstring
metadata:
- name: my-config
+ name: prod-my-config
annotations:
config.kubernetes.io/local-config: "true"
editMode: prepend
diff --git a/local-config.yaml b/local-config.yaml
index b8d83d1..304fc07 100644
--- a/local-config.yaml
Expand Down
2 changes: 1 addition & 1 deletion tests/search-replace/file-path-match/.expected/exec.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /bin/bash

# shellcheck disable=SC2016
kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable --include-meta-resources --image-pull-policy=never -- \
kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable --image-pull-policy=never -- \
by-value=project-id by-file-path='**/setters.yaml' put-value=new-project
1 change: 1 addition & 0 deletions tests/search-replace/no-results/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pipeline:
- image: gcr.io/kpt-fn/search-replace:unstable
configMap:
by-value: non-existent-value
by-file-path: 'resources.yaml'
2 changes: 2 additions & 0 deletions tests/set-annotations/additional-annotations/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ pipeline:
mutators:
- image: gcr.io/kpt-fn/set-annotations:unstable
configPath: fn-config.yaml
selectors:
- kind: ConfigMap
2 changes: 2 additions & 0 deletions tests/set-annotations/legacy-config/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ pipeline:
mutators:
- image: gcr.io/kpt-fn/set-annotations:unstable
configPath: fn-config.yaml
selectors:
- kind: ConfigMap
2 changes: 2 additions & 0 deletions tests/set-annotations/local-config/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ pipeline:
mutators:
- image: gcr.io/kpt-fn/set-annotations:unstable
configPath: fn-config.yaml
selectors:
- kind: ConfigMap
2 changes: 2 additions & 0 deletions tests/set-labels/additional-labels/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ pipeline:
mutators:
- image: gcr.io/kpt-fn/set-labels:unstable
configPath: fn-config.yaml
selectors:
- kind: ConfigMap
3 changes: 3 additions & 0 deletions tests/set-labels/legacy-config/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ pipeline:
mutators:
- image: gcr.io/kpt-fn/set-labels:unstable
configPath: fn-config.yaml
selectors:
- kind: ConfigMap
- kind: MyResource
2 changes: 2 additions & 0 deletions tests/set-labels/local-config/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ pipeline:
mutators:
- image: gcr.io/kpt-fn/set-labels:unstable
configPath: fn-config.yaml
selectors:
- kind: ConfigMap
3 changes: 2 additions & 1 deletion tests/starlark/map-key-inline-comment/fn-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ source: |
def setnamespace(resources, namespace):
for resource in resources:
# mutate the resource
resource["metadata"]["namespace"] = namespace
if resource["kind"] not in ["StarlarkRun", "Kptfile"]:
resource["metadata"]["namespace"] = namespace
setnamespace(ctx.resource_list["items"], "prod")
3 changes: 2 additions & 1 deletion tests/starlark/non-standard-features/fn-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ source: |
print(fib(3))
for resource in ctx.resource_list["items"]:
resource["metadata"]["namespace"] = "test"
if resource["kind"] not in ["StarlarkRun", "Kptfile"]:
resource["metadata"]["namespace"] = "test"

0 comments on commit e649e50

Please sign in to comment.