github.com/oam-dev/kubevela@v1.9.11/charts/vela-core/templates/defwithtemplate/command.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/command.cue 3 apiVersion: core.oam.dev/v1beta1 4 kind: TraitDefinition 5 metadata: 6 annotations: 7 definition.oam.dev/description: Add command on K8s pod for your workload which follows the pod spec in path 'spec.template' 8 name: command 9 namespace: {{ include "systemDefinitionNamespace" . }} 10 spec: 11 appliesToWorkloads: 12 - deployments.apps 13 - statefulsets.apps 14 - daemonsets.apps 15 - jobs.batch 16 schematic: 17 cue: 18 template: | 19 #PatchParams: { 20 // +usage=Specify the name of the target container, if not set, use the component name 21 containerName: *"" | string 22 // +usage=Specify the command to use in the target container, if not set, it will not be changed 23 command: *null | [...string] 24 // +usage=Specify the args to use in the target container, if set, it will override existing args 25 args: *null | [...string] 26 // +usage=Specify the args to add in the target container, existing args will be kept, cannot be used with `args` 27 addArgs: *null | [...string] 28 // +usage=Specify the existing args to delete in the target container, cannot be used with `args` 29 delArgs: *null | [...string] 30 } 31 PatchContainer: { 32 _params: #PatchParams 33 name: _params.containerName 34 _baseContainers: context.output.spec.template.spec.containers 35 _matchContainers_: [ for _container_ in _baseContainers if _container_.name == name {_container_}] 36 _baseContainer: *_|_ | {...} 37 if len(_matchContainers_) == 0 { 38 err: "container \(name) not found" 39 } 40 if len(_matchContainers_) > 0 { 41 _baseContainer: _matchContainers_[0] 42 if _params.command != null { 43 // +patchStrategy=replace 44 command: _params.command 45 } 46 if (_params.addArgs != null || _params.delArgs != null) && _params.args != null { 47 err: "cannot set addArgs/delArgs and args at the same time" 48 } 49 _delArgs: {...} 50 if _params.delArgs != null { 51 _delArgs: {for k in _params.delArgs {(k): ""}} 52 } 53 if _params.delArgs == null { 54 _delArgs: {} 55 } 56 _args: [...string] 57 if _params.args != null { 58 _args: _params.args 59 } 60 if _params.args == null && _baseContainer.args != _|_ { 61 _args: _baseContainer.args 62 } 63 if _params.args == null && _baseContainer.args == _|_ { 64 _args: [] 65 } 66 _argsMap: {for a in _args {(a): ""}} 67 _addArgs: [...string] 68 if _params.addArgs != null { 69 _addArgs: _params.addArgs 70 } 71 if _params.addArgs == null { 72 _addArgs: [] 73 } 74 75 // +patchStrategy=replace 76 args: [ for a in _args if _delArgs[a] == _|_ {a}] + [ for a in _addArgs if _delArgs[a] == _|_ && _argsMap[a] == _|_ {a}] 77 } 78 } 79 // +patchStrategy=open 80 patch: spec: template: spec: { 81 if parameter.containers == _|_ { 82 // +patchKey=name 83 containers: [{ 84 PatchContainer & {_params: { 85 if parameter.containerName == "" { 86 containerName: context.name 87 } 88 if parameter.containerName != "" { 89 containerName: parameter.containerName 90 } 91 command: parameter.command 92 args: parameter.args 93 addArgs: parameter.addArgs 94 delArgs: parameter.delArgs 95 }} 96 }] 97 } 98 if parameter.containers != _|_ { 99 // +patchKey=name 100 containers: [ for c in parameter.containers { 101 if c.containerName == "" { 102 err: "container name must be set for containers" 103 } 104 if c.containerName != "" { 105 PatchContainer & {_params: c} 106 } 107 }] 108 } 109 } 110 111 parameter: *#PatchParams | close({ 112 // +usage=Specify the commands for multiple containers 113 containers: [...#PatchParams] 114 }) 115 116 errs: [ for c in patch.spec.template.spec.containers if c.err != _|_ {c.err}] 117