Skip to content

[CONTP-1504] Create DatadogCSIDriver from DDA when createDatadogCSIDriver=true#2857

Draft
tbavelier wants to merge 23 commits intomainfrom
tbavelier/create-ddcsi-from-dda
Draft

[CONTP-1504] Create DatadogCSIDriver from DDA when createDatadogCSIDriver=true#2857
tbavelier wants to merge 23 commits intomainfrom
tbavelier/create-ddcsi-from-dda

Conversation

@tbavelier
Copy link
Copy Markdown
Member

@tbavelier tbavelier commented Apr 2, 2026

What does this PR do?

When spec.global.csi.enabled=true and the new spec.global.csi.createDatadogCSIDriver=true field is set, the DatadogAgent controller automatically creates a DatadogCSIDriver custom resource owned by the DDA.

This gives users a single-CR experience: configure CSI on their DatadogAgent and the operator handles creating the DatadogCSIDriver. The DatadogCSIDriver controller then reconciles it (DaemonSet, CSIDriver object, etc.).

Key behaviors:

  • createDatadogCSIDriver defaults to false — no behavior change for existing users
  • The DatadogCSIDriver is treated as a desired-state object (like DDAI): external modifications are reconciled back
  • If the DatadogCSIDriver CRD is not installed and the field is not set, nothing happens (safe for clusters without the CRD)
  • If the CRD is not installed but the field is set, an error is returned
  • Cleanup: toggling the field off deletes the operator-owned DatadogCSIDriver; manually-created ones are left alone
  • Only works in the V3 reconcile path (DatadogAgentInternalEnabled=true)

Motivation

Simplify the user experience for CSI driver setup. Instead of requiring users to create both a DatadogAgent and a separate DatadogCSIDriver, they can opt into automatic creation from their DDA spec.

Additional Notes

  • The created DatadogCSIDriver currently has an empty spec (the DatadogCSIDriver controller applies its own defaults). A follow-up PR will construct the spec based on relevant DDA fields.
  • The DatadogCSIDriver lifecycle is managed via direct API calls (create/update/delete) rather than the dependency store, because the store only supports built-in Kubernetes types. This is documented in code comments.
  • Requires the DatadogCSIDriver CRD to be installed and the controller to be enabled (--datadogCSIDriverEnabled).

Minimum Agent Versions

N/A — this is an operator-level feature.

Describe your test plan

Unit tests in ddcsi_test.go cover:

  • CSI disabled — no resource created
  • CSI enabled + createDatadogCSIDriver=true — resource created with owner reference
  • CRD not available — error returned
  • createDatadogCSIDriver=false — no resource created
  • Idempotency — second reconcile is a no-op
  • Spec drift — external modifications reconciled back to desired state
  • Cleanup on disable — owned resource deleted
  • Cleanup skips unowned — manually-created resources left alone
  • Cleanup when CRD absent — no error

Checklist

  • PR has at least one valid label: bug, enhancement, refactoring, documentation, tooling, and/or dependencies
  • PR has a milestone or the qa/skip-qa label
  • All commits are signed (see: signing commits)

tbavelier and others added 9 commits April 2, 2026 14:03
Define the DatadogCSIDriver, DatadogCSIDriverSpec, DatadogCSIDriverOverride,
and DatadogCSIDriverStatus types in api/datadoghq/v1alpha1. The CRD enables
declarative management of the Datadog CSI Driver via the operator, replacing
the standalone Helm chart deployment.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Controller-runtime wiring for the DatadogCSIDriver reconciler. Watches the
primary CR with GenerationChangedPredicate, owned DaemonSets for all changes
(including status), and CSIDriver objects via label-based enqueue for drift
detection on the cluster-scoped resource.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implements the reconciliation logic for the DatadogCSIDriver controller:
- Deferred SSA status patch with ObservedGeneration tracking
- CSIDriver object management with Get+DeepEqual+Update for full drift reversion
- DaemonSet management with the same pattern, including label enforcement
- Override system with merge-by-name semantics (env vars, volumes, mounts)
- Image resolution via pkg/images (supports tag-only overrides)
- Finalizer-based cleanup of the cluster-scoped CSIDriver on deletion
- Comprehensive unit tests covering creation, updates, drift, deletion, overrides

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Register the controller in setup.go with a feature flag and add the
-datadogCSIDriverEnabled flag (default: false) to cmd/main.go. Also
registers the storagev1 scheme required for CSIDriver object management.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Treat the DatadogCSIDriver as a desired-state object like DDAI: if
someone modifies it externally, reconcile it back to the operator's
desired state on the next loop. Uses apiequality.Semantic.DeepEqual
to compare specs and kubernetes.UpdateFromObject to update.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 2, 2026

Codecov Report

❌ Patch coverage is 71.92982% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.12%. Comparing base (189f12c) to head (932c38e).

Files with missing lines Patch % Lines
internal/controller/datadogagent/ddcsi.go 74.54% 7 Missing and 7 partials ⚠️
internal/controller/datadogagent/dependencies.go 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2857      +/-   ##
==========================================
+ Coverage   40.06%   40.12%   +0.06%     
==========================================
  Files         319      320       +1     
  Lines       28039    28096      +57     
==========================================
+ Hits        11233    11274      +41     
- Misses      15983    15991       +8     
- Partials      823      831       +8     
Flag Coverage Δ
unittests 40.12% <71.92%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/controller/datadogagent/dependencies.go 60.86% <0.00%> (-2.77%) ⬇️
internal/controller/datadogagent/ddcsi.go 74.54% <74.54%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 189f12c...932c38e. Read the comment docs.

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

Base automatically changed from tbavelier/csi-driver-standalone-v2 to main April 8, 2026 14:29
@tbavelier tbavelier changed the title Create DatadogCSIDriver from DDA when createDatadogCSIDriver=true [CONTP-1504] Create DatadogCSIDriver from DDA when createDatadogCSIDriver=true Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants