Skip to content

Commit 0063969

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

File tree

17 files changed

+1125
-0
lines changed

17 files changed

+1125
-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: 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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 your-app
13+
```
14+
15+
We use the following `Kptfile` to configure the function.
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 by running the following commands:
30+
31+
```shell
32+
$ kpt fn render your-app
33+
```
34+
35+
### Expected result
36+
All resources should have `app.kubernetes.io/name: your-app` label added to the meta and label selector fields.
37+
38+
[`set-default-labels`]: https://catalog.kpt.dev/set-labels/v0.1/
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)