Skip to content

Commit

Permalink
replace inline CRD config with configPath
Browse files Browse the repository at this point in the history
  • Loading branch information
Mengqi committed May 14, 2021
1 parent de2db9a commit 6ba2890
Show file tree
Hide file tree
Showing 26 changed files with 218 additions and 186 deletions.
13 changes: 1 addition & 12 deletions examples/ensure-name-substring/advanced/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,4 @@ metadata:
pipeline:
mutators:
- image: gcr.io/kpt-fn/ensure-name-substring:unstable
config:
apiVersion: fn.kpt.dev/v1alpha1
kind: EnsureNameSubstring
metadata:
name: my-config
substring: prod-
editMode: prepend
fieldSpecs:
- group: dev.example.com
version: v1
kind: MyResource
path: spec/name
configPath: fn-config.yaml
32 changes: 19 additions & 13 deletions examples/ensure-name-substring/advanced/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ file an [issue].
This example demonstrates how to declaratively run the [`ensure-name-substring`]
function to prepend prefix in the resource names.

We use the following Kptfile to run the function.
We use the following `Kptfile` and `fn-config.yaml` to run the function.

```yaml
apiVersion: kpt.dev/v1alpha2
Expand All @@ -19,18 +19,24 @@ metadata:
pipeline:
mutators:
- image: gcr.io/kpt-fn/ensure-name-substring:unstable
config:
apiVersion: fn.kpt.dev/v1alpha1
kind: EnsureNameSubstring
metadata:
name: my-config
substring: prod-
editMode: prepend
fieldSpecs:
- group: dev.example.com
version: v1
kind: MyResource
path: spec/name
configPath: fn-config.yaml
```
```yaml
# fn-config.yaml
apiVersion: fn.kpt.dev/v1alpha1
kind: EnsureNameSubstring
metadata:
name: my-config
annotations:
config.kubernetes.io/local-config: 'true'
substring: prod-
editMode: prepend
fieldSpecs:
- group: dev.example.com
version: v1
kind: MyResource
path: spec/name
```
We are going to prepend prefix `prod-` to resource names.
Expand Down
13 changes: 13 additions & 0 deletions examples/ensure-name-substring/advanced/fn-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: fn.kpt.dev/v1alpha1
kind: EnsureNameSubstring
metadata:
name: my-config
annotations:
config.kubernetes.io/local-config: 'true'
substring: prod-
editMode: prepend
fieldSpecs:
- group: dev.example.com
version: v1
kind: MyResource
path: spec/name
6 changes: 0 additions & 6 deletions examples/kubeval/simple/.expected/results.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ metadata:
exitCode: 1
items:
- image: gcr.io/kpt-fn/kubeval:unstable
stderr: |
[ERROR] Validating arbitrary CRDs is not supported yet. You can skip them by setting ignore_missing_schemas or skip_kinds in the function config:
ERR - stdin: Failed initializing schema file:///tmp/master-standalone-strict/mycustom-example-v1.json: open /tmp/master-standalone-strict/mycustom-example-v1.json: no such file or directory
in object 'example.com/v1/MyCustom//alice' in file resources.yaml
[ERROR] Additional property templates is not allowed in object 'v1/ReplicationController//bob' in file resources.yaml in field templates
[ERROR] Invalid type. Expected: [integer,null], given: string in object 'v1/ReplicationController//bob' in file resources.yaml in field spec.replicas
exitCode: 1
results:
- message: |
Expand Down
15 changes: 1 addition & 14 deletions examples/set-annotations/advanced/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,4 @@ metadata:
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-annotations:unstable
config:
apiVersion: fn.kpt.dev/v1alpha1
kind: SetAnnotationConfig
metadata:
name: my-func-config
annotations:
fruit: apple
color: orange
fieldSpecs:
- kind: MyResource
group: dev.example.com
version: v1
create: true
path: spec/selector/annotations
configPath: fn-config.yaml
36 changes: 21 additions & 15 deletions examples/set-annotations/advanced/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This example demonstrates how to declaratively run [`set-annotations`] function
to upsert annotations to the `.metadata.annotations` field on all resources.

We use the following `Kptfile` to configure the function.
We use the following `Kptfile` and `fn-config.yaml` to configure the function.

