github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/internal/trait/container-image.cue (about) 1 "container-image": { 2 type: "trait" 3 annotations: {} 4 description: "Set the image of the container." 5 attributes: { 6 podDisruptive: true 7 appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"] 8 } 9 } 10 template: { 11 #PatchParams: { 12 // +usage=Specify the name of the target container, if not set, use the component name 13 containerName: *"" | string 14 // +usage=Specify the image of the container 15 image: string 16 // +usage=Specify the image pull policy of the container 17 imagePullPolicy: *"" | "IfNotPresent" | "Always" | "Never" 18 } 19 PatchContainer: { 20 _params: #PatchParams 21 name: _params.containerName 22 _baseContainers: context.output.spec.template.spec.containers 23 _matchContainers_: [ for _container_ in _baseContainers if _container_.name == name {_container_}] 24 _baseContainer: *_|_ | {...} 25 if len(_matchContainers_) == 0 { 26 err: "container \(name) not found" 27 } 28 if len(_matchContainers_) > 0 { 29 // +patchStrategy=retainKeys 30 image: _params.image 31 32 if _params.imagePullPolicy != "" { 33 // +patchStrategy=retainKeys 34 imagePullPolicy: _params.imagePullPolicy 35 } 36 } 37 } 38 patch: spec: template: spec: { 39 if parameter.containers == _|_ { 40 // +patchKey=name 41 containers: [{ 42 PatchContainer & {_params: { 43 if parameter.containerName == "" { 44 containerName: context.name 45 } 46 if parameter.containerName != "" { 47 containerName: parameter.containerName 48 } 49 image: parameter.image 50 imagePullPolicy: parameter.imagePullPolicy 51 }} 52 }] 53 } 54 if parameter.containers != _|_ { 55 // +patchKey=name 56 containers: [ for c in parameter.containers { 57 if c.containerName == "" { 58 err: "containerName must be set for containers" 59 } 60 if c.containerName != "" { 61 PatchContainer & {_params: c} 62 } 63 }] 64 } 65 } 66 67 parameter: #PatchParams | close({ 68 // +usage=Specify the container image for multiple containers 69 containers: [...#PatchParams] 70 }) 71 72 errs: [ for c in patch.spec.template.spec.containers if c.err != _|_ {c.err}] 73 }