Skip to content

Commit 60163af

Browse files
author
Mengqi Yu
authored
Merge pull request #456 from mengqiy/gatekeeper/v0.1
Merge master to gatekeeper/v0.1
2 parents 68e9569 + 9afe0d4 commit 60163af

File tree

49 files changed

+883
-442
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+883
-442
lines changed
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
diff --git a/resources.yaml b/resources.yaml
2-
index f9d3714..76fef40 100644
2+
index b521905..0d10662 100644
33
--- a/resources.yaml
44
+++ b/resources.yaml
5-
@@ -1,15 +1,15 @@
6-
apiVersion: v1
7-
kind: ConfigMap
5+
@@ -3,7 +3,7 @@ kind: Deployment
86
metadata:
9-
- name: ubuntu-development # kpt-set: ${image}-development
10-
+ name: darwin-development # kpt-set: ${image}-development
11-
data:
12-
some-key: some-value
13-
---
14-
apiVersion: v1
15-
kind: MyKind
7+
name: my-nginx
8+
spec:
9+
- replicas: 4 # kpt-set: ${nginx-replicas}
10+
+ replicas: 3 # kpt-set: ${nginx-replicas}
11+
selector:
12+
matchLabels:
13+
app: nginx
14+
@@ -14,7 +14,7 @@ spec:
15+
spec:
16+
containers:
17+
- name: nginx
18+
- image: "nginx:1.16.1" # kpt-set: nginx:${tag}
19+
+ image: "nginx:1.16.2" # kpt-set: nginx:${tag}
20+
ports:
21+
- protocol: TCP
22+
containerPort: 80
23+
@@ -24,5 +24,5 @@ kind: MyKind
1624
metadata:
17-
- name: ubuntu # kpt-set: ${image}
18-
-image: nginx:1.1.2 # kpt-set: ${app}:${tag}
19-
+ name: darwin # kpt-set: ${image}
20-
+image: nginx:2.1.2 # kpt-set: ${app}:${tag}
21-
roles: # kpt-set: ${role}
25+
name: foo
26+
environments: # kpt-set: ${env}
27+
+ - prod
2228
- dev
23-
- - pro
24-
\ No newline at end of file
25-
+ - intermediate
29+
- - stage

examples/apply-setters-simple/Kptfile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,4 @@ metadata:
55
pipeline:
66
mutators:
77
- image: gcr.io/kpt-fn/apply-setters:unstable
8-
configMap:
9-
image: darwin
10-
role: |
11-
- dev
12-
- intermediate
13-
tag: 2.1.2
8+
configPath: setters.yaml

examples/apply-setters-simple/README.md

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
### Overview
44

5-
The `apply-setters` KRM config function applies setter values to resource fields
6-
with setter references.
7-
85
In this example, we will see how to apply desired setter values to the
96
resource fields parameterized by `kpt-set` comments.
107

@@ -16,26 +13,6 @@ Get the example package by running the following commands:
1613
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/apply-setters-simple
1714
```
1815

19-
Let's start with the input resources
20-
21-
```yaml
22-
apiVersion: v1
23-
kind: ConfigMap
24-
metadata:
25-
name: ubuntu-development # kpt-set: ${image}-development
26-
data:
27-
some-key: some-value
28-
---
29-
apiVersion: v1
30-
kind: MyKind
31-
metadata:
32-
name: ubuntu # kpt-set: ${image}
33-
image: nginx:1.1.2 # kpt-set: ${app}:${tag}
34-
roles: # kpt-set: ${role}
35-
- dev
36-
- pro
37-
```
38-
3916
We use `ConfigMap` to configure the `apply-setters` function. The desired
4017
setter values are provided as key-value pairs using `data` field where key is
4118
the name of the setter(as seen in the reference comments) and value is the new
@@ -47,47 +24,26 @@ kind: ConfigMap
4724
metadata:
4825
name: apply-setters-fn-config
4926
data:
50-
image: darwin
27+
replicas: "3"
5128
role: |
5229
- dev
53-
- intermediate
54-
tag: 2.1.2
55-
```
56-
57-
Invoking `apply-setters` function would apply the changes to resource configs
58-
59-
```yaml
60-
apiVersion: v1
61-
kind: ConfigMap
62-
metadata:
63-
name: darwin-development # kpt-set: ${image}-development
64-
data:
65-
some-key: some-value
66-
---
67-
apiVersion: v1
68-
kind: MyKind
69-
metadata:
70-
name: darwin # kpt-set: ${image}
71-
image: nginx:2.1.2 # kpt-set: ${app}:${tag}
72-
roles: # kpt-set: ${role}
73-
- dev
74-
- intermediate
30+
- prod
31+
tag: 1.16.2
7532
```
7633
7734
### Function invocation
7835
79-
Invoke the function by running the following commands:
36+
Invoke the function by running the following command:
8037
8138
```shell
8239
$ kpt fn render apply-setters-simple
8340
```
8441

