The init-container trait attaches an initialization container to the component. This type of containers are useful for setup operations and are able to work with shared storage with the component.
The following snippet shows an example application with an init container that executes a command. The init-container shares a volume
workdir that is mounted on
/work-dir and that is also mounted on the component container on
apiVersion: core.oam.dev/v1beta1 kind: Application metadata: name: my-app annotations: version: "v0.0.1" description: "My application" spec: components: - name: busybox type: worker properties: image: my-app-image:v1.0.0 cmd: ["cmd"] cpu: "0.25" memory: "200Mi" traits: - type: "init-container" # Set to init-container properties: name: init-container-name # (Required) name of init container image: my-container-image:v1.0.0 # (Required) image of init container cmd: ["cmd"] # (Optional) commands run in the init container args: ["args"] # (Optional) args run in the init container mountName: "workdir" # (Required) mount name of shared volume. workdir by default appMountPath: "/component-work-dir" # (Required) mount path of app container initMountPath: "/work-dir" # (Required) mount path of init container env: # (Optional) envs of init container - name: ENV_VAR1 # Setting the value directly value: "value1" - name: ENV_VAR2 # Using a secret to obtain a key value valueFrom: secretKeyRef: name: secret-name key: key2 - name: ENV_VAR3 # Using a configmap to obtain a key value valueFrom: configMapKeyRef: name: config-map-name key: key2