Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
bdc4993
add more e2e tests; change readme to get rid of additional label fields
zyy98 Jul 13, 2022
9beb52c
update generated docs
zyy98 Jul 13, 2022
c19446c
add license make rule
zyy98 Jul 13, 2022
440fd79
change directory for make rule
zyy98 Jul 13, 2022
632d8f4
defer update license to next PR
zyy98 Jul 13, 2022
52f0772
fix tests bugs, add reply message for empty resource
zyy98 Jul 13, 2022
7a5fa4b
add good examples and fix old example readme
zyy98 Jul 14, 2022
010c76c
update metadata file
zyy98 Jul 14, 2022
9adb808
fix minor formatting
zyy98 Jul 14, 2022
183b011
minor rename and doc
zyy98 Jul 14, 2022
c59a4aa
doc rename
zyy98 Jul 14, 2022
2922e8a
doc rename
zyy98 Jul 14, 2022
25d7422
doc rename
zyy98 Jul 14, 2022
945bf4e
fix previous error logic in test files. Update set-labels to handle a…
zyy98 Jul 15, 2022
0462c90
handle local config
zyy98 Jul 18, 2022
c4dd0dc
update go module, add full coverage test, fix minor logic bug in set-…
zyy98 Jul 19, 2022
b256a6a
update unit test
zyy98 Jul 19, 2022
3819a29
delete unnecessary examples, all covered by full coverage
zyy98 Jul 19, 2022
c2132d2
readme wording
zyy98 Jul 19, 2022
634ad0e
seperated check local config into another PR
zyy98 Jul 19, 2022
5ebe543
update same local config, otherwise cannot pass tests
zyy98 Jul 19, 2022
da7375c
revert local config, actual change in another PR
zyy98 Jul 19, 2022
2e1d14c
merge from master
zyy98 Jul 20, 2022
6f585c9
delete selector from Kptfile
zyy98 Jul 20, 2022
fe31cc7
add more label path in common.go, add FieldPath "spec.template.spec.a…
zyy98 Jul 21, 2022
29d4f81
change to hard code resources; fix resource error in yaml
zyy98 Jul 23, 2022
c3ef4a0
delete unused comments
zyy98 Jul 23, 2022
b6bedec
doc string and rename
zyy98 Jul 23, 2022
2cc6104
a bit rename and refactor
zyy98 Jul 23, 2022
4d71f3b
refactor
zyy98 Jul 23, 2022
8535172
modify testvalue into different test value
zyy98 Jul 24, 2022
e9eb89d
delete comments in yaml
zyy98 Jul 25, 2022
da94748
merge with master; split PR to contain only tests
zyy98 Jul 26, 2022
f705e19
no resource exit with 0 instead of 1
zyy98 Jul 26, 2022
161f5cc
change error message
zyy98 Jul 28, 2022
90bbd91
delete unnecessary diff
zyy98 Jul 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions examples/set-labels-advanced/.expected/diff.patch

This file was deleted.

16 changes: 0 additions & 16 deletions examples/set-labels-advanced/resources.yaml

This file was deleted.

