github.com/oam-dev/kubevela@v1.9.11/charts/vela-core/templates/defwithtemplate/container-image.yaml (about)

     1  # Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.
     2  # Definition source cue file: vela-templates/definitions/internal/container-image.cue
     3  apiVersion: core.oam.dev/v1beta1
     4  kind: TraitDefinition
     5  metadata:
     6    annotations:
     7      definition.oam.dev/description: Set the image of the container.
     8    name: container-image
     9    namespace: {{ include "systemDefinitionNamespace" . }}
    10  spec:
    11    appliesToWorkloads:
    12      - deployments.apps
    13      - statefulsets.apps
    14      - daemonsets.apps
    15      - jobs.batch
    16    podDisruptive: true
    17    schematic:
    18      cue:
    19        template: |
    20          #PatchParams: {
    21          	// +usage=Specify the name of the target container, if not set, use the component name
    22          	containerName: *"" | string
    23          	// +usage=Specify the image of the container
    24          	image: string
    25          	// +usage=Specify the image pull policy of the container
    26          	imagePullPolicy: *"" | "IfNotPresent" | "Always" | "Never"
    27          }
    28          PatchContainer: {
    29          	_params:         #PatchParams
    30          	name:            _params.containerName
    31          	_baseContainers: context.output.spec.template.spec.containers
    32          	_matchContainers_: [ for _container_ in _baseContainers if _container_.name == name {_container_}]
    33          	_baseContainer: *_|_ | {...}
    34          	if len(_matchContainers_) == 0 {
    35          		err: "container \(name) not found"
    36          	}
    37          	if len(_matchContainers_) > 0 {
    38          		// +patchStrategy=retainKeys
    39          		image: _params.image
    40  
    41          		if _params.imagePullPolicy != "" {
    42          			// +patchStrategy=retainKeys
    43          			imagePullPolicy: _params.imagePullPolicy
    44          		}
    45          	}
    46          }
    47          patch: spec: template: spec: {
    48          	if parameter.containers == _|_ {
    49          		// +patchKey=name
    50          		containers: [{
    51          			PatchContainer & {_params: {
    52          				if parameter.containerName == "" {
    53          					containerName: context.name
    54          				}
    55          				if parameter.containerName != "" {
    56          					containerName: parameter.containerName
    57          				}
    58          				image:           parameter.image
    59          				imagePullPolicy: parameter.imagePullPolicy
    60          			}}
    61          		}]
    62          	}
    63          	if parameter.containers != _|_ {
    64          		// +patchKey=name
    65          		containers: [ for c in parameter.containers {
    66          			if c.containerName == "" {
    67          				err: "containerName must be set for containers"
    68          			}
    69          			if c.containerName != "" {
    70          				PatchContainer & {_params: c}
    71          			}
    72          		}]
    73          	}
    74          }
    75  
    76          parameter: #PatchParams | close({
    77          	// +usage=Specify the container image for multiple containers
    78          	containers: [...#PatchParams]
    79          })
    80  
    81          errs: [ for c in patch.spec.template.spec.containers if c.err != _|_ {c.err}]
    82