-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #939 from kbhawkey/doc-images-take2
add tutorial for custom images transformer
- Loading branch information
Showing
5 changed files
with
245 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
## Images transformations | ||
|
||
This tutorial shows how to modify images in resources, and create a custom images transformer configuration. | ||
|
||
Create a workspace by | ||
<!-- @createws @test --> | ||
``` | ||
DEMO_HOME=$(mktemp -d) | ||
``` | ||
|
||
### Adding a custom resource | ||
|
||
Consider a Custom Resource Definition(CRD) of kind `MyKind` with field | ||
- `.spec.runLatest.container.image` referencing an image | ||
|
||
Add the following file to configure the images transformer for the CRD: | ||
|
||
<!-- @addConfig @test --> | ||
``` | ||
mkdir $DEMO_HOME/kustomizeconfig | ||
cat > $DEMO_HOME/kustomizeconfig/mykind.yaml << EOF | ||
images: | ||
- path: spec/runLatest/container/image | ||
kind: MyKind | ||
EOF | ||
``` | ||
|
||
### Apply config | ||
|
||
Create a file with some resources that includes an instance of `MyKind`: | ||
|
||
<!-- @createResource @test --> | ||
``` | ||
cat > $DEMO_HOME/resources.yaml << EOF | ||
apiVersion: config/v1 | ||
kind: MyKind | ||
metadata: | ||
name: testSvc | ||
spec: | ||
runLatest: | ||
container: | ||
image: crd-image | ||
containers: | ||
- image: docker | ||
name: ecosystem | ||
- image: my-mysql | ||
name: testing-1 | ||
--- | ||
group: apps | ||
apiVersion: v1 | ||
kind: Deployment | ||
metadata: | ||
name: deploy1 | ||
spec: | ||
template: | ||
spec: | ||
initContainers: | ||
- name: nginx2 | ||
image: my-app | ||
- name: init-alpine | ||
image: alpine:1.8.0 | ||
EOF | ||
``` | ||
|
||
Create a kustomization.yaml referring to it: | ||
|
||
<!-- @createKustomization @test --> | ||
``` | ||
cat > $DEMO_HOME/kustomization.yaml << EOF | ||
resources: | ||
- resources.yaml | ||
images: | ||
- name: crd-image | ||
newName: new-crd-image | ||
newTag: new-v1-tag | ||
- name: my-app | ||
newName: new-app-1 | ||
newTag: MYNEWTAG-1 | ||
- name: my-mysql | ||
newName: prod-mysql | ||
newTag: v3 | ||
- name: docker | ||
newName: my-docker2 | ||
digest: sha256:25a0d4 | ||
EOF | ||
``` | ||
|
||
Use the customized transformer configurations by specifying them | ||
in the kustomization file: | ||
<!-- @addTransformerConfigs @test --> | ||
``` | ||
cat >> $DEMO_HOME/kustomization.yaml << EOF | ||
configurations: | ||
- kustomizeconfig/mykind.yaml | ||
EOF | ||
``` | ||
|
||
Run `kustomize build` and verify that the images have been updated. | ||
|
||
<!-- @build @test --> | ||
``` | ||
test 1 == \ | ||
$(kustomize build $DEMO_HOME | grep -A 2 ".*image" | grep "new-crd-image:new-v1-tag" | wc -l); \ | ||
echo $? | ||
``` | ||
|
||
<!-- @build @test --> | ||
``` | ||
test 1 == \ | ||
$(kustomize build $DEMO_HOME | grep -A 2 ".*image" | grep "new-app-1:MYNEWTAG-1" | wc -l); \ | ||
echo $? | ||
``` | ||
|
||
<!-- @build @test --> | ||
``` | ||
test 1 == \ | ||
$(kustomize build $DEMO_HOME | grep -A 2 ".*image" | grep "my-docker2@sha" | wc -l); \ | ||
echo $? | ||
``` | ||
<!-- @build @test --> | ||
``` | ||
test 1 == \ | ||
$(kustomize build $DEMO_HOME | grep -A 2 ".*image" | grep "prod-mysql:v3" | wc -l); \ | ||
echo $? | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
resources: | ||
- resources.yaml | ||
|
||
configurations: | ||
- kustomizeconfig/mykind.yaml | ||
|
||
images: | ||
- name: crd-image | ||
newName: new-crd-image | ||
newTag: new-v1-tag | ||
- name: my-app | ||
newName: new-app-1 | ||
newTag: MYNEWTAG-1 | ||
- name: my-mysql | ||
newName: prod-mysql | ||
newTag: v3 | ||
- name: docker | ||
newName: my-docker2 | ||
digest: sha256:25a0d4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
images: | ||
- path: spec/runLatest/container/image | ||
kind: MyKind |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apiVersion: config/v1 | ||
kind: MyKind | ||
metadata: | ||
name: testSvc | ||
spec: | ||
runLatest: | ||
container: | ||
image: crd-image | ||
containers: | ||
- image: docker | ||
name: ecosystem | ||
- image: my-mysql | ||
name: testing-1 | ||
--- | ||
group: apps | ||
apiVersion: v1 | ||
kind: Deployment | ||
metadata: | ||
name: deploy1 | ||
spec: | ||
template: | ||
spec: | ||
initContainers: | ||
- name: nginx2 | ||
image: my-app | ||
- name: init-alpine | ||
image: alpine:1.8.0 |