256 changes: 256 additions & 0 deletions examples/set-labels-full-coverage/.expected/diff.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
diff --git a/resources.yaml b/resources.yaml
index 6a06662..62df835 100644
--- a/resources.yaml
+++ b/resources.yaml
@@ -2,56 +2,84 @@ apiVersion: v1
kind: Service
metadata:
name: my-service
+ labels:
+ app: new
+ color: orange
+ fruit: apple
spec:
selector:
- app: MyApp
+ app: new
+ color: orange
+ fruit: apple
---
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx
+ labels:
+ app: new
+ color: orange
+ fruit: apple
spec:
replicas: 3
selector:
- app: nginx
+ app: new
+ color: orange
+ fruit: apple
template:
metadata:
name: nginx
labels:
- app: nginx
+ app: new
+ color: orange
+ fruit: apple
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
- app: nginx
+ app: new
+ color: orange
+ fruit: apple
spec:
replicas: 3
selector:
matchLabels:
- app: nginx
+ app: new
+ color: orange
+ fruit: apple
template:
metadata:
labels:
- app: nginx
+ app: new
+ color: orange
+ fruit: apple
---
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: frontend
labels:
- app: guestbook
+ app: new
tier: frontend
+ color: orange
+ fruit: apple
spec:
replicas: 3
selector:
matchLabels:
tier: frontend
+ app: new
+ color: orange
+ fruit: apple
template:
metadata:
labels:
tier: frontend
+ app: new
+ color: orange
+ fruit: apple
---
apiVersion: apps/v1
kind: DaemonSet
@@ -60,23 +88,38 @@ metadata:
namespace: kube-system
labels:
k8s-app: fluentd-logging
+ app: new
+ color: orange
+ fruit: apple
spec:
selector:
matchLabels:
name: fluentd-elasticsearch
+ app: new
+ color: orange
+ fruit: apple
template:
metadata:
labels:
name: fluentd-elasticsearch
+ app: new
+ color: orange
+ fruit: apple
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
+ labels:
+ app: new
+ color: orange
+ fruit: apple
spec:
selector:
matchLabels:
- app: nginx
+ app: new
+ color: orange
+ fruit: apple
serviceName: "nginx"
replicas: 3
minReadySeconds: 10
@@ -85,6 +128,9 @@ spec:
name: www
labels:
key: www
+ app: new
+ color: orange
+ fruit: apple
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: "my-storage-class"
@@ -95,6 +141,9 @@ spec:
name: xxx
labels:
key: xxx
+ app: new
+ color: orange
+ fruit: apple
spec:
accessModes: ["ReadWrite"]
storageClassName: "my-storage-class"
@@ -104,12 +153,18 @@ spec:
template:
metadata:
labels:
- app: nginx
+ app: new
+ color: orange
+ fruit: apple
---
apiVersion: batch/v1
kind: Job
metadata:
name: pi
+ labels:
+ app: new
+ color: orange
+ fruit: apple
spec:
selector:
matchLabels:
@@ -117,12 +172,14 @@ spec:
template:
metadata:
labels:
- color: pi
+ color: orange
+ app: new
+ fruit: apple
spec:
containers:
- name: pi
image: perl:5.34
- command: ["perl", "-Mbignum=bpi", "-wle", "'print bpi(2000)'"]
+ command: ["perl", "-Mbignum=bpi", "-wle", "'print bpi(2000)'"]
restartPolicy: Never
backoffLimit: 4
---
@@ -130,12 +187,19 @@ apiVersion: batch/v1
kind: CronJob
metadata:
name: hello
+ labels:
+ app: new
+ color: orange
+ fruit: apple
spec:
schedule: "* * * * *"
jobTemplate:
metadata:
labels:
env: dev
+ app: new
+ color: orange
+ fruit: apple
spec:
selector:
matchLabels:
@@ -144,6 +208,9 @@ spec:
metadata:
labels:
testkey: testvalue
+ app: new
+ color: orange
+ fruit: apple
spec:
containers:
- name: hello
@@ -159,6 +226,10 @@ apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: hello
+ labels:
+ app: new
+ color: orange
+ fruit: apple
spec:
selector:
matchLabels:
@@ -169,6 +240,10 @@ kind: NetworkPolicy
metadata:
name: test-network-policy
namespace: default
+ labels:
+ app: new
+ color: orange
+ fruit: apple
spec:
podSelector:
matchLabels:
@@ -179,6 +254,10 @@ kind: MyResource
metadata:
name: the-service
namespace: the-namespace
+ labels:
+ app: new
+ color: orange
+ fruit: apple
spec:
selector:
labels:
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: example
annotations:
config.kubernetes.io/local-config: "true"
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-labels:unstable
configPath: fn-config.yaml
selectors:
- kind: ConfigMap
- kind: MyResource
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# set-labels: Advanced Example
# set-labels: Full Coverage Example
Comment thread
mengqiy marked this conversation as resolved.

### Overview

This example demonstrates how to declaratively run [`set-labels`] function
to upsert labels to the `.metadata.labels` field on all resources.
to upsert all common labels to different built-in resources and CustomResourceDefinition (CRD) resources.

### Fetch the example package

Get the example package by running the following commands:

```shell
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/set-labels-advanced
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/set-labels-full-coverage
```

We use the following `Kptfile` and `fn-config.yaml` to configure the function.
Expand All @@ -20,6 +20,8 @@ apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: example
annotations:
config.kubernetes.io/local-config: "true"
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-labels:unstable
Expand All @@ -32,33 +34,28 @@ apiVersion: fn.kpt.dev/v1alpha1
kind: SetLabels
metadata:
name: my-config
annotations:
config.kubernetes.io/local-config: "true"
labels:
color: orange
fruit: apple
additionalLabelFields:
- kind: MyResource
group: dev.example.com
version: v1
create: true
path: spec/selector/labels
app: new
```

The desired labels is provided using `labels` field. We have a CRD with group
`dev.example.com`, version `v1` and kind `MyResource`. We want the labels to be
added to field `.spec.selector.labels` as well. We specify it in field
`additionalLabelFields`.
`dev.example.com`, version `v1` and kind `MyResource`.

### Function invocation

Invoke the function by running the following commands:

```shell
$ kpt fn render set-labels-advanced
$ kpt fn render set-labels-full-coverage
```

### Expected result

Check all resources have 2 labels: `color: orange` and `fruit: apple`. And the
resource of kind `MyResource` also has these 2 labels in `spec.selector.labels`.
Check all resources, the following labels should be upserted to the `labels`, `matchingLabels` or `seletors(labelSelector)` fields:
`color: orange`, `fruit: apple` and `app: new`.

[`set-labels`]: https://catalog.kpt.dev/set-labels/v0.1/
10 changes: 10 additions & 0 deletions examples/set-labels-full-coverage/fn-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: fn.kpt.dev/v1alpha1
kind: SetLabels
metadata:
name: my-config
annotations:
config.kubernetes.io/local-config: "true"
labels:
color: orange
fruit: apple
app: new
Comment thread
zyy98 marked this conversation as resolved.
Loading