Skip to content

Commit 6cd9b92

Browse files
committed
Add set-default-labels function
1 parent f05f540 commit 6cd9b92

File tree

17 files changed

+1150
-0
lines changed

17 files changed

+1150
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
diff --git a/app1_ghost/resources.yaml b/app1_ghost/resources.yaml
2+
index 5c7a0b8..0cca983 100644
3+
--- a/app1_ghost/resources.yaml
4+
+++ b/app1_ghost/resources.yaml
5+
@@ -2,6 +2,8 @@ apiVersion: apps/v1
6+
kind: Deployment
7+
metadata:
8+
name: ghost
9+
+ labels:
10+
+ app.kubernetes.io/name: root-app
11+
spec:
12+
replicas: 2
13+
template:
14+
@@ -16,3 +18,9 @@ spec:
15+
value: http://localhost:8080
16+
- name: database__connection__database
17+
value: ghost
18+
+ metadata:
19+
+ labels:
20+
+ app.kubernetes.io/name: root-app
21+
+ selector:
22+
+ matchLabels:
23+
+ app.kubernetes.io/name: root-app
24+
diff --git a/app2_mysql/resources.yaml b/app2_mysql/resources.yaml
25+
index 88d0df7..be45a8d 100644
26+
--- a/app2_mysql/resources.yaml
27+
+++ b/app2_mysql/resources.yaml
28+
@@ -2,6 +2,8 @@ apiVersion: apps/v1
29+
kind: Deployment
30+
metadata:
31+
name: mysql
32+
+ labels:
33+
+ app.kubernetes.io/name: root-app
34+
spec:
35+
template:
36+
spec:
37+
@@ -11,5 +13,11 @@ spec:
38+
ports:
39+
- name: mysql
40+
containerPort: 3306
41+
+ metadata:
42+
+ labels:
43+
+ app.kubernetes.io/name: root-app
44+
strategy:
45+
type: Recreate
46+
+ selector:
47+
+ matchLabels:
48+
+ app.kubernetes.io/name: root-app
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.expected
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: root-app
5+
annotations:
6+
config.kubernetes.io/local-config: "true"
7+
pipeline:
8+
mutators:
9+
- image: gcr.io/kpt-fn/set-default-labels:unstable
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# set-default-labels: Nested Package Example
2+
3+
### Overview
4+
5+
This example shows how to run [`set-default-labels`] in a nested KPT package.
6+
7+
### Fetch the example package
8+
9+
Get the example package by running the following commands:
10+
11+
```shell
12+
kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/set-default-labels-nested-package
13+
```
14+
15+
Take a look at the `Kptfile`, it has the `set-default-labels` configured. Note, it does not require function configs (no `configPath` nor `configMap`).
16+
17+
```yaml
18+
apiVersion: kpt.dev/v1
19+
kind: Kptfile
20+
metadata:
21+
name: your-app
22+
pipeline:
23+
mutators:
24+
- image: gcr.io/kpt-fn/set-default-labels:unstable
25+
```
26+
27+
### Function invocation
28+
29+
Invoke the function:
30+
31+
```shell
32+
$ kpt fn render root-app
33+
```
34+
35+
### Expected result
36+
A [recommended label] `app.kubernetes.io/name: your-app` using the root pacakge name is added to all the resources `labels` and `matchLabels` fields.
37+
38+
[`set-default-labels`]: https://catalog.kpt.dev/set-labels/v0.1/
39+
[recommended label]: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: kpt.dev/v1
2+
kind: Kptfile
3+
metadata:
4+
name: app1_ghost
5+
annotations:
6+
config.kubernetes.io/local-config: "true"
7+
info:
8+
description: sample description
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: ghost
5+
spec:
6+
replicas: 2
7+
template:
8+
spec:
9+
containers:
10+
- name: ghost
11+
image: ghost:3-alpine
12+
ports:
13+
- containerPort: 2368
14+
env:
15+
- name: url
16+
value: http://localhost:8080
17+
- name: database__connection__database
18+
value: ghost
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: kpt.dev/v1
2+
kind: Kptfile
3+
metadata:
4+
name: app2_mysql
5+
annotations:
6+
config.kubernetes.io/local-config: "true"
7+
info:
8+
description: sample description
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# app2
2+
3+
## Description
4+
sample description
5+
6+
## Usage
7+
8+
### Fetch the package
9+
`kpt pkg get REPO_URI[.git]/PKG_PATH[@VERSION] app2`
10+
Details: https://kpt.dev/reference/cli/pkg/get/
11+
12+
### View package content
13+
`kpt pkg tree app2`
14+
Details: https://kpt.dev/reference/cli/pkg/tree/
15+
16+
### Apply the package
17+
```
18+
kpt live init app2
19+
kpt live apply app2 --reconcile-timeout=2m --output=table
20+
```
21+
Details: https://kpt.dev/reference/cli/live/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: mysql
5+
spec:
6+
template:
7+
spec:
8+
containers:
9+
- name: mysql
10+
image: mysql:5.7
11+
ports:
12+
- name: mysql
13+
containerPort: 3306
14+
strategy:
15+
type: Recreate

functions/go/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ FUNCTIONS := \
3737
set-enforcement-action \
3838
set-image \
3939
set-labels \
40+
set-default-labels \
4041
set-namespace \
4142
set-project-id \
4243
source-gcloud-config \

0 commit comments

Comments
 (0)