8542
### Expected result
8643

87-
1. Check the value of field `metadata.name` is set to `darwin-development` in `ConfigMap` resource.
88-
2. Check the value of field `metadata.name` is set to value `darwin` in `MyKind` resource.
89-
3. Check the value of field `image` is set to value `nginx:2.1.2` in `MyKind` resource.
90-
4. Check the value of field `roles` is set to array value `[dev, intermediate]` in `MyKind` resource.
44+
1. Check the value of field `replicas` is set to `3` in `Deployment` resource.
45+
2. Check the value of field `image` is set to value `nginx:1.16.2` in `Deployment` resource.
46+
3. Check the value of field `environments` is set to value `[dev, prod]` in `MyKind` resource.
9147

9248
#### Note:
9349

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
apiVersion: v1
2-
kind: ConfigMap
1+
apiVersion: apps/v1
2+
kind: Deployment
33
metadata:
4-
name: ubuntu-development # kpt-set: ${image}-development
5-
data:
6-
some-key: some-value
4+
name: my-nginx
5+
spec:
6+
replicas: 4 # kpt-set: ${nginx-replicas}
7+
selector:
8+
matchLabels:
9+
app: nginx
10+
template:
11+
metadata:
12+
labels:
13+
app: nginx
14+
spec:
15+
containers:
16+
- name: nginx
17+
image: "nginx:1.16.1" # kpt-set: nginx:${tag}
18+
ports:
19+
- protocol: TCP
20+
containerPort: 80
721
---
822
apiVersion: v1
923
kind: MyKind
1024
metadata:
11-
name: ubuntu # kpt-set: ${image}
12-
image: nginx:1.1.2 # kpt-set: ${app}:${tag}
13-
roles: # kpt-set: ${role}
25+
name: foo
26+
environments: # kpt-set: ${env}
1427
- dev
15-
- pro
28+
- stage
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: setters
5+
data:
6+
env: |-
7+
- prod
8+
- dev
9+
nginx-replicas: "3"
10+
tag: 1.16.2
Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
diff --git a/resources.yaml b/resources.yaml
2-
index 36ebeed..9e435d7 100644
2+
index 716ecb9..b521905 100644
33
--- a/resources.yaml
44
+++ b/resources.yaml
5-
@@ -1,15 +1,15 @@
6-
apiVersion: v1
7-
kind: ConfigMap
5+
@@ -3,7 +3,7 @@ kind: Deployment
86
metadata:
9-
- name: ubuntu-development
10-
+ name: ubuntu-development # kpt-set: ${image}-development
11-
data:
12-
some-key: some-value
13-
---
14-
apiVersion: v1
7+
name: my-nginx
8+
spec:
9+
- replicas: 4
10+
+ replicas: 4 # kpt-set: ${nginx-replicas}
11+
selector:
12+
matchLabels:
13+
app: nginx
14+
@@ -14,7 +14,7 @@ spec:
15+
spec:
16+
containers:
17+
- name: nginx
18+
- image: "nginx:1.16.1"
19+
+ image: "nginx:1.16.1" # kpt-set: nginx:${tag}
20+
ports:
21+
- protocol: TCP
22+
containerPort: 80
23+
@@ -23,6 +23,6 @@ apiVersion: v1
1524
kind: MyKind
1625
metadata:
17-
- name: ubuntu
18-
-image: nginx:1.1.2
19-
-roles:
20-
+ name: ubuntu # kpt-set: ${image}
21-
+image: nginx:1.1.2 # kpt-set: ${app}:${tag}
22-
+roles: # kpt-set: ${role}
26+
name: foo
27+
-environments:
28+
+environments: # kpt-set: ${env}
2329
- dev
24-
- pro
30+
- stage

