Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Mengqi Yu committed May 26, 2021
1 parent 9918923 commit c8f3a5d
Show file tree
Hide file tree
Showing 30 changed files with 131 additions and 130 deletions.
10 changes: 4 additions & 6 deletions examples/apply-setters/simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

### Overview

<!-- TODO(phanimarupaka): Populate here and update below -->

Setters provide a solution for template-free setting of field values. The
`apply-setters` KRM config function applies setter values to resource fields
with setter references.
Expand All @@ -27,7 +25,7 @@ environments: # kpt-set: ${env}
- stage
```
We use ConfigMap to configure the `apply-setters` function. The desired
We use `ConfigMap` to configure the `apply-setters` function. The desired
setter values are provided as key-value pairs using `data` field where key is
the name of the setter(as seen in the reference comments) and value is the new
desired value for the tagged field.
Expand Down Expand Up @@ -67,9 +65,9 @@ environments: # kpt-set: ${env}

Get the config example and try it out by running the following commands:

```sh
kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/apply-setters/simple .
kpt fn render simple
```shell
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/apply-setters/simple .
$ kpt fn render simple
```

### Expected result
Expand Down
4 changes: 2 additions & 2 deletions examples/contrib/analyze-istio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ declarative configuration.

Get this example and try it out by running the following commands:

```sh
```shell
kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/contrib/analyze-istio .
kpt fn run analyze-istio
```
Expand All @@ -18,7 +18,7 @@ kpt fn run analyze-istio

This should give the following output:

```sh
```shell
[ERROR] Schema validation error: gateway must have at least one server in object 'networking.istio.io/v1alpha3/Gateway//httpbin-gateway' in file example-config.yaml
error: exit status 1
```
Expand Down
6 changes: 3 additions & 3 deletions examples/contrib/inflate-helm-chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declarative configuration.

Get this example and try it out by running the following commands:

```sh
```shell
kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/contrib/inflate-helm-chart .
kpt fn run --as-current-user inflate-helm-chart/local-configs --mount type=bind,src=$(pwd)/inflate-helm-chart/helloworld-chart,dst=/source
```
Expand All @@ -17,7 +17,7 @@ kpt fn run --as-current-user inflate-helm-chart/local-configs --mount type=bind,

Checking the contents of the `local-configs` directory with `kpt cfg tree inflate-helm-chart/local-configs/` should reveal the following new yaml files:

```sh
```shell
inflate-helm-chart/local-configs
├── [deployment_chart-helloworld-chart.yaml] Deployment chart-helloworld-chart
├── [fn-config.yaml] ConfigMap my-func-config
Expand All @@ -28,7 +28,7 @@ inflate-helm-chart/local-configs

To view changes without writing them into a file, a dry run can be performed as follows:

```sh
```shell
kpt fn run --as-current-user inflate-helm-chart/local-configs --mount type=bind,src=$(pwd)/inflate-helm-chart/helloworld-chart,dst=/source --dry-run
```

Expand Down
4 changes: 2 additions & 2 deletions examples/contrib/sops/age/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This example demonstrates invocation of `sops` for encryption the resouce called

Get this example and try it out by running the following commands:

```sh
```shell
# download this example
kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/contrib/sops/age .

Expand All @@ -25,7 +25,7 @@ SOPS_IMPORT_AGE="$(cat age_keys.txt)" kpt fn run age

Verify the updated configuration:

```sh
```shell
kpt cfg cat age
```

Expand Down
4 changes: 2 additions & 2 deletions examples/contrib/sops/gpg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This example demonstrates invocation of `sops` for encryption the resouce called

Get this example and try it out by running the following commands:

```sh
```shell
# download this example
kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/contrib/sops/gpg .

Expand All @@ -25,7 +25,7 @@ SOPS_IMPORT_PGP="$(cat gpg_keys.asc)" kpt fn run gpg

Verify the updated configuration:

```sh
```shell
kpt cfg cat gpg
```

