Skip to content

feat: Add function set-standard-labels #930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 24 additions & 0 deletions examples/set-stanrdard-labels-abstract/.expected/diff.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/resources.yaml b/resources.yaml
index 1e641f7..bb4be90 100644
--- a/resources.yaml
+++ b/resources.yaml
@@ -2,6 +2,9 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: the-map
+ labels:
+ color: orange
+ fruit: apple
data:
some-key: some-value
---
@@ -10,6 +13,9 @@ kind: MyResource
metadata:
name: the-service
namespace: the-namespace
+ labels:
+ color: orange
+ fruit: apple
spec:
selector:
labels:
9 changes: 9 additions & 0 deletions examples/set-stanrdard-labels-abstract/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: base-app
annotations:
config.kubernetes.io/local-config: "true"
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-standard-labels:unstable
42 changes: 42 additions & 0 deletions examples/set-stanrdard-labels-abstract/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# set-standard-labels: Abstract Example

### Overview

This example demonstrates how to add kubernetes recommended labels to kpt Abstract (or Catalog) packages
by running the [`set-starndard-labels`] function.

### 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-stanrdard-labels-abstract
```

We use the following `Kptfile` to configure the function.

```yaml
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: base-app
annotations:
config.kubernetes.io/local-config: "true"
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-standard-labels:unstable
```

### Function invocation

Invoke the function by running the following commands:

```shell
$ kpt fn render set-stanrdard-labels-abstract
```

### Expected result

Check the deployment has label `app.kubernetes.io/name: base-app` added.

[`set-labels`]: https://catalog.kpt.dev/set-standard-labels/v0.1/
14 changes: 14 additions & 0 deletions examples/set-stanrdard-labels-abstract/resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

apiVersion: apps/v1
kind: Deployment
metadata:
name: base-app
namespace: example
spec:
selector:
matchLabels:
test: abstract-base-app
template:
metadata:
labels:
test: abstract-base-app
24 changes: 24 additions & 0 deletions examples/set-stanrdard-labels-blueprint/.expected/diff.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/resources.yaml b/resources.yaml
index 1e641f7..bb4be90 100644
--- a/resources.yaml
+++ b/resources.yaml
@@ -2,6 +2,9 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: the-map
+ labels:
+ color: orange
+ fruit: apple
data:
some-key: some-value
---
@@ -10,6 +13,9 @@ kind: MyResource
metadata:
name: the-service
namespace: the-namespace
+ labels:
+ color: orange
+ fruit: apple
spec:
selector:
labels:
9 changes: 9 additions & 0 deletions examples/set-stanrdard-labels-blueprint/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: frontend
annotations:
config.kubernetes.io/local-config: "true"
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-standard-labels:unstable
39 changes: 39 additions & 0 deletions examples/set-stanrdard-labels-blueprint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# set-standard-labels: Blueprint Example

### Overview

This example demonstrates how to add kubernetes recommended labels to kpt Blueprint packages
by running the [`set-starndard-labels`] function.

### 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-stanrdard-labels-blueprint
```

We use the following `Kptfile` to configure the function.

```yaml
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: frontend
annotations:
config.kubernetes.io/local-config: "true"
```

### Function invocation

Invoke the function by running the following commands:

```shell
$ kpt fn render set-stanrdard-labels-blueprint
```

### Expected result

Check the deployment has label `app.kubernetes.io/name: frontend` added.