```yaml
apiVersion: kpt.dev/v1alpha2
Expand All @@ -15,20 +15,26 @@ metadata:
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-annotations:unstable
config:
apiVersion: fn.kpt.dev/v1alpha1
kind: SetAnnotationConfig
metadata:
name: my-func-config
annotations:
fruit: apple
color: orange
fieldSpecs:
- kind: MyResource
group: dev.example.com
version: v1
create: true
path: spec/selector/annotations
configPath: fn-config.yaml
```
```yaml
# fn-config.yaml
apiVersion: fn.kpt.dev/v1alpha1
kind: SetAnnotationConfig
metadata:
name: my-func-config
annotations:
config.kubernetes.io/local-config: 'true'
annotations:
fruit: apple
color: orange
fieldSpecs:
- kind: MyResource
group: dev.example.com
version: v1
create: true
path: spec/selector/annotations
```
The desired annotations are provided using the `annotations` field. We have a
Expand Down
15 changes: 15 additions & 0 deletions examples/set-annotations/advanced/fn-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: fn.kpt.dev/v1alpha1
kind: SetAnnotationConfig
metadata:
name: my-func-config
annotations:
config.kubernetes.io/local-config: 'true'
annotations:
fruit: apple
color: orange
fieldSpecs:
- kind: MyResource
group: dev.example.com
version: v1
create: true
path: spec/selector/annotations
15 changes: 1 addition & 14 deletions examples/set-labels/advanced/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,4 @@ metadata:
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-labels:unstable
config:
apiVersion: fn.kpt.dev/v1alpha1
kind: SetLabelConfig
metadata:
name: my-config
labels:
color: orange
fruit: apple
fieldSpecs:
- kind: MyResource
group: dev.example.com
version: v1
create: true
path: spec/selector/labels
configPath: fn-config.yaml
36 changes: 21 additions & 15 deletions examples/set-labels/advanced/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This example demonstrates how to declaratively run [`set-labels`] function
to upsert labels to the `.metadata.labels` field on all resources.

We use the following `Kptfile` to configure the function.
We use the following `Kptfile` and `fn-config.yaml` to configure the function.

```yaml
apiVersion: kpt.dev/v1alpha2
Expand All @@ -15,20 +15,26 @@ metadata:
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-labels:unstable
config:
apiVersion: fn.kpt.dev/v1alpha1
kind: SetLabelConfig
metadata:
name: my-config
labels:
color: orange
fruit: apple
fieldSpecs:
- kind: MyResource
group: dev.example.com
version: v1
create: true
path: spec/selector/labels
configPath: fn-config.yaml
```
```yaml
# fn-config.yaml
apiVersion: fn.kpt.dev/v1alpha1
kind: SetLabelConfig
metadata:
name: my-config
annotations:
config.kubernetes.io/local-config: 'true'
labels:
color: orange
fruit: apple
fieldSpecs:
- kind: MyResource
group: dev.example.com
version: v1
create: true
path: spec/selector/labels
```
The desired labels is provided using `labels` field. We have a CRD with group
Expand Down
15 changes: 15 additions & 0 deletions examples/set-labels/advanced/fn-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: fn.kpt.dev/v1alpha1
kind: SetLabelConfig
metadata:
name: my-config
annotations:
config.kubernetes.io/local-config: 'true'
labels:
color: orange
fruit: apple
fieldSpecs:
- kind: MyResource
group: dev.example.com
version: v1
create: true
path: spec/selector/labels
11 changes: 1 addition & 10 deletions examples/set-namespace/advanced/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,4 @@ metadata:
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-namespace:unstable
config: # inline config
apiVersion: fn.kpt.dev/v1alpha1
kind: SetNamespaceConfig
namespace: example-ns
fieldSpecs:
- group: dev.example.com
version: v1
kind: MyResource
path: spec/configmapRef/namespace
create: true
configPath: fn-config.yaml
30 changes: 19 additions & 11 deletions examples/set-namespace/advanced/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This example demonstrates how to declaratively run [`set-namespace`] function
to add or replace the `.metadata.namespace` field on all resources except for
those known to be cluster-scoped.

We use the following `Kptfile` to configure the function.
We use the following `Kptfile` and `fn-config.yaml` to configure the function.

```yaml
apiVersion: kpt.dev/v1alpha2
Expand All @@ -16,16 +16,24 @@ metadata:
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-namespace:unstable
config: # inline config
apiVersion: fn.kpt.dev/v1alpha1
kind: SetNamespaceConfig
namespace: example-ns
fieldSpecs:
- group: dev.example.com
version: v1
kind: MyResource
path: spec/configmapRef/namespace
create: true
configPath: fn-config.yaml
```
```yaml
# fn-config.yaml
apiVersion: fn.kpt.dev/v1alpha1
kind: SetNamespaceConfig
metadata:
name: my-config
annotations:
config.kubernetes.io/local-config: 'true'
namespace: example-ns
fieldSpecs:
- group: dev.example.com
version: v1
kind: MyResource
path: spec/configmapRef/namespace
create: true
```
`set-namespace` function not only support ConfigMap but also a CRD as the
Expand Down
13 changes: 13 additions & 0 deletions examples/set-namespace/advanced/fn-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: fn.kpt.dev/v1alpha1
kind: SetNamespaceConfig
metadata:
name: my-config
annotations:
config.kubernetes.io/local-config: 'true'
namespace: example-ns
fieldSpecs:
- group: dev.example.com
version: v1
kind: MyResource
path: spec/configmapRef/namespace
create: true
13 changes: 1 addition & 12 deletions examples/starlark/simple/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,4 @@ metadata:
pipeline:
mutators:
- image: gcr.io/kpt-fn/starlark:unstable
config:
apiVersion: fn.kpt.dev/v1alpha1
kind: StarlarkRun
metadata:
name: set-namespace-to-prod
source: |
# set the namespace on all resources
def setnamespace(resources, namespace):
for resource in resources:
# mutate the resource
resource["metadata"]["namespace"] = namespace
setnamespace(ctx.resource_list["items"], "prod")
configPath: fn-config.yaml
Loading

0 comments on commit 6ba2890

Please sign in to comment.