Skip to content

Add PodSecurityContext support for DaemonSets#2120

Merged
tariq1890 merged 1 commit intoNVIDIA:mainfrom
faganihajizada:feat/custom-labels-and-security-context
Feb 20, 2026
Merged

Add PodSecurityContext support for DaemonSets#2120
tariq1890 merged 1 commit intoNVIDIA:mainfrom
faganihajizada:feat/custom-labels-and-security-context

Conversation

@faganihajizada
Copy link
Contributor

@faganihajizada faganihajizada commented Feb 11, 2026

Description

Partially fixes #1030

Adds PodSecurityContext support to both ClusterPolicy and NVIDIADriver CRs:

  • ClusterPolicy — spec.daemonsets.podSecurityContext sets pod-level security context for all DaemonSet pods managed by ClusterPolicy
  • NVIDIADriver — spec.podSecurityContext sets pod-level security context for the nvidia-driver DaemonSet pod

Design notes

  • Pod-level SecurityContext is full replace, not merge. This matches the existing pattern for tolerations and priorityClassName in applyCommonDaemonsetConfig. No embedded DaemonSet manifest currently sets a pod-level SecurityContext, so there is nothing to lose on replace.
  • For NVIDIADriver, the PodSecurityContext is templated directly into the driver DaemonSet manifest, following the same Go template pattern used for other optional spec fields (tolerations, labels, annotations).

Checklist

  • No secrets, sensitive information, or unrelated changes
  • Lint checks passing (make lint)
  • Generated assets in-sync (make validate-generated-assets)
  • Go mod artifacts in-sync (make validate-modules)
  • Test cases are added for new code paths

Testing

  • Unit tests for mergeSecurityContext (5 cases: nil target, nil defaults, empty target, merge with existing, no-overwrite)
  • Unit tests for applyCommonDaemonsetConfig (4 new cases: podSecurityContext, nil container SecurityContext, merge into existing, initContainers)
  • Unit tests for applyDaemonsetMetadataToPod (4 cases: no-op, label skip, annotations, nil labels)
  • Unit tests for applyCommonDaemonsetMetadata (existing tests still pass)

@copy-pr-bot
Copy link

copy-pr-bot bot commented Feb 11, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@faganihajizada faganihajizada force-pushed the feat/custom-labels-and-security-context branch from 57fee73 to cc94407 Compare February 11, 2026 12:20
@faganihajizada faganihajizada force-pushed the feat/custom-labels-and-security-context branch 2 times, most recently from 7b5211a to 0e21f29 Compare February 13, 2026 09:57
@rahulait
Copy link
Contributor

We need to add this to nvidiadriver CR as well if we are adding it for clusterpolicy. Basically here: https://github.com/NVIDIA/gpu-operator/blob/main/api/nvidia/v1alpha1/nvidiadriver_types.go#L199

After that, we need to update the nvidia-driver specific daemonset manifest to also include securityContext if set here: https://github.com/NVIDIA/gpu-operator/blob/main/manifests/state-driver/0500_daemonset.yaml#L86

@tariq1890
Copy link
Contributor

@faganihajizada Thanks again for the contribution! Can you amend the commit message and PR title so that it reflects the changes after review?

Please commit with the --signoff option so that the DCO checks are satisfied

@faganihajizada faganihajizada force-pushed the feat/custom-labels-and-security-context branch from 0e21f29 to 23df463 Compare February 18, 2026 08:22
@faganihajizada faganihajizada changed the title Add custom labels, securityContext to DaemonSets Add PodSecurityContext support for DaemonSets Feb 18, 2026
@faganihajizada
Copy link
Contributor Author

@faganihajizada Thanks again for the contribution! Can you amend the commit message and PR title so that it reflects the changes after review?

Please commit with the --signoff option so that the DCO checks are satisfied

Thanks @tariq1890 I updated commit message and also addressed comment from @rahulait

@faganihajizada faganihajizada force-pushed the feat/custom-labels-and-security-context branch from 23df463 to 5013497 Compare February 18, 2026 09:33
Copy link
Contributor

@rahulait rahulait left a comment

Choose a reason for hiding this comment

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

LGTM

@rahulait
Copy link
Contributor

/ok to test 5013497

@faganihajizada
Copy link
Contributor Author

@rahulait seems like there's no mechanism to regenerate the golden test files in internal/state/testdata/golden/ when the API types change. Is there a preferred way to handle this, or do you typically update them manually?

I can add a small UPDATE_GOLDEN=1 flag in the tests in a follow-up PR if it helps.

@rahulait
Copy link
Contributor

rahulait commented Feb 18, 2026

@faganihajizada unit-tests will need updates so that CI can pass. I think they are generated manually for now as I don't see any script doing that. You can just update the failing test for now to match the new fields added.

Allow users to set pod-level security context for DaemonSet pods via
spec.daemonsets.podSecurityContext (ClusterPolicy) and
spec.podSecurityContext (NVIDIADriver CR). Kubernetes applies
PodSecurityContext as defaults to all containers and init containers
in the pod (e.g. runAsUser, runAsGroup, runAsNonRoot, fsGroup).
@faganihajizada faganihajizada force-pushed the feat/custom-labels-and-security-context branch from 5013497 to e13fd80 Compare February 18, 2026 17:13
@rahulait
Copy link
Contributor

/ok to test e13fd80

fieldPath: status.hostIP
- name: DRIVER_CONFIG_DIGEST
value: "3041669332"
value: "4192128261"
Copy link
Contributor

Choose a reason for hiding this comment

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

I am a bit concerned that the DRIVER_CONFIG_DIGEST is changed here even though we don't set the .Driver.Spec.PodSecurityContext field. Is this because the struct schema has changed?

We need to keep in mind that this change will cancel fast path re-deployments where is was previously possible.

cc @cdesiniotis @karthikvetrivel

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can I help on this?

Copy link
Member

Choose a reason for hiding this comment

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

Taking a look at this. No action required on your side right now @faganihajizada, thanks!

@tariq1890 tariq1890 merged commit 0607fe6 into NVIDIA:main Feb 20, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow adding custom labels and securityContext to the components deployed by ClusterPolicy

4 participants

Comments