Skip to content

feat: support temp volume as volumeClaimTemplate in StatefulSet [backport #1077] - #1078

Merged
kalbasit merged 1 commit into
release-0.9from
backport-1077-to-release-0.9
Mar 12, 2026
Merged

kalbasit merged 1 commit into
release-0.9from
backport-1077-to-release-0.9

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

Bot-based backport to release-0.9, triggered by a label in #1077.

This change allows the ncps Helm chart to use a volumeClaimTemplate for the temporary volume when the application is running in StatefulSet mode and config.cache.tempVolume.type is set to pvc.

Previously, the temporary volume was always rendered as a regular volume in the Pod spec, which meant all replicas in a StatefulSet would share the same PVC if a name was provided, or each would get a separate emptyDir if that was the type.

By using volumeClaimTemplates, Kubernetes automatically creates a unique PVC for each replica, providing better isolation and persistence for temporary data (like chunking/downloads) in HA deployments.

The temp-pvc.yaml template was updated to only render in deployment mode, as it's redundant (and potentially conflicting) for StatefulSet mode.

Tests were updated to verify the correct rendering in both StatefulSet and Deployment modes.

This change allows the ncps Helm chart to use a volumeClaimTemplate for
the temporary volume when the application is running in StatefulSet mode
and config.cache.tempVolume.type is set to pvc.

Previously, the temporary volume was always rendered as a regular volume
in the Pod spec, which meant all replicas in a StatefulSet would share
the same PVC if a name was provided, or each would get a separate
emptyDir if that was the type.

By using volumeClaimTemplates, Kubernetes automatically creates a unique
PVC for each replica, providing better isolation and persistence for
temporary data (like chunking/downloads) in HA deployments.

The temp-pvc.yaml template was updated to only render in deployment
mode, as it's redundant (and potentially conflicting) for StatefulSet
mode.

Tests were updated to verify the correct rendering in both StatefulSet
and Deployment modes.

(cherry picked from commit 4d4123e)
@kalbasit
kalbasit enabled auto-merge (squash) March 12, 2026 16:26
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request helm labels Mar 12, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Helm chart to properly manage temporary volumes for applications deployed as StatefulSets. Previously, temporary PVCs could lead to shared storage or emptyDir volumes across replicas. The changes introduce volumeClaimTemplates for StatefulSets, allowing Kubernetes to dynamically provision unique PVCs for each replica, which is crucial for high-availability deployments requiring isolated and persistent temporary storage. The update also refines the conditional rendering of standalone temporary PVCs to prevent conflicts between deployment and StatefulSet configurations.

Highlights

  • StatefulSet Temporary Volume Support: Implemented support for using volumeClaimTemplate for temporary volumes when the application runs in StatefulSet mode and config.cache.tempVolume.type is set to pvc. This ensures each replica gets a unique, dynamically provisioned PVC.
  • PVC Isolation and Persistence: By leveraging volumeClaimTemplates, Kubernetes automatically creates a unique PersistentVolumeClaim (PVC) for each replica in a StatefulSet, providing improved isolation and persistence for temporary data.
  • Conditional temp-pvc.yaml Rendering: The temp-pvc.yaml template was updated to only render when the application is in deployment mode, avoiding conflicts and redundancy when StatefulSets manage temporary PVCs via templates.
  • Enhanced Test Coverage: New and updated tests verify the correct rendering of temporary volumes and volumeClaimTemplates in both StatefulSet and Deployment modes, covering various configurations including existing claims and custom annotations/selectors.
Changelog
  • charts/ncps/templates/_helpers.tpl
    • Added a new Helm template ncps.tempVolumeClaimTemplate to define the structure for temporary PersistentVolumeClaim templates, including metadata, access modes, resources, storage class, and selector.
  • charts/ncps/templates/statefulset.yaml
    • Modified the inclusion logic for ncps.tempVolume to ensure it's only rendered if the temporary volume type is not pvc or if an existing PVC claim is specified, preventing redundant volume definitions.
    • Introduced conditional logic to render volumeClaimTemplates for temporary PVCs within the StatefulSet spec, utilizing the newly defined ncps.tempVolumeClaimTemplate when a temporary PVC is configured without an existing claim.
  • charts/ncps/templates/temp-pvc.yaml
    • Updated the rendering condition for the temporary PersistentVolumeClaim template to explicitly check if the application mode is 'deployment', ensuring it's not created when StatefulSets handle temporary PVCs via templates.
  • charts/ncps/tests/temp_volume_test.yaml
    • Added a test case to assert that the tmp volume is not included in spec.template.spec.volumes when a StatefulSet uses a PVC for temporary storage without an existing claim.
    • Introduced a test case to verify that volumeClaimTemplate is correctly generated for the tmp volume when the type is pvc and no existing claim is provided in StatefulSet mode.
    • Added a test case to confirm that an existing PVC is correctly referenced in volumes and volumeClaimTemplates are not generated when an existing claim is specified for a StatefulSet.
    • Updated an existing test case for temp-pvc.yaml to explicitly set mode: deployment when checking for PVC creation, aligning with the new conditional rendering logic.
    • Added a test case to ensure that temp-pvc.yaml does not create a PVC document when the application is in StatefulSet mode.
    • Expanded an existing test case to explicitly set mode: deployment when asserting that no PVC is created for temp-pvc.yaml if an existing claim is provided.
    • Added a test case to verify that annotations and selectors are correctly included in the volumeClaimTemplate for temporary volumes in StatefulSet mode.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly implements support for using volumeClaimTemplate for temporary volumes in a StatefulSet, which is a valuable enhancement for high-availability deployments. The logic is sound, the changes are well-contained, and the new test cases provide good coverage. I have one suggestion to improve the robustness of the new helper template against potential misconfiguration.

Comment on lines +290 to +293
accessModes:
{{- range .Values.config.cache.tempVolume.pvc.accessModes }}
- {{ . | quote }}
{{- end }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation will render an invalid accessModes field if .Values.config.cache.tempVolume.pvc.accessModes is an empty list, which would cause the Helm release to fail during Kubernetes resource validation. To improve robustness, it's better to add a validation check that fails the template rendering with a clear error message if accessModes is empty.

    accessModes:
      {{- if not .Values.config.cache.tempVolume.pvc.accessModes }}
      {{- fail "config.cache.tempVolume.pvc.accessModes must not be empty when tempVolume.type is pvc" }}
      {{- end }}
      {{- range .Values.config.cache.tempVolume.pvc.accessModes }}
      - {{ . | quote }}
      {{- end }}

@codecov

codecov Bot commented Mar 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 5.04%. Comparing base (ee46bad) to head (2af2710).
⚠️ Report is 1 commits behind head on release-0.9.

Additional details and impacted files
@@             Coverage Diff             @@
##           release-0.9   #1078   +/-   ##
===========================================
  Coverage         5.04%   5.04%           
===========================================
  Files                6       6           
  Lines              436     436           
===========================================
  Hits                22      22           
  Misses             410     410           
  Partials             4       4           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kalbasit
kalbasit merged commit 45a2f3f into release-0.9 Mar 12, 2026
13 checks passed
@kalbasit
kalbasit deleted the backport-1077-to-release-0.9 branch March 12, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request helm size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant