odo uses devfile to build and deploy components. You can also use devfile events with a component during its lifecycle. The four different types of devfile events are
Each event is an array of devfile commands to be executed. The devfile command to be executed should be of type
- name: runtime
- name: "3000/tcp"
args: [ '-f', '/dev/null']
- name: "tools"
- id: copy
commandLine: "cp /tools/myfile.txt tools.txt"
- id: initCache
- id: connectDB
- id: disconnectDB
- id: cleanup
- id: postStartCompositeCmd
label: Copy and Init Cache
PreStart events are executed as init containers for the project pod in the order they are specified.
The devfile command's
workingDir become the init container's command and as a result the devfile component container's
args or the container image's
Args are overwritten. If a composite command with
parallel: true is used, it will be executed sequentially as Kubernetes init containers only execute in sequence.
In the above example, PreStart is going to execute the devfile command
connectDB as an init container for the odo component's main pod.
Caution should be exercised when using preStart with devfile container component that mount sources. File operations with preStart on the project sync directory may result in inconsistent behaviour.
Note that odo currently does not support preStart events.
PostStart events are executed when the Kubernetes deployment for the odo component is created.
In the above example, PostStart is going to execute the composite command
postStartCompositeCmd once the odo component's deployment is created and the pod is up and running. The composite command
postStartCompositeCmd has sub-commands
initCache which will be executed in parallel.
PreStop events are executed before the Kubernetes deployment for the odo component is deleted.
In the above example, PreStop is going to execute the devfile command
disconnectDB before the odo component deployment is deleted.
PostStop events are executed after the Kubernetes deployment for the odo component is deleted.
In the above example, PostStop will execute the devfile command
cleanup after the component has been deleted.
Note that odo currently does not support postStop events.