examples/create-setters-simple/Kptfile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,4 @@ metadata:
55
pipeline:
66
mutators:
77
- image: gcr.io/kpt-fn/create-setters:unstable
8-
configMap:
9-
app: nginx
10-
image: ubuntu
11-
role: |
12-
- dev
13-
- pro
14-
tag: 1.1.2
8+
configPath: setters.yaml

examples/create-setters-simple/README.md

Lines changed: 13 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,92 +2,47 @@
22

33
### Overview
44

5-
The `create-setters` KRM config function adds comments to resource fields
6-
with setter references.
7-
8-
In this example, we will see how to add setter comments declaratively to
5+
In this example, we will see how to add [setter] comments to
96
resource fields using `create-setters` function.
107

118
### Fetch the example package
129

13-
Get the example package by running the following commands:
10+
Get the example package by running the following command:
1411

1512
```shell
1613
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/create-setters-simple
1714
```
1815

19-
```yaml
20-
apiVersion: v1
21-
kind: ConfigMap
22-
metadata:
23-
name: ubuntu-development
24-
data:
25-
some-key: some-value
26-
---
27-
apiVersion: v1
28-
kind: MyKind
29-
metadata:
30-
name: ubuntu
31-
image: nginx:1.1.2
32-
roles:
33-
- dev
34-
- pro
35-
```
36-
3716
We use `ConfigMap` to configure the `create-setters` function.
3817
The desired setter values are provided as key-value pairs using `data` field.
39-
Here, key is the name of the setter which is used to set the comment and value
40-
is the field value to parameterize.
18+
Here, key is the name of the setter and value is the field value to be parameterized.
4119

4220
```yaml
21+
# create-setters-fn-config.yaml
4322
apiVersion: v1
4423
kind: ConfigMap
4524
metadata:
4625
name: create-setters-fn-config
4726
data:
48-
app: nginx
49-
image: ubuntu
50-
role: |
27+
nginx-replicas: "4"
28+
env: |
5129
- dev
52-
- pro
53-
tag: 1.1.2
54-
```
55-
56-
Invoking `create-setters` function would add the setter comments.
57-
58-
```yaml
59-
apiVersion: v1
60-
kind: ConfigMap
61-
metadata:
62-
name: ubuntu-development # kpt-set: ${image}-development
63-
data:
64-
some-key: some-value
65-
---
66-
apiVersion: v1
67-
kind: MyKind
68-
metadata:
69-
name: ubuntu # kpt-set: ${image}
70-
image: nginx:1.1.2 # kpt-set: ${app}:${tag}
71-
roles: # kpt-set: ${role}
72-
- dev
73-
- pro
30+
- stage
31+
tag: 1.16.1
7432
```
7533
7634
### Function invocation
7735
78-
Invoke the function by running the following commands:
36+
Invoke the function by running the following command:
7937
8038
```shell
8139
$ kpt fn render create-setters-simple
8240
```
8341

8442
### Expected result
8543

86-
`Comment` is added to the resources with the `Values` given below as they match the `Setters`.
44+
1. Check the setter comment `kpt-set: ${nginx-replicas}` is added to `replicas` field value `4` in `Deployment` resource.
45+
2. Check the setter comment `kpt-set: nginx:${tag}` is added to `image` field value `nginx:1.16.1` in `Deployment` resource.
46+
3. Check the setter comment `kpt-set: ${env}` is added to `environment` field in `MyKind` resource.
8747

88-
| Setters | Value | Comment |
89-
|--------------------------------------------|------------------------------|---------------------------------------|
90-
| <pre>image: ubuntu</pre> | <pre>ubuntu</pre> | `# kpt-set: ${image}` |
91-
| <pre>image: ubuntu</pre> | <pre>ubuntu-development</pre>| `# kpt-set: ${image}-development` |
92-
| <pre>app: nginx<br>tag: 1.1.2</pre> | <pre>nginx:1.1.2</pre> | `# kpt-set: ${app}:${tag}` |
93-
| <pre>role: \|<br> - pro<br> - dev</pre> | <pre>- dev<br>- pro</pre> | `# kpt-set: ${role}` |
48+
[setter]: https://catalog.kpt.dev/apply-setters/v0.1/?id=definitions

0 commit comments

Comments
 (0)