[`set-labels`]: https://catalog.kpt.dev/set-standard-labels/v0.1/
18 changes: 18 additions & 0 deletions examples/set-stanrdard-labels-blueprint/resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: base-app
namespace: example
labels:
test: abstract-base-app
app.kubernetes.io/name: base-app
spec:
selector:
matchLabels:
test: abstract-base-app
app.kubernetes.io/name: base-app
template:
metadata:
labels:
test: abstract-base-app
app.kubernetes.io/name: base-app
24 changes: 24 additions & 0 deletions examples/set-stanrdard-labels-deployment/.expected/diff.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/resources.yaml b/resources.yaml
index 1e641f7..bb4be90 100644
--- a/resources.yaml
+++ b/resources.yaml
@@ -2,6 +2,9 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: the-map
+ labels:
+ color: orange
+ fruit: apple
data:
some-key: some-value
---
@@ -10,6 +13,9 @@ kind: MyResource
metadata:
name: the-service
namespace: the-namespace
+ labels:
+ color: orange
+ fruit: apple
spec:
selector:
labels:
9 changes: 9 additions & 0 deletions examples/set-stanrdard-labels-deployment/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: frontend-dev
annotations:
config.kubernetes.io/local-config: "true"
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-standard-labels:unstable
40 changes: 40 additions & 0 deletions examples/set-stanrdard-labels-deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# set-standard-labels: Deployment Example

### Overview

This example demonstrates how to add kubernetes recommended labels to kpt Deployment packages
by running the [`set-starndard-labels`] function.

### 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-stanrdard-labels-deployment
```

We use the following `Kptfile` to configure the function.

```yaml
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: frontend
annotations:
config.kubernetes.io/local-config: "true"
```

### Function invocation

Invoke the function by running the following commands:

```shell
$ kpt fn render set-stanrdard-labels-deployment
```

### Expected result

Check the deployment has label `app.kubernetes.io/instance: frontend-dev` added, and the
existing upstream label `app.kubernetes.io/name: frontend` is preserved.

[`set-labels`]: https://catalog.kpt.dev/set-standard-labels/v0.1/
27 changes: 27 additions & 0 deletions examples/set-stanrdard-labels-deployment/resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: kptfile.kpt.dev
annotations:
config.kubernetes.io/local-config: "true"
data:
name: frontend-dev
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: base-app
namespace: example
labels:
test: abstract-base-app
app.kubernetes.io/name: frontend
spec:
selector:
matchLabels:
test: abstract-base-app
app.kubernetes.io/name: frontend
template:
metadata:
labels:
test: abstract-base-app
app.kubernetes.io/name: frontend
24 changes: 24 additions & 0 deletions examples/set-stanrdard-labels-manual-force/.expected/diff.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/resources.yaml b/resources.yaml
index 1e641f7..bb4be90 100644
--- a/resources.yaml
+++ b/resources.yaml
@@ -2,6 +2,9 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: the-map
+ labels:
+ color: orange
+ fruit: apple
data:
some-key: some-value
---
@@ -10,6 +13,9 @@ kind: MyResource
metadata:
name: the-service
namespace: the-namespace
+ labels:
+ color: orange
+ fruit: apple
spec:
selector:
labels:
11 changes: 11 additions & 0 deletions examples/set-stanrdard-labels-manual-force/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: custom-frontend
annotations:
config.kubernetes.io/local-config: "true"
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-standard-labels:unstable
configMap:
isDeployment: false
46 changes: 46 additions & 0 deletions examples/set-stanrdard-labels-manual-force/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# set-standard-labels: Manual Force Example

### Overview

This example demonstrates how to add kubernetes recommended labels to a kpt package via manually
forcing the package (with package-context.yaml) to be treated as a blueprint package.
by running the [`set-starndard-labels`] function.

### 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-stanrdard-labels-manual-force
```

We use the following `Kptfile` to configure the function.

```yaml
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: custom-frontend
annotations:
config.kubernetes.io/local-config: "true"
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-standard-labels:unstable
configMap:
isDeployment: false
```

### Function invocation

Invoke the function by running the following commands:

```shell
$ kpt fn render set-stanrdard-labels-manual-force
```

### Expected result

Check the label is changed from `app.kubernetes.io/name: frontend` to
`app.kubernetes.io/name: custom-frontend`.

[`set-labels`]: https://catalog.kpt.dev/set-standard-labels/v0.1/
Loading