Skip to content

Commit d9db966

Browse files
committed
Use GetSlice and get/set by string pointer.
merge after
1 parent b9aec2a commit d9db966

9 files changed

Lines changed: 141 additions & 115 deletions

File tree

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
diff --git a/app.yaml b/app.yaml
2-
index 1e641f7..bb4be90 100644
2+
index d67a0d2..bf55161 100644
33
--- a/app.yaml
44
+++ b/app.yaml
5-
@@ -2,6 +2,9 @@ apiVersion: v1
6-
kind: ConfigMap
7-
metadata:
8-
name: the-map
9-
+ labels:
10-
+ color: orange
11-
+ fruit: apple
12-
data:
13-
some-key: some-value
14-
---
15-
@@ -10,6 +13,9 @@ kind: MyResource
5+
@@ -9,7 +9,7 @@ apiVersion: v1
6+
kind: Service
167
metadata:
178
name: the-service
18-
namespace: the-namespace
19-
+ labels:
20-
+ color: orange
21-
+ fruit: apple
9+
- namespace: example
10+
+ namespace: new-ns
2211
spec:
23-
selector:
24-
labels:
12+
ports:
13+
- name: etcd-server-ssl
14+
@@ -34,4 +34,4 @@ spec:
15+
apiVersion: v1
16+
kind: Namespace
17+
metadata:
18+
- name: example
19+
+ name: new-ns
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
testType: eval
22
image: gcr.io/kpt-fn/set-namespace:unstable
33
args:
4-
namespace: example-ns
4+
namespace: new-ns
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
diff --git a/app.yaml b/app.yaml
2-
index 1f8aeee..33e42da 100644
2+
index d67a0d2..bf55161 100644
33
--- a/app.yaml
44
+++ b/app.yaml
55
@@ -9,7 +9,7 @@ apiVersion: v1
66
kind: Service
77
metadata:
88
name: the-service
9-
- namespace: the-namespace
10-
+ namespace: example-ns
9+
- namespace: example
10+
+ namespace: new-ns
1111
spec:
1212
ports:
1313
- name: etcd-server-ssl
14-
@@ -21,4 +21,4 @@ spec:
14+
@@ -34,4 +34,4 @@ spec:
1515
apiVersion: v1
1616
kind: Namespace
1717
metadata:
1818
- name: example
19-
+ name: example-ns
19+
+ name: new-ns

examples/set-namespace-imperative/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
### Overview
44

5-
This examples shows how to set namespace in the `.metadata.namespace` field on
6-
all resources by running [`set-namespace`] function imperatively. Resources that
7-
are known to be cluster-scoped will be skipped.
5+
This examples shows how to replace KRM resources' namespace fields by matching
6+
the namespace with the namespace object's `metadata.name`.
7+
The example uses `kpt fn eval` to run the function imperatively.
88

99
### Fetch the example package
1010

@@ -27,6 +27,7 @@ The desired namespace is provided after `--` and it will be converted to
2727

2828
### Expected result
2929

30-
Check all resources have `metadata.namespace` set to `example-ns`:
30+
Only the namespace fields which match the `namespace` "example" object has the value updated to
31+
`new-ns`:
3132

3233
[`set-namespace`]: https://catalog.kpt.dev/set-namespace/v0.1/

examples/set-namespace-imperative/app.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,20 @@ apiVersion: v1
99
kind: Service
1010
metadata:
1111
name: the-service
12-
namespace: the-namespace
12+
namespace: example
13+
spec:
14+
ports:
15+
- name: etcd-server-ssl
16+
port: 2380
17+
- name: etcd-client-ssl
18+
port: 2379
19+
publishNotReadyAddresses: true
20+
---
21+
apiVersion: v1
22+
kind: Service
23+
metadata:
24+
name: the-service
25+
namespace: not-match-example
1326
spec:
1427
ports:
1528
- name: etcd-server-ssl

functions/go/set-namespace/Dockerfile

Lines changed: 0 additions & 17 deletions
This file was deleted.

functions/go/set-namespace/go.mod

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,34 @@ module github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/set-na
33
go 1.17
44

55
require (
6-
github.com/GoogleContainerTools/kpt-functions-sdk/go/fn v0.0.0-20220326221816-442298f7a17c
6+
github.com/GoogleContainerTools/kpt-functions-sdk/go/fn v0.0.0-20220405020624-e5817d5d2014
77
k8s.io/apimachinery v0.23.5
88
)
99

1010
require (
1111
github.com/PuerkitoBio/purell v1.1.1 // indirect
1212
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
1313
github.com/davecgh/go-spew v1.1.1 // indirect
14-
github.com/go-errors/errors v1.0.1 // indirect
15-
github.com/go-logr/logr v1.2.0 // indirect
14+
github.com/go-errors/errors v1.4.2 // indirect
15+
github.com/go-logr/logr v1.2.3 // indirect
1616
github.com/go-openapi/jsonpointer v0.19.5 // indirect
17-
github.com/go-openapi/jsonreference v0.19.3 // indirect
18-
github.com/go-openapi/swag v0.19.5 // indirect
19-
github.com/mailru/easyjson v0.7.0 // indirect
17+
github.com/go-openapi/jsonreference v0.19.6 // indirect
18+
github.com/go-openapi/swag v0.21.1 // indirect
19+
github.com/golang/protobuf v1.5.2 // indirect
20+
github.com/google/gnostic v0.6.7 // indirect
21+
github.com/josharian/intern v1.0.0 // indirect
22+
github.com/mailru/easyjson v0.7.7 // indirect
2023
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
2124
github.com/pkg/errors v0.9.1 // indirect
2225
github.com/pmezard/go-difflib v1.0.0 // indirect
23-
github.com/stretchr/testify v1.7.0 // indirect
24-
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
25-
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
26+
github.com/stretchr/testify v1.7.1 // indirect
27+
github.com/xlab/treeprint v1.1.0 // indirect
28+
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b // indirect
2629
golang.org/x/text v0.3.7 // indirect
30+
google.golang.org/protobuf v1.28.0 // indirect
2731
gopkg.in/yaml.v2 v2.4.0 // indirect
2832
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
29-
k8s.io/klog/v2 v2.30.0 // indirect
30-
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
31-
sigs.k8s.io/kustomize/kyaml v0.13.3 // indirect
33+
k8s.io/klog/v2 v2.60.1 // indirect
34+
k8s.io/kube-openapi v0.0.0-20220401212409-b28bf2818661 // indirect
35+
sigs.k8s.io/kustomize/kyaml v0.13.6 // indirect
3236
)

0 commit comments

Comments
 (0)