github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/internal/trait/sidecar.cue (about) 1 sidecar: { 2 type: "trait" 3 annotations: {} 4 description: "Inject a sidecar container to K8s pod for your workload which follows the pod spec in path 'spec.template'." 5 attributes: { 6 podDisruptive: true 7 appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"] 8 } 9 } 10 template: { 11 patch: { 12 // +patchKey=name 13 spec: template: spec: containers: [{ 14 name: parameter.name 15 image: parameter.image 16 if parameter.cmd != _|_ { 17 command: parameter.cmd 18 } 19 if parameter.args != _|_ { 20 args: parameter.args 21 } 22 if parameter["env"] != _|_ { 23 env: parameter.env 24 } 25 if parameter["volumes"] != _|_ { 26 volumeMounts: [ for v in parameter.volumes { 27 { 28 mountPath: v.path 29 name: v.name 30 } 31 }] 32 } 33 if parameter["livenessProbe"] != _|_ { 34 livenessProbe: parameter.livenessProbe 35 } 36 37 if parameter["readinessProbe"] != _|_ { 38 readinessProbe: parameter.readinessProbe 39 } 40 }] 41 } 42 parameter: { 43 // +usage=Specify the name of sidecar container 44 name: string 45 46 // +usage=Specify the image of sidecar container 47 image: string 48 49 // +usage=Specify the commands run in the sidecar 50 cmd?: [...string] 51 52 // +usage=Specify the args in the sidecar 53 args?: [...string] 54 55 // +usage=Specify the env in the sidecar 56 env?: [...{ 57 // +usage=Environment variable name 58 name: string 59 // +usage=The value of the environment variable 60 value?: string 61 // +usage=Specifies a source the value of this var should come from 62 valueFrom?: { 63 // +usage=Selects a key of a secret in the pod's namespace 64 secretKeyRef?: { 65 // +usage=The name of the secret in the pod's namespace to select from 66 name: string 67 // +usage=The key of the secret to select from. Must be a valid secret key 68 key: string 69 } 70 // +usage=Selects a key of a config map in the pod's namespace 71 configMapKeyRef?: { 72 // +usage=The name of the config map in the pod's namespace to select from 73 name: string 74 // +usage=The key of the config map to select from. Must be a valid secret key 75 key: string 76 } 77 // +usage=Specify the field reference for env 78 fieldRef?: { 79 // +usage=Specify the field path for env 80 fieldPath: string 81 } 82 } 83 }] 84 85 // +usage=Specify the shared volume path 86 volumes?: [...{ 87 name: string 88 path: string 89 }] 90 91 // +usage=Instructions for assessing whether the container is alive. 92 livenessProbe?: #HealthProbe 93 94 // +usage=Instructions for assessing whether the container is in a suitable state to serve traffic. 95 readinessProbe?: #HealthProbe 96 } 97 98 #HealthProbe: { 99 100 // +usage=Instructions for assessing container health by executing a command. Either this attribute or the httpGet attribute or the tcpSocket attribute MUST be specified. This attribute is mutually exclusive with both the httpGet attribute and the tcpSocket attribute. 101 exec?: { 102 // +usage=A command to be executed inside the container to assess its health. Each space delimited token of the command is a separate array element. Commands exiting 0 are considered to be successful probes, whilst all other exit codes are considered failures. 103 command: [...string] 104 } 105 106 // +usage=Instructions for assessing container health by executing an HTTP GET request. Either this attribute or the exec attribute or the tcpSocket attribute MUST be specified. This attribute is mutually exclusive with both the exec attribute and the tcpSocket attribute. 107 httpGet?: { 108 // +usage=The endpoint, relative to the port, to which the HTTP GET request should be directed. 109 path: string 110 // +usage=The TCP socket within the container to which the HTTP GET request should be directed. 111 port: int 112 httpHeaders?: [...{ 113 name: string 114 value: string 115 }] 116 } 117 118 // +usage=Instructions for assessing container health by probing a TCP socket. Either this attribute or the exec attribute or the httpGet attribute MUST be specified. This attribute is mutually exclusive with both the exec attribute and the httpGet attribute. 119 tcpSocket?: { 120 // +usage=The TCP socket within the container that should be probed to assess container health. 121 port: int 122 } 123 124 // +usage=Number of seconds after the container is started before the first probe is initiated. 125 initialDelaySeconds: *0 | int 126 127 // +usage=How often, in seconds, to execute the probe. 128 periodSeconds: *10 | int 129 130 // +usage=Number of seconds after which the probe times out. 131 timeoutSeconds: *1 | int 132 133 // +usage=Minimum consecutive successes for the probe to be considered successful after having failed. 134 successThreshold: *1 | int 135 136 // +usage=Number of consecutive failures required to determine the container is not alive (liveness probe) or not ready (readiness probe). 137 failureThreshold: *3 | int 138 } 139 }