mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 17:34:21 +00:00
Remove extraneous whitespace.
make all (generate docs) Update examples in cmd docs. make all (generate docs) functions/examples: Whitespace cleanup. functions/examples: Fix some example commands.
This commit is contained in:
@@ -58,7 +58,7 @@
|
||||
|
||||
`tree` can also be used with `kubectl get` to print cluster Resources using OwnersReferences
|
||||
to build the tree structure.
|
||||
|
||||
|
||||
kubectl apply -R -f cockroachdb/
|
||||
kubectl get all -o yaml | kustomize config tree --graph-structure owners --name --image --replicas
|
||||
.
|
||||
@@ -112,7 +112,7 @@
|
||||
ordering of fields and indentation.
|
||||
|
||||
$ kustomize config fmt mysql-wordpress-pd/
|
||||
|
||||
|
||||
Run `git diff` and see the changes that have been applied.
|
||||
|
||||
### `grep` -- search for Resources by field values
|
||||
@@ -141,7 +141,6 @@
|
||||
|
||||
- list elements may be indexed by a field value using list[field=value]
|
||||
- '.' as part of a key or value may be escaped as '\.'
|
||||
|
||||
|
||||
$ kustomize config grep "spec.status.spec.containers[name=nginx].image=mysql:5\.6" wordpress/
|
||||
apiVersion: apps/v1 # for k8s versions before 1.9.0 use apps/v1beta2 and before 1.8.0 use extensions/v1beta1
|
||||
@@ -162,12 +161,11 @@
|
||||
tier: mysql
|
||||
...
|
||||
|
||||
|
||||
`grep` may be used with kubectl to search for Resources in a cluster matching a value.
|
||||
|
||||
|
||||
kubectl get all -o yaml | kustomize config grep "spec.replicas>0" | kustomize config tree --replicas
|
||||
.
|
||||
└──
|
||||
└──
|
||||
├── [.] Deployment wp/wordpress
|
||||
│ └── spec.replicas: 1
|
||||
├── [.] ReplicaSet wp/wordpress-76b5d9f5c8
|
||||
@@ -178,7 +176,7 @@
|
||||
└── spec.replicas: 1
|
||||
|
||||
### Error handling
|
||||
|
||||
|
||||
If there is an error parsing the Resource configuration, kustomize will print an error with the file.
|
||||
|
||||
$ kustomize config grep "spec.template.spec.containers[name=\.*].resources.limits.cpu>1.0" ./staging/ | kustomize config tree --name --resources
|
||||
@@ -187,13 +185,13 @@
|
||||
|
||||
Here the `staging/persistent-volume-provisioning/quobyte/quobyte-admin-secret.yaml` has a malformed
|
||||
Resource. Remove the malformed Resources:
|
||||
|
||||
|
||||
rm staging/persistent-volume-provisioning/quobyte/quobyte-admin-secret.yaml
|
||||
rm staging/storage/vitess/etcd-service-template.yaml
|
||||
|
||||
When developing -- to get a stack trace for where an error was encountered,
|
||||
use the `--stack-trace` flag:
|
||||
|
||||
|
||||
$ kustomize config grep "spec.template.spec.containers[name=\.*].resources.limits.cpu>1.0" ./staging/ --stack-trace
|
||||
go/src/sigs.k8s.io/kustomize/kyaml/yaml/types.go:260 (0x4d35c86)
|
||||
(*RNode).GetMeta: return m, errors.Wrap(err)
|
||||
@@ -205,9 +203,9 @@
|
||||
### Combine `grep` and `tree`
|
||||
|
||||
`grep` and `tree` may be combined to perform queries against configuration.
|
||||
|
||||
|
||||
Query for `replicas`:
|
||||
|
||||
|
||||
$ kustomize config grep "spec.replicas>5" ./ | kustomize config tree --replicas
|
||||
.
|
||||
├── staging/sysdig-cloud
|
||||
@@ -245,9 +243,9 @@
|
||||
|
||||
The `grep` results may be inverted with the `-v` flag and used to find Resources that don't
|
||||
match a query.
|
||||
|
||||
|
||||
Find Resources that have an image specified, but the image doesn't have a tag:
|
||||
|
||||
|
||||
$ kustomize config grep "spec.template.spec.containers[name=\.*].name=\.*" ./ | kustomize config grep "spec.template.spec.containers[name=\.*].image=\.*:\.*" -v | kustomize config tree --image --name
|
||||
.
|
||||
├── staging/newrelic
|
||||
|
||||
@@ -23,31 +23,30 @@
|
||||
directory, and invoke `run` on the `local-resource/` directory.
|
||||
|
||||
cd template-heredoc-cockroachdb/
|
||||
|
||||
|
||||
# view the Resources
|
||||
kustomize config tree local-resource/ --name --image --replicas
|
||||
|
||||
|
||||
# run the function
|
||||
kustomize config run local-resource/
|
||||
|
||||
# view the generated Resources
|
||||
|
||||
# view the generated Resources
|
||||
kustomize config tree local-resource/ --name --image --replicas
|
||||
|
||||
|
||||
`run` generated the directory ` local-resource/config` containing the generated
|
||||
Resources.
|
||||
|
||||
|
||||
#### 2. Modify the Generated Resources
|
||||
|
||||
|
||||
- modify the generated Resources by adding an annotation, sidecar container, etc.
|
||||
- modify the `local-resources/example-use.yaml` by changing the replicas
|
||||
|
||||
- modify the `local-resources/example-use.yaml` by changing the replicas
|
||||
|
||||
re-run `run`. this will apply the updated replicas to the generated Resources,
|
||||
but keep the fields that you manually added to the generated Resource configuration.
|
||||
|
||||
|
||||
# run the function
|
||||
kustomize config run local-resource/
|
||||
|
||||
|
||||
`run` facilitates a non-destructive *smart templating* approach that allows templating
|
||||
to be composed with manual modifications directly to the template output, as well as
|
||||
composition with other functions which may appy validation or injection of values.
|
||||
@@ -60,7 +59,7 @@
|
||||
### Templating -- Nginx
|
||||
|
||||
The steps in this section are identical to the CockroachDB templating example,
|
||||
but the function implementation is very different, and implemented as a `go`
|
||||
but the function implementation is very different, and implemented as a `go`
|
||||
program rather than a `bash` script.
|
||||
|
||||
#### 1: Generate the Resources
|
||||
@@ -69,32 +68,32 @@
|
||||
directory, and invoke `run` on the `local-resource/` directory.
|
||||
|
||||
cd template-go-nginx/
|
||||
|
||||
|
||||
# view the Resources
|
||||
kustomize config tree local-resource/ --name --image --replicas
|
||||
|
||||
|
||||
# run the function
|
||||
kustomize config run local-resource/
|
||||
|
||||
# view the generated Resources
|
||||
|
||||
# view the generated Resources
|
||||
kustomize config tree local-resource/ --name --image --replicas
|
||||
|
||||
|
||||
`run` generated the directory ` local-resource/config` containing the generated
|
||||
Resources. this time it put the configuration in a single file rather than multiple
|
||||
files. The mapping of Resources to files is controlled by the function itself through
|
||||
annotations on the generated Resources.
|
||||
|
||||
|
||||
#### 2. Modify the Generated Resources
|
||||
|
||||
- modify the generated Resources by adding an annotation, sidecar container, etc.
|
||||
- modify the `local-resources/example-use.yaml` by changing the replicas
|
||||
|
||||
|
||||
re-run `run`. this will apply the updated replicas to the generated Resources,
|
||||
but keep the fields that you manually added to the generated Resource configuration.
|
||||
|
||||
|
||||
# run the function
|
||||
kustomize config run local-resource/
|
||||
|
||||
|
||||
Just like in the preceding section, the function is implemented using a non-destructive
|
||||
approach which merges the generated Resources into previously generated instances.
|
||||
|
||||
@@ -106,7 +105,7 @@
|
||||
### Validation -- resource reservations
|
||||
|
||||
This section uses `run` to perform validation rather than generate Resources.
|
||||
|
||||
|
||||
#### 1: Run the Validator
|
||||
|
||||
`cd` into the `kustomize/functions/examples/validator-resource-requests`
|
||||
@@ -118,13 +117,13 @@
|
||||
Error: exit status 1
|
||||
Usage:
|
||||
...
|
||||
|
||||
|
||||
#### 2: Fix the validation issue
|
||||
|
||||
The command will fail complaining that the nginx Deployment is missing `cpu-requests`,
|
||||
and print the name of the file + Resource index. Edit the file and uncomment the resources,
|
||||
then re-run the functions.
|
||||
|
||||
|
||||
kustomize config run local-resource/
|
||||
|
||||
The validation now passes.
|
||||
@@ -133,7 +132,7 @@
|
||||
|
||||
This section uses `run` to perform injection of field values based off annotations
|
||||
on the Resource.
|
||||
|
||||
|
||||
#### 1: Run the Injector
|
||||
|
||||
`cd` into the `kustomize/functions/examples/inject-tshirt-sizes`
|
||||
@@ -142,7 +141,7 @@
|
||||
# print the resources
|
||||
kustomize config tree local-resource --resources --name
|
||||
local-resource
|
||||
├── [example-use.yaml] Validator
|
||||
├── [example-use.yaml] Validator
|
||||
└── [example-use.yaml] Deployment nginx
|
||||
└── spec.template.spec.containers
|
||||
└── 0
|
||||
@@ -150,10 +149,10 @@
|
||||
|
||||
# run the functions
|
||||
kustomize config run local-resource/
|
||||
|
||||
|
||||
# print the new resources
|
||||
kustomize config tree local-resource --resources --name
|
||||
├── [example-use.yaml] Validator
|
||||
kustomize config tree local-resource --resources --name
|
||||
├── [example-use.yaml] Validator
|
||||
└── [example-use.yaml] Deployment nginx
|
||||
└── spec.template.spec.containers
|
||||
└── 0
|
||||
@@ -161,24 +160,24 @@
|
||||
└── resources: {requests: {cpu: 4, memory: 1GiB}}
|
||||
|
||||
#### 2: Change the tshirt-size
|
||||
|
||||
|
||||
Change the `tshirt-size` annotation from `medium` to `small` and re-run the functions.
|
||||
|
||||
kustomize config run local-resource/
|
||||
kustomize config tree local-resource/
|
||||
local-resource
|
||||
├── [example-use.yaml] Validator
|
||||
├── [example-use.yaml] Validator
|
||||
└── [example-use.yaml] Deployment nginx
|
||||
└── spec.template.spec.containers
|
||||
└── 0
|
||||
├── name: nginx
|
||||
└── resources: {requests: {cpu: 200m, memory: 50MiB}}
|
||||
|
||||
The function has applied the reservations for the new tshirt-size
|
||||
The function has applied the reservations for the new tshirt-size
|
||||
|
||||
### Function Composition
|
||||
|
||||
Functions may be composed together. Try putting the Injection (tshirt-size) and
|
||||
Functions may be composed together. Try putting the Injection (tshirt-size) and
|
||||
Validation functions together in the same .yaml file (separated by `---`). Run
|
||||
`run` and observe that the first function in the file is applied to the Resources,
|
||||
and then the second function in the file is applied.
|
||||
and then the second function in the file is applied.
|
||||
|
||||
Reference in New Issue
Block a user