Expand Down
8 changes: 4 additions & 4 deletions examples/enforce-gatekeeper/invalid-configmap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
This example demonstrates how to declaratively run the [enforce-gatekeeper]
function to validate resources using gatekeeper constraints.

There are 3 resources: a ConstraintTemplate, a K8sBannedConfigMapKeysV1 and a
ConfigMap.
The constraint disallows using `private_key` as a key in the ConfigMap.
There are 3 resources: a `ConstraintTemplate`, a `K8sBannedConfigMapKeysV1` and
a `ConfigMap`.
The constraint disallows using `private_key` as a key in the `ConfigMap`.

Here's an example Kptfile to run the function:
```yaml
Expand Down Expand Up @@ -72,7 +72,7 @@ You can find:
- what constraint does it violate
- where does the resource live and its index in the file
To pass validation, let's replace the key `private_key` in the ConfigMap in
To pass validation, let's replace the key `private_key` in the `ConfigMap` in
`resources.yaml` with something else e.g. `public_key`.
Rerun the command. It will succeed.

Expand Down
4 changes: 2 additions & 2 deletions examples/enforce-gatekeeper/warning-only/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 the [enforce-gatekeeper]
function to validate resources using gatekeeper constraints. The violations are
configured to be warnings instead of errors.

Here's an example Kptfile to run the function:
Here's an example `Kptfile` to run the function:

```yaml
apiVersion: kpt.dev/v1alpha2
Expand Down Expand Up @@ -80,7 +80,7 @@ You can find:
- what constraint does it violate
- where does the resource live and its index in the file

To pass validation, let's replace the key `private_key` in the ConfigMap in
To pass validation, let's replace the key `private_key` in the `ConfigMap` in
`resources.yaml` with something else e.g. `public_key`.
Rerun the command. It will no longer have the warning.

Expand Down
6 changes: 3 additions & 3 deletions examples/ensure-name-substring/advanced/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ The function will not only update field `.metadata.name` but also field

Get the config example and try it out by running the following commands:

```sh
kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/ensure-name-substring/advanced .
kpt fn render advanced
```shell
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/ensure-name-substring/advanced .
$ kpt fn render advanced
```

### Expected result
Expand Down
8 changes: 4 additions & 4 deletions examples/ensure-name-substring/prefix/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 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` to run the function.

```yaml
apiVersion: kpt.dev/v1alpha2
Expand All @@ -25,9 +25,9 @@ We are going to prepend prefix `prod-` to resource names.

Get the config example and try it out by running the following commands:

```sh
kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/ensure-name-substring/prefix .
kpt fn render prefix
```shell
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/ensure-name-substring/prefix .
$ kpt fn render prefix
```

### Expected result
Expand Down
8 changes: 4 additions & 4 deletions examples/ensure-name-substring/suffix/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 the [`ensure-name-substring`]
function to append suffix in the resource names.

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

```yaml
apiVersion: kpt.dev/v1alpha2
Expand All @@ -25,9 +25,9 @@ We are going to append suffix `-prod` to resource names.

Get the config example and try it out by running the following commands:

```sh
kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/ensure-name-substring/suffix .
kpt fn render suffix
```shell
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/ensure-name-substring/suffix .
$ kpt fn render suffix
```

### Expected result
Expand Down
6 changes: 3 additions & 3 deletions examples/fix/simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ The transformed package is compatible with kpt 1.0 binary.

Get the config example and try it out by running the following commands:

```sh
kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/fix/simple .
kpt fn eval simple --image gcr.io/kpt-fn/fix:unstable --include-meta-resources
```shell
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/fix/simple .
$ kpt fn eval simple --image gcr.io/kpt-fn/fix:unstable --include-meta-resources
```

### Expected result
Expand Down
6 changes: 3 additions & 3 deletions examples/format/imperative/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ This example depicts the functionality of `format` function by formatting a

Get the config example and try it out by running the following commands:

```sh
kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/format/imperative .
kpt fn eval imperative --image=gcr.io/kpt-fn/format:unstable
```shell
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/format/imperative .
$ kpt fn eval imperative --image=gcr.io/kpt-fn/format:unstable
```

