Skip to content

fix(orchestrator): add Helm hook annotations to sonataflow DB creation Job - #409

Closed
Fortune-Ndlovu wants to merge 1 commit into
redhat-developer:mainfrom
Fortune-Ndlovu:fix/sonataflow-job-helm-hook
Closed

fix(orchestrator): add Helm hook annotations to sonataflow DB creation Job#409
Fortune-Ndlovu wants to merge 1 commit into
redhat-developer:mainfrom
Fortune-Ndlovu:fix/sonataflow-job-helm-hook

Conversation

@Fortune-Ndlovu

Copy link
Copy Markdown
Member

Description of the change

Kubernetes Jobs have immutable spec.template fields, so helm upgrade fails when the Job spec changes between chart versions. Adding post-install/post-upgrade hook with before-hook-creation delete policy ensures the old Job is removed before the new one is created.

Which issue(s) does this PR fix or relate to

  • JIRA_issue_link

How to test changes / Special notes to the reviewer

Checklist

  • For each Chart updated, version bumped in the corresponding Chart.yaml according to Semantic Versioning.
  • For each Chart updated, variables are documented in the values.yaml and added to the corresponding README.md. The pre-commit utility can be used to generate the necessary content. Run pre-commit run --all-files to run the hooks and then push any resulting changes. The pre-commit Workflow will enforce this and warn you if needed.
  • JSON Schema template updated and re-generated the raw schema via the pre-commit hook.
  • Tests pass using the Chart Testing tool and the ct lint command.
  • If you updated the orchestrator-infra chart, make sure the versions of the Knative CRDs are aligned with the versions of the CRDs installed by the OpenShift Serverless operators declared in the values.yaml file. See Installing Knative Eventing and Knative Serving CRDs for more details.

…n Job

Kubernetes Jobs have immutable spec.template fields, so `helm upgrade`
fails when the Job spec changes between chart versions. Adding
post-install/post-upgrade hook with before-hook-creation delete policy
ensures the old Job is removed before the new one is created.
@Fortune-Ndlovu
Fortune-Ndlovu requested a review from a team as a code owner May 19, 2026 11:57
@rhdh-qodo-merge

rhdh-qodo-merge Bot commented May 19, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0)

Grey Divider


Action required

1. Hook can fail upgrades 🐞 Bug ☼ Reliability
Description
By turning the DB creation Job into a post-install/post-upgrade Helm hook, Helm will wait for the
Job to complete and mark the install/upgrade failed if it fails. With activeDeadlineSeconds=120 and
a loop that waits for DB connectivity, slower DB startups can now cause Helm installs/upgrades to
fail even though the system might have eventually recovered.
Code

charts/backstage/templates/sonataflows.yaml[R90-92]

+  annotations:
+    "helm.sh/hook": post-install,post-upgrade
+    "helm.sh/hook-delete-policy": before-hook-creation
Relevance

⭐⭐ Medium

