Skip to content

[CONTP-1656] feat: Add DatadogInstrumentation CRD#2962

Merged
Mathew-Estafanous merged 4 commits into
mainfrom
mathew.estafanous/instrumentation-crd
May 5, 2026
Merged

[CONTP-1656] feat: Add DatadogInstrumentation CRD#2962
Mathew-Estafanous merged 4 commits into
mainfrom
mathew.estafanous/instrumentation-crd

Conversation

@Mathew-Estafanous

@Mathew-Estafanous Mathew-Estafanous commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Relates to #1605

Defines the operator-side DatadogInstrumentation CRD in datadoghq.com/v1alpha1 for future use by the Cluster Agent. This PR only publishes the API surface. It does not add an Operator reconciler or runtime controller logic.

Example

apiVersion: datadoghq.com/v1alpha1
kind: DatadogInstrumentation
metadata:
  name: redis-check
  namespace: cache
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: redis-workload
  config:
    checks:
      - integration: redisdb
        containerImage:
          - redis
        initConfig: {}
        instances:
          - host: "%%host%%"
            port: 6379
            password: "12345678"
            tags:
              - service:redis
              - env:dev
        logs:
          - type: file
            path: /var/log/redis/*.log
            source: redis
            service: redis
            tags:
              - service:redis
              - env:dev

Motivation

This CRD follows the Datadog Instrumentation RFC by defining a Kubernetes API object that the Cluster Agent can consume to apply workload instrumentation configuration.

The spec is intentionally scoped to Autodiscovery checks for now. It uses spec.targetRef for workload targeting, requires spec.config, keeps integration-specific check payloads flexible through raw initConfig and instances, and types the documented custom log collection fields while preserving unknown log fields for forward compatibility.

Additional Notes

spec.config is required. Inside spec.config.checks, integration is required for each check entry. Other check fields are optional.

The log configuration schema includes the documented Datadog Agent custom log collection fields, while preserving unknown fields on each log item for forward compatibility with Agent-supported options.

Describe your test plan

Ran:

make generate
make manifests
go test ./api/...
bin/darwin-arm64/operator-sdk bundle validate ./bundle

Also verified make generate && make manifests produces no additional diff after generated files are up to date.

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)

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Apr 29, 2026

Copy link
Copy Markdown

Code Coverage

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 41.58% (+0.06%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 17c1357 | Docs | Datadog PR Page | Give us feedback!

@codecov-commenter

codecov-commenter commented Apr 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.56%. Comparing base (953ade2) to head (17c1357).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2962      +/-   ##
==========================================
+ Coverage   40.91%   41.56%   +0.65%     
==========================================
  Files         324      331       +7     
  Lines       28743    30816    +2073     
==========================================
+ Hits        11760    12810    +1050     
- Misses      16129    17113     +984     
- Partials      854      893      +39     
Flag Coverage Δ
unittests 41.56% <ø> (+0.65%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 40 files with indirect coverage changes


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 953ade2...17c1357. Read the comment docs.

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

@Mathew-Estafanous Mathew-Estafanous added this to the v1.27.0 milestone May 4, 2026
@Mathew-Estafanous Mathew-Estafanous changed the title [CONTP-1546] feat: Add DatadogInstrumentation CRD [CONTP-1656] feat: Add DatadogInstrumentation CRD May 4, 2026
@Mathew-Estafanous
Mathew-Estafanous marked this pull request as ready for review May 4, 2026 18:52
@Mathew-Estafanous
Mathew-Estafanous requested a review from a team May 4, 2026 18:52
@Mathew-Estafanous
Mathew-Estafanous requested a review from a team as a code owner May 4, 2026 18:52
@Mathew-Estafanous
Mathew-Estafanous requested a review from a team May 4, 2026 18:53

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b591c31ae4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

"kind": "DatadogInstrumentation",
"metadata": {
"name": "redis-check",
"namespace": "cache"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove hard-coded namespace from ALM example

The new DatadogInstrumentation ALM example is pinned to "namespace": "cache", which causes the OLM “Create Example” flow to fail on clusters that don’t already have a cache namespace or where users lack cross-namespace write RBAC. Other examples rely on the user-selected namespace; this one should do the same (or use a placeholder) to avoid a broken out-of-the-box creation path.

Useful? React with 👍 / 👎.

@Mathew-Estafanous
Mathew-Estafanous merged commit d1d2b65 into main May 5, 2026
39 checks passed
@Mathew-Estafanous
Mathew-Estafanous deleted the mathew.estafanous/instrumentation-crd branch May 5, 2026 15:38
gh-worker-dd-mergequeue-cf854d Bot pushed a commit to DataDog/datadog-agent that referenced this pull request May 8, 2026
…ent dispatching (#50206)

### What does this PR do?

Introduces a `DatadogInstrumentation` CRD controller in the Cluster Agent that watches `DatadogInstrumentation` custom resources and dispatches section-level events (`EventCreate`, `EventUpdate`, `EventDelete`) to product-specific handlers.

- **Controller** (`pkg/clusteragent/instrumentation/`): Uses a key-only workqueue with a `lastSeen` store to diff current state (from the informer cache) against the last successfully reconciled state. This gives natural deduplication and prevents stale-snapshot bugs on requeue.
- **`Handler` interface**: Product handlers implement `HasSection`, `Handle`, `Validate`, and `SupportsTarget`. Each handler owns a section of the CR spec and only receives events when its section changes.
- **Status conditions**: After handlers run, the leader writes `metav1.Condition` entries back to `.status.conditions` with conflict retry.
- **Autodiscovery handler stub**: Skeleton handler that checks for `spec.config.checks` presence. Returns `ConditionUnknown` until check delivery is implemented in a follow-up.
- **Registration**: Gated behind `datadog_instrumentation.enabled: true` in the Cluster Agent controller catalog.

### Motivation

Part of the [DatadogInstrumentation CRD initiative](https://datadoghq.atlassian.net/wiki/spaces/CONTP/pages/6564659495/DatadogInstrumentation+CRD+for+Workload-Scoped+Product+Enablement) to enable workload-scoped product configuration through a Kubernetes-native CRD. This PR builds the shared controller platform that all product handlers (Autodiscovery check delivery, APM SSI, etc.) will plug into.

Depends on: DataDog/datadog-operator#2962

### Describe how you validated your changes

Unit tests covering reconciliation dispatch, section-level event classification, leader-only status writes, `lastSeen` lifecycle, event deduplication, and status condition updates with a fake dynamic client.

#### CR status is updated on each create/update/delete event
<img width="696" height="173" alt="image" src="https://github.com/user-attachments/assets/37310f64-caf8-4167-b305-331a6ead76c9" />

<img width="793" height="610" alt="image" src="https://github.com/user-attachments/assets/5f884b70-a71e-4621-92b2-f5299fd62d68" />

Co-authored-by: mathew.estafanous <[email protected]>
chouetz pushed a commit to DataDog/datadog-agent that referenced this pull request May 13, 2026
…ent dispatching (#50206)

### What does this PR do?

Introduces a `DatadogInstrumentation` CRD controller in the Cluster Agent that watches `DatadogInstrumentation` custom resources and dispatches section-level events (`EventCreate`, `EventUpdate`, `EventDelete`) to product-specific handlers.

- **Controller** (`pkg/clusteragent/instrumentation/`): Uses a key-only workqueue with a `lastSeen` store to diff current state (from the informer cache) against the last successfully reconciled state. This gives natural deduplication and prevents stale-snapshot bugs on requeue.
- **`Handler` interface**: Product handlers implement `HasSection`, `Handle`, `Validate`, and `SupportsTarget`. Each handler owns a section of the CR spec and only receives events when its section changes.
- **Status conditions**: After handlers run, the leader writes `metav1.Condition` entries back to `.status.conditions` with conflict retry.
- **Autodiscovery handler stub**: Skeleton handler that checks for `spec.config.checks` presence. Returns `ConditionUnknown` until check delivery is implemented in a follow-up.
- **Registration**: Gated behind `datadog_instrumentation.enabled: true` in the Cluster Agent controller catalog.

### Motivation

Part of the [DatadogInstrumentation CRD initiative](https://datadoghq.atlassian.net/wiki/spaces/CONTP/pages/6564659495/DatadogInstrumentation+CRD+for+Workload-Scoped+Product+Enablement) to enable workload-scoped product configuration through a Kubernetes-native CRD. This PR builds the shared controller platform that all product handlers (Autodiscovery check delivery, APM SSI, etc.) will plug into.

Depends on: DataDog/datadog-operator#2962

### Describe how you validated your changes

Unit tests covering reconciliation dispatch, section-level event classification, leader-only status writes, `lastSeen` lifecycle, event deduplication, and status condition updates with a fake dynamic client.

#### CR status is updated on each create/update/delete event
<img width="696" height="173" alt="image" src="https://github.com/user-attachments/assets/37310f64-caf8-4167-b305-331a6ead76c9" />

<img width="793" height="610" alt="image" src="https://github.com/user-attachments/assets/5f884b70-a71e-4621-92b2-f5299fd62d68" />

Co-authored-by: mathew.estafanous <[email protected]>
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.

5 participants