github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/internal/trait/init-container.cue (about) 1 "init-container": { 2 type: "trait" 3 annotations: {} 4 description: "add an init container and use shared volume with pod" 5 attributes: { 6 podDisruptive: true 7 appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"] 8 } 9 } 10 template: { 11 patch: spec: template: spec: { 12 // +patchKey=name 13 containers: [{ 14 name: context.name 15 // +patchKey=name 16 volumeMounts: [{ 17 name: parameter.mountName 18 mountPath: parameter.appMountPath 19 }] 20 }] 21 // +patchKey=name 22 initContainers: [{ 23 name: parameter.name 24 image: parameter.image 25 imagePullPolicy: parameter.imagePullPolicy 26 if parameter.cmd != _|_ { 27 command: parameter.cmd 28 } 29 if parameter.args != _|_ { 30 args: parameter.args 31 } 32 if parameter["env"] != _|_ { 33 env: parameter.env 34 } 35 36 // +patchKey=name 37 volumeMounts: [{ 38 name: parameter.mountName 39 mountPath: parameter.initMountPath 40 }] + parameter.extraVolumeMounts 41 }] 42 // +patchKey=name 43 volumes: [{ 44 name: parameter.mountName 45 emptyDir: {} 46 }] 47 } 48 parameter: { 49 // +usage=Specify the name of init container 50 name: string 51 52 // +usage=Specify the image of init container 53 image: string 54 55 // +usage=Specify image pull policy for your service 56 imagePullPolicy: *"IfNotPresent" | "Always" | "Never" 57 58 // +usage=Specify the commands run in the init container 59 cmd?: [...string] 60 61 // +usage=Specify the args run in the init container 62 args?: [...string] 63 64 // +usage=Specify the env run in the init container 65 env?: [...{ 66 // +usage=Environment variable name 67 name: string 68 // +usage=The value of the environment variable 69 value?: string 70 // +usage=Specifies a source the value of this var should come from 71 valueFrom?: { 72 // +usage=Selects a key of a secret in the pod's namespace 73 secretKeyRef?: { 74 // +usage=The name of the secret in the pod's namespace to select from 75 name: string 76 // +usage=The key of the secret to select from. Must be a valid secret key 77 key: string 78 } 79 // +usage=Selects a key of a config map in the pod's namespace 80 configMapKeyRef?: { 81 // +usage=The name of the config map in the pod's namespace to select from 82 name: string 83 // +usage=The key of the config map to select from. Must be a valid secret key 84 key: string 85 } 86 } 87 }] 88 89 // +usage=Specify the mount name of shared volume 90 mountName: *"workdir" | string 91 92 // +usage=Specify the mount path of app container 93 appMountPath: string 94 95 // +usage=Specify the mount path of init container 96 initMountPath: string 97 98 // +usage=Specify the extra volume mounts for the init container 99 extraVolumeMounts: [...{ 100 // +usage=The name of the volume to be mounted 101 name: string 102 // +usage=The mountPath for mount in the init container 103 mountPath: string 104 }] 105 } 106 }