Debian Codegraph @

examples/transformerconfigs/images/README.md

raw
1 ## Images transformations
2
3 This tutorial shows how to modify images in resources, and create a custom images transformer configuration.
4
5 Create a workspace by
6 <!-- @createws @testAgainstLatestRelease -->
7 ```
8 DEMO_HOME=$(mktemp -d)
9 ```
10
11 ### Adding a custom resource
12
13 Consider a Custom Resource Definition(CRD) of kind `MyKind` with field
14 - `.spec.runLatest.container.image` referencing an image
15
16 Add the following file to configure the images transformer for the CRD:
17
18 <!-- @addConfig @testAgainstLatestRelease -->
19 ```
20 mkdir $DEMO_HOME/kustomizeconfig
21 cat > $DEMO_HOME/kustomizeconfig/mykind.yaml << EOF
22
23 images:
24 - path: spec/runLatest/container/image
25 kind: MyKind
26 EOF
27 ```
28
29 ### Apply config
30
31 Create a file with some resources that includes an instance of `MyKind`:
32
33 <!-- @createResource @testAgainstLatestRelease -->
34 ```
35 cat > $DEMO_HOME/resources.yaml << EOF
36
37 apiVersion: config/v1
38 kind: MyKind
39 metadata:
40 name: testSvc
41 spec:
42 runLatest:
43 container:
44 image: crd-image
45 containers:
46 - image: docker
47 name: ecosystem
48 - image: my-mysql
49 name: testing-1
50 ---
51 group: apps
52 apiVersion: v1
53 kind: Deployment
54 metadata:
55 name: deploy1
56 spec:
57 template:
58 spec:
59 initContainers:
60 - name: nginx2
61 image: my-app
62 - name: init-alpine
63 image: alpine:1.8.0
64 EOF
65 ```
66
67 Create a kustomization.yaml referring to it:
68
69 <!-- @createKustomization @testAgainstLatestRelease -->
70 ```
71 cat > $DEMO_HOME/kustomization.yaml << EOF
72 resources:
73 - resources.yaml
74
75 images:
76 - name: crd-image
77 newName: new-crd-image
78 newTag: new-v1-tag
79 - name: my-app
80 newName: new-app-1
81 newTag: MYNEWTAG-1
82 - name: my-mysql
83 newName: prod-mysql
84 newTag: v3
85 - name: docker
86 newName: my-docker2
87 digest: sha256:25a0d4
88 EOF
89 ```
90
91 Use the customized transformer configurations by specifying them
92 in the kustomization file:
93 <!-- @addTransformerConfigs @testAgainstLatestRelease -->
94 ```
95 cat >> $DEMO_HOME/kustomization.yaml << EOF
96 configurations:
97 - kustomizeconfig/mykind.yaml
98 EOF
99 ```
100
101 Run `kustomize build` and verify that the images have been updated.
102
103 <!-- @build @testAgainstLatestRelease -->
104 ```
105 test 1 == \
106 $(kustomize build $DEMO_HOME | grep -A 2 ".*image" | grep "new-crd-image:new-v1-tag" | wc -l); \
107 echo $?
108 ```
109
110 <!-- @build @testAgainstLatestRelease -->
111 ```
112 test 1 == \
113 $(kustomize build $DEMO_HOME | grep -A 2 ".*image" | grep "new-app-1:MYNEWTAG-1" | wc -l); \
114 echo $?
115 ```
116
117 <!-- @build @testAgainstLatestRelease -->
118 ```
119 test 1 == \
120 $(kustomize build $DEMO_HOME | grep -A 2 ".*image" | grep "my-docker2@sha" | wc -l); \
121 echo $?
122 ```
123 <!-- @build @testAgainstLatestRelease -->
124 ```
125 test 1 == \
126 $(kustomize build $DEMO_HOME | grep -A 2 ".*image" | grep "prod-mysql:v3" | wc -l); \
127 echo $?
128 ```