Skip to content

Commit 793eefd

Browse files
committed
add functoin set-standard-labels
1 parent c653dc8 commit 793eefd

File tree

37 files changed

+1067
-0
lines changed

37 files changed

+1067
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git a/resources.yaml b/resources.yaml
2+
index 1e641f7..bb4be90 100644
3+
--- a/resources.yaml
4+
+++ b/resources.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
16+
metadata:
17+
name: the-service
18+
namespace: the-namespace
19+
+ labels:
20+
+ color: orange
21+
+ fruit: apple
22+
spec:
23+
selector:
24+
labels:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: kpt.dev/v1
2+
kind: Kptfile
3+
metadata:
4+
name: base-app
5+
annotations:
6+
config.kubernetes.io/local-config: "true"
7+
pipeline:
8+
mutators:
9+
- image: gcr.io/kpt-fn/set-standard-labels:unstable
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# set-standard-labels: Abstract Example
2+
3+
### Overview
4+
5+
This example demonstrates how to add kubernetes recommended labels to kpt Abstract (or Catalog) packages
6+
by running the [`set-starndard-labels`] function.
7+
8+
### Fetch the example package
9+
10+
Get the example package by running the following commands:
11+
12+
```shell
13+
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/set-stanrdard-labels-abstract
14+
```
15+
16+
We use the following `Kptfile` to configure the function.
17+
18+
```yaml
19+
apiVersion: kpt.dev/v1
20+
kind: Kptfile
21+
metadata:
22+
name: base-app
23+
annotations:
24+
config.kubernetes.io/local-config: "true"
25+
pipeline:
26+
mutators:
27+
- image: gcr.io/kpt-fn/set-standard-labels:unstable
28+
```
29+
30+
### Function invocation
31+
32+
Invoke the function by running the following commands:
33+
34+
```shell
35+
$ kpt fn render set-stanrdard-labels-abstract
36+
```
37+
38+
### Expected result
39+
40+
Check the deployment has label `app.kubernetes.io/name: base-app` added.
41+
42+
[`set-labels`]: https://catalog.kpt.dev/set-standard-labels/v0.1/
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: base-app
6+
namespace: example
7+
spec:
8+
selector:
9+
matchLabels:
10+
test: abstract-base-app
11+
template:
12+
metadata:
13+
labels:
14+
test: abstract-base-app
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git a/resources.yaml b/resources.yaml
2+
index 1e641f7..bb4be90 100644
3+
--- a/resources.yaml
4+
+++ b/resources.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
16+
metadata:
17+
name: the-service
18+
namespace: the-namespace
19+
+ labels:
20+
+ color: orange
21+
+ fruit: apple
22+
spec:
23+
selector:
24+
labels:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: kpt.dev/v1
2+
kind: Kptfile
3+
metadata:
4+
name: frontend
5+
annotations:
6+
config.kubernetes.io/local-config: "true"
7+
pipeline:
8+
mutators:
9+
- image: gcr.io/kpt-fn/set-standard-labels:unstable
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# set-standard-labels: Blueprint Example
2+
3+
### Overview
4+
5+
This example demonstrates how to add kubernetes recommended labels to kpt Blueprint packages
6+
by running the [`set-starndard-labels`] function.
7+
8+
### Fetch the example package
9+
10+
Get the example package by running the following commands:
11+
12+
```shell
13+
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/set-stanrdard-labels-blueprint
14+
```
15+
16+
We use the following `Kptfile` to configure the function.
17+
18+
```yaml
19+
apiVersion: kpt.dev/v1
20+
kind: Kptfile
21+
metadata:
22+
name: frontend
23+
annotations:
24+
config.kubernetes.io/local-config: "true"
25+
```
26+
27+
### Function invocation
28+
29+
Invoke the function by running the following commands:
30+
31+
```shell
32+
$ kpt fn render set-stanrdard-labels-blueprint
33+
```
34+
35+
### Expected result
36+
37+
Check the deployment has label `app.kubernetes.io/name: frontend` added.
38+
39+
[`set-labels`]: https://catalog.kpt.dev/set-standard-labels/v0.1/
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: base-app
5+
namespace: example
6+
labels:
7+
test: abstract-base-app
8+
app.kubernetes.io/name: base-app
9+
spec:
10+
selector:
11+
matchLabels:
12+
test: abstract-base-app
13+
app.kubernetes.io/name: base-app
14+
template:
15+
metadata:
16+
labels:
17+
test: abstract-base-app
18+
app.kubernetes.io/name: base-app
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git a/resources.yaml b/resources.yaml
2+
index 1e641f7..bb4be90 100644
3+
--- a/resources.yaml
4+
+++ b/resources.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
16+
metadata:
17+
name: the-service
18+
namespace: the-namespace
19+
+ labels:
20+
+ color: orange
21+
+ fruit: apple
22+
spec:
23+
selector:
24+
labels:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: kpt.dev/v1
2+
kind: Kptfile
3+
metadata:
4+
name: frontend-dev
5+
annotations:
6+
config.kubernetes.io/local-config: "true"
7+
pipeline:
8+
mutators:
9+
- image: gcr.io/kpt-fn/set-standard-labels:unstable
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# set-standard-labels: Deployment Example
2+
3+
### Overview
4+
5+
This example demonstrates how to add kubernetes recommended labels to kpt Deployment packages
6+
by running the [`set-starndard-labels`] function.
7+
8+
### Fetch the example package
9+
10+
Get the example package by running the following commands:
11+
12+
```shell
13+
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/set-stanrdard-labels-deployment
14+
```
15+
16+
We use the following `Kptfile` to configure the function.
17+
18+
```yaml
19+
apiVersion: kpt.dev/v1
20+
kind: Kptfile
21+
metadata:
22+
name: frontend
23+
annotations:
24+
config.kubernetes.io/local-config: "true"
25+
```
26+
27+
### Function invocation
28+
29+
Invoke the function by running the following commands:
30+
31+
```shell
32+
$ kpt fn render set-stanrdard-labels-deployment
33+
```
34+
35+
### Expected result
36+
37+
Check the deployment has label `app.kubernetes.io/instance: frontend-dev` added, and the
38+
existing upstream label `app.kubernetes.io/name: frontend` is preserved.
39+
40+
[`set-labels`]: https://catalog.kpt.dev/set-standard-labels/v0.1/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: kptfile.kpt.dev
5+
annotations:
6+
config.kubernetes.io/local-config: "true"
7+
data:
8+
name: frontend-dev
9+
---
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
metadata:
13+
name: base-app
14+
namespace: example
15+
labels:
16+
test: abstract-base-app
17+
app.kubernetes.io/name: frontend
18+
spec:
19+
selector:
20+
matchLabels:
21+
test: abstract-base-app
22+
app.kubernetes.io/name: frontend
23+
template:
24+
metadata:
25+
labels:
26+
test: abstract-base-app
27+
app.kubernetes.io/name: frontend
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git a/resources.yaml b/resources.yaml
2+
index 1e641f7..bb4be90 100644
3+
--- a/resources.yaml
4+
+++ b/resources.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
16+
metadata:
17+
name: the-service
18+
namespace: the-namespace
19+
+ labels:
20+
+ color: orange
21+
+ fruit: apple
22+
spec:
23+
selector:
24+
labels:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: kpt.dev/v1
2+
kind: Kptfile
3+
metadata:
4+
name: custom-frontend
5+
annotations:
6+
config.kubernetes.io/local-config: "true"
7+
pipeline:
8+
mutators:
9+
- image: gcr.io/kpt-fn/set-standard-labels:unstable
10+
configMap:
11+
isDeployment: false
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# set-standard-labels: Manual Force Example
2+
3+
### Overview
4+
5+
This example demonstrates how to add kubernetes recommended labels to a kpt package via manually
6+
forcing the package (with package-context.yaml) to be treated as a blueprint package.
7+
by running the [`set-starndard-labels`] function.
8+
9+
### Fetch the example package
10+
11+
Get the example package by running the following commands:
12+
13+
```shell
14+
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/set-stanrdard-labels-manual-force
15+
```
16+
17+
We use the following `Kptfile` to configure the function.
18+
19+
```yaml
20+
apiVersion: kpt.dev/v1
21+
kind: Kptfile
22+
metadata:
23+
name: custom-frontend
24+
annotations:
25+
config.kubernetes.io/local-config: "true"
26+
pipeline:
27+
mutators:
28+
- image: gcr.io/kpt-fn/set-standard-labels:unstable
29+
configMap:
30+
isDeployment: false
31+
```
32+
33+
### Function invocation
34+
35+
Invoke the function by running the following commands:
36+
37+
```shell
38+
$ kpt fn render set-stanrdard-labels-manual-force
39+
```
40+
41+
### Expected result
42+
43+
Check the label is changed from `app.kubernetes.io/name: frontend` to
44+
`app.kubernetes.io/name: custom-frontend`.
45+
46+
[`set-labels`]: https://catalog.kpt.dev/set-standard-labels/v0.1/

0 commit comments

Comments
 (0)