## Expected result
Expand Down
11 changes: 0 additions & 11 deletions examples/kubeval/simple/.expected/results.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@ items:
- image: gcr.io/kpt-fn/kubeval:unstable
exitCode: 1
results:
- message: |
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
severity: error
resourceRef:
apiVersion: example.com/v1
kind: MyCustom
name: alice
file:
path: resources.yaml
index: 1
- message: Additional property templates is not allowed
severity: error
resourceRef:
Expand Down
1 change: 1 addition & 0 deletions examples/kubeval/simple/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pipeline:
- image: gcr.io/kpt-fn/kubeval:unstable
configMap:
strict: 'true'
skip_kinds: MyCustom
63 changes: 38 additions & 25 deletions examples/kubeval/simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,60 @@ pipeline:
strict: 'true'
```
The function configuration is provided using a ConfigMap. We set 1 key-value
pair:
The function configuration is provided using a `ConfigMap`. We set 2 key-value
pairs:
- `strict: 'true'`: We disallow unknown fields.
- `skip_kinds: MyCustom`: We skip resources of kind `MyCustom`.

### Function invocation

Get this example and try it out by running the following commands:

```sh
kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/kubeval/simple .
kpt fn render simple
```shell
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/kubeval/simple .
$ kpt fn render simple --results-dir=/tmp
```

### Expected Results

This should give the following output:
Let's take a look at the structured results in `/tmp/results.yaml`:

```sh
Package "simple":
[RUNNING] "gcr.io/kpt-fn/kubeval:unstable"
[FAIL] "gcr.io/kpt-fn/kubeval:unstable"
Stderr:
"[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"
""
Exit Code: 1
```yaml
apiVersion: kpt.dev/v1alpha2
kind: FunctionResultList
metadata:
name: fnresults
exitCode: 1
items:
- image: gcr.io/kpt-fn/kubeval:unstable
exitCode: 1
results:
- message: Additional property templates is not allowed
severity: error
resourceRef:
apiVersion: v1
kind: ReplicationController
name: bob
field:
path: templates
file:
path: resources.yaml
- message: 'Invalid type. Expected: [integer,null], given: string'
severity: error
resourceRef:
apiVersion: v1
kind: ReplicationController
name: bob
field:
path: spec.replicas
file:
path: resources.yaml
```

There are validation error in the `resources.yaml` file, to fix them:
- replace the value of `spec.replicas` with an integer
- change `templates` to `template`

Rerun the command, and it should output like the following:
```sh
Package "simple":
[RUNNING] "gcr.io/kpt-fn/kubeval:unstable"
[PASS] "gcr.io/kpt-fn/kubeval:unstable"
Successfully executed 1 function(s) in 1 package(s).
```
Rerun the command, and it should succeed now.

[`kubeval`]: https://catalog.kpt.dev/kubeval/v0.1/
14 changes: 7 additions & 7 deletions examples/search-replace/create-setters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ spec:
Get the config example:
```sh
kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/search-replace/create-setters .
```shell
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/search-replace/create-setters .
```

Suppose you want to expose the values of `image` and `tag` as parameters.
You can create [setters] by invoking `search-replace` function with following arguments:

```sh
kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- 'by-path=spec.replicas' 'put-comment=kpt-set: ${replicas}'
```shell
$ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- 'by-path=spec.replicas' 'put-comment=kpt-set: ${replicas}'
```

```sh
kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- 'by-path=spec.**.image' 'put-comment=kpt-set: gcr.io/${image}:${tag}'
```shell
$ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- 'by-path=spec.**.image' 'put-comment=kpt-set: gcr.io/${image}:${tag}'
```

### Expected result
Expand All @@ -61,7 +61,7 @@ spec:
Next, you can try to run the `apply-setters` function to use the [setters] that
you just created. For example:
```shell
kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- replicas=3 image=nginx tag=1.14.2
$ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- replicas=3 image=nginx tag=1.14.2
```

You should be able to see the values got updated by the [setters].
Expand Down
Loading

0 comments on commit c8f3a5d

Please sign in to comment.