Drop unknown fields from ssaMergeCRD #2484
Open
+450
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR makes the DDAI profile merge logic resilient to outdated DDA/DDAI CRDs. When the local SSA merge (
managedfields.FieldManager.Apply) fails with field not declared in schema, we extract the offending dotted field path, remove those fields from the merge inputs, and retry the merge. This prevents reconciliation from failing while preserving all other supported fields. A unit test is added to validate behavior when the installed CRD schema is missing a newly introduced field.Motivation
.spec.features.cws.enforcement) and blocks reconciliation. Since those fields would be pruned by the apiserver on older CRDs anyway, stripping and retrying is safe backward-compatibility mechanism. This avoids upgrade foot-guns and keeps reconciliation working even when CRD updates lag behind operator updates.latestimage which is always pulled, or users not deploying the updated Helm chart/other manifestsAdditional Notes
Anything else we should know when reviewing?
Minimum Agent Versions
Are there minimum versions of the Datadog Agent and/or Cluster Agent required?
Describe your test plan
datadog-operator-2.17.0-dev.3), with DDAI, profiles enabledcws.enabled=truecws.enforcement([CWS] add enforcement parameter #2465) -> e.g. directly edit the image field with kubectl edit{"level":"ERROR","ts":"2026-01-13T08:23:28.290Z","msg":"Reconciler error","controller":"datadogagent","controllerGroup":"datadoghq.com","controllerKind":"DatadogAgent","DatadogAgent":{"name":"datadog-agent","namespace":"datadog-agent"},"namespace":"datadog-agent","name":"datadog-agent","reconcileID":"f60073e3-dc40-4743-a862-17fd5eea41ad","error":"failed to apply merge: failed to create manager for existing fields: failed to convert new object (datadog-agent/datadog-agent; datadoghq.com/v1alpha1, Kind=DatadogAgentInternal) to smd typed: .spec.features.cws.enforcement: field not declared in schema","stacktrace":"sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).reconcileHandler\n\t/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:347\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).processNextWorkItem\n\t/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:294\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).Start.func2.2\n\t/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:255"} {"level":"INFO","ts":"2026-01-13T08:23:31.315Z","logger":"KubeAPIWarningLogger","msg":"unknown field \"spec.features.cws.enforcement\""}Checklist
bug,enhancement,refactoring,documentation,tooling, and/ordependenciesqa/skip-qalabel