No prior reviews on hook jobs gating upgrades/timeouts; team previously accepted hooks for upgrade
behavior (#117).

PR-#117

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The template now marks the Job as a Helm hook, and the same Job has a hard 120s active deadline plus
a wait-for-db loop; this combination means the Helm operation can be gated by DB readiness within
that deadline.

charts/backstage/templates/sonataflows.yaml[84-96]
charts/backstage/templates/sonataflows.yaml[97-129]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The create-sonataflow-database Job is now a Helm post-install/post-upgrade hook, which means Helm will wait for it; if it exceeds `activeDeadlineSeconds: 120` or otherwise fails, the whole Helm install/upgrade fails.

### Issue Context
The Job currently has a hardcoded 120s deadline and an initContainer loop that waits for DB connectivity, which may legitimately take longer on cold starts or constrained clusters.

### Fix
- Increase the default `activeDeadlineSeconds` (e.g., 300–600 seconds).
- Preferably make it configurable via `values.yaml` (e.g., `orchestrator.sonataflowPlatform.createDBJob.activeDeadlineSeconds`) and use that value in the template.

### Fix Focus Areas
- charts/backstage/templates/sonataflows.yaml[84-129]
- charts/backstage/values.yaml[1-250] (add value + documentation if not present)

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Advisory comments

2. Hook Jobs not cleaned 🐞 Bug ⚙ Maintainability
Description
The hook delete policy is only before-hook-creation, so each successful/failed hook Job can remain
in the namespace indefinitely until the next upgrade triggers another hook run. This creates
persistent completed/failed Job clutter and can leave orphaned resources that operators must clean
up manually.
Code

charts/backstage/templates/sonataflows.yaml[R90-92]

+  annotations:
+    "helm.sh/hook": post-install,post-upgrade
+    "helm.sh/hook-delete-policy": before-hook-creation
Relevance

⭐ Low

Team accepted before-hook-creation-only hook delete policy on other hooks (#117);
cleanup-on-success not enforced; hook-failed removal rejected (#170).

PR-#117
PR-#170

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The hook is configured with helm.sh/hook-delete-policy: before-hook-creation and no additional
cleanup policy or TTL, so completed hook Jobs will not be removed after they finish.

charts/backstage/templates/sonataflows.yaml[84-93]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The create-sonataflow-database hook Job is only deleted before the next hook creation, leaving completed/failed Jobs around.

### Issue Context
The Job is named deterministically (`{{ .Release.Name }}-create-sonataflow-database`), and the template does not set a TTL, so resources will accumulate across installs/upgrades.

### Fix
- Update `helm.sh/hook-delete-policy` to include cleanup after execution, e.g.:
 - `before-hook-creation,hook-succeeded` (keep failed Jobs for debugging), or
 - `before-hook-creation,hook-succeeded,hook-failed` (clean both success/failure).
- Optionally add `ttlSecondsAfterFinished` to the Job spec if cluster supports it.

### Fix Focus Areas
- charts/backstage/templates/sonataflows.yaml[84-99]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@sonarqubecloud

Copy link
Copy Markdown

@rhdh-qodo-merge

Copy link
Copy Markdown

Review Summary by Qodo

Add Helm hook annotations to sonataflow DB Job

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Add Helm hook annotations to sonataflow DB creation Job
• Ensures old Job removed before new one created during upgrades
• Prevents helm upgrade failures due to immutable spec.template fields
• Bump backstage chart version to 5.13.3
Diagram
flowchart LR
  A["sonataflows.yaml Job"] -- "add post-install/post-upgrade hooks" --> B["Helm annotations"]
  B -- "before-hook-creation delete policy" --> C["Old Job removed before upgrade"]
  C -- "prevents immutable spec errors" --> D["Successful helm upgrade"]
Loading

Grey Divider

File Changes

1. charts/backstage/Chart.yaml ⚙️ Configuration changes +1/-1

Bump backstage chart version

• Bump chart version from 5.13.2 to 5.13.3
• Follows semantic versioning for patch-level changes

charts/backstage/Chart.yaml


2. charts/backstage/README.md 📝 Documentation +2/-2

Update documentation with new version

• Update version badge from 5.13.2 to 5.13.3
• Update helm install command example with new version

charts/backstage/README.md


3. charts/backstage/templates/sonataflows.yaml 🐞 Bug fix +3/-0

Add Helm hook annotations to DB Job

• Add helm.sh/hook annotation with post-install and post-upgrade values
• Add helm.sh/hook-delete-policy annotation set to before-hook-creation
• Ensures Job is deleted before new version created during helm upgrades
• Resolves immutable spec.template field issues in Kubernetes Jobs

charts/backstage/templates/sonataflows.yaml


Grey Divider

Qodo Logo

@rhdh-qodo-merge rhdh-qodo-merge Bot added documentation Improvements or additions to documentation bug_fix labels May 19, 2026
@Fortune-Ndlovu

Copy link
Copy Markdown
Member Author

nice test pass closing PR adding changes to another PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug_fix documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant