Skip to content

Avoid checking job completion in init containers #203

@emmanuelmathot

Description

@emmanuelmathot

Problem description

Each API service has an init container that check the PGSTACBootstrap job to be complete. This is not very efficient as it starts 4 init containers doing the same thing. It also requires specific role bindings for monitoring the job.

Proposed changed: Use Helm Hooks

We can replace this current behavior with Helm hooks to control the execution order. Here's the plan:

  1. Add Helm hook annotations to the pgstacbootstrap job:

    • helm.sh/hook: post-install,post-upgrade - Ensures the job runs after the postgres dependency is installed
    • helm.sh/hook-weight: -5 - Lower weight means it runs earlier in the hook sequence
    • helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded - Cleans up the job after it succeeds
  2. Remove the initContainer from the deployment that waits for the pgstacbootstrap job

  3. Add a hook weight to the deployment to ensure it runs after the pgstacbootstrap job:

    • helm.sh/hook-weight: 0 (higher than the pgstacbootstrap job's weight)

This approach will:

  • Ensure the pgstacbootstrap job runs after the postgres dependency is installed
  • Make the deployment wait for the pgstacbootstrap job to complete before starting
  • Remove the need for the kubectl polling in the initContainer
Implementation Details

The modified pgstacbootstrap job would look like:

apiVersion: batch/v1
kind: Job
metadata:
  name: pgstacbootstrap
  labels:
    app: pgstacbootstrap
  annotations:
    helm.sh/hook: post-install,post-upgrade
    helm.sh/hook-weight: "-5"
    helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded

And we would remove the initContainer from the deployment.

Expected Behaviour

PGSTACBootstrap as pre-hook job shall be managed by Helm that will pursue the deployment once the job is complete

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions