Open yangcao77 opened 3 months ago
after this has been updated, remember to update the doc: https://github.com/devfile/api/issues/1578
@yangcao77 👋🏼
How do we plan to implement this? Would it be through Kubernetes postStart and preStop lifecycle?
In which case, would it be beneficial to have a side-effect as described in their documentation - https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/#discussion
Kubernetes sends the postStart event immediately after the Container is created. There is no guarantee, however, that the postStart handler is called before the Container's entrypoint is called. The postStart handler runs asynchronously relative to the Container's code, but Kubernetes' management of the container blocks until the postStart handler completes. The Container's status is not set to RUNNING until the postStart handler completes.
Kubernetes sends the preStop event immediately before the Container is terminated. Kubernetes' management of the Container blocks until the preStop handler completes, unless the Pod's grace period expires.
My use case is as follows -
If devfile has the option to specify postStart
, I would be tempted to run npm install
is a postStart command. However, as described from the Kubernetes docs, there is no guarantee that it would run before the container's entrypoint and that it would block the readiness status of the pod until those command successfully execute. npm install
can take some amount of time depending on the project.
How do we reconcile these things? This makes me think is it a bad idea to use Kubernetes lifecycle hooks here? Curious to know what the team thinks about this problem and the potential solutions.
Thanks
Hi @vishaltak . Devfile library will use the container lifecycle as described here: https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/, and generate a proper pod definition.
Devfile library does not handle the reconcile of any Kube resources. So I can give suggestions as what I would try, but not from Devfile's perspective.
If you want your npm install
always run after the entrypoint, I would try overwrite the container entrypoint and set pod spec.container.command
to npm install && <ENTRYPOINT_COMMAND>
, or even set the npm install
command in the container's Dockerfile.
Another way is to have a initContainer and volumeMount, to run npm install
to get all your dependencies.
Regarding on the pod readiness, since your container would rely on the npm or bundle installation, I do not have any good suggestions.
/kind user-story
Which area is this user story related to?
/area library
User Story
Being raised in https://kubernetes.slack.com/archives/C02SX9E5B55/p1717391635662029
As a devfile library user I want to convert devfile to kube resource definitions with postStart & beforeStop events defined, so that the generated container definition will have the commands in the spec.
Acceptance Criteria