Git Product home page Git Product logo

Comments (3)

yangcao77 avatar yangcao77 commented on August 17, 2024

after this has been updated, remember to update the doc: #1578

from api.

vishaltak avatar vishaltak commented on August 17, 2024

@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 -

  • When my pod is available, I want to execute certain commands to make it ready for my use e.g. npm install, bundle install, etc. These commands can take quite some time and depends significantly on the project.
  • I want these commands to be executed as soon as my pod is ready.
  • It should not be dependent on any IDE i.e. execute some commands when the IDE opens up.

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

from api.

yangcao77 avatar yangcao77 commented on August 17, 2024

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.

from api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.