8gears / n8n-helm-chart

A Kubernetes Helm chart for n8n a Workflow Automation Tool. Easily automate tasks across different services.
https://artifacthub.io/packages/helm/open-8gears/n8n
Apache License 2.0
187 stars 97 forks source link

Add lifecycle configuration for main deployment #30

Closed tomaszkiewicz closed 1 year ago

tomaszkiewicz commented 1 year ago

Hello,

Sometimes it doesn't make sense to build new docker image just to add some stuff to the main container. In K8S we can use lifecycle parameter for container to inject some kind of actions.

This PR adds a configuration parameter "lifecycle" to the template to accomplish that.

Sample usage (values.yaml):

lifecycle:
  postStart:
    exec:
      command: ["/bin/sh", "-c", "apk add mysql-client"]
Vad1mo commented 1 year ago

Thank you for your contribution, I like it. I wonder if it would make more sense to do it in pre, instead of post, as there might be dependencies that n8n would need to start.

tomaszkiewicz commented 1 year ago

Current K8S version has only postStart and preStop lifecycle hooks (https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/), so the only way to run it before n8n is to change entrypoint or command which I think can break some stuff when base container changes.

Lifecycle hook is not perfect, but relatively safe to make cases like package addition into the container.

Vad1mo commented 1 year ago

Ok, didn't know that.

Vad1mo commented 1 year ago

Since what K8s version is it supported? If it's older then 1.21 we might need to do a check for api version

Vad1mo commented 1 year ago

Or a comment in the values yaml file

tomaszkiewicz commented 1 year ago

It's available as long as I remember, so a couple years at least :)