velero: add container-based config discovery support#24507
Conversation
Environment: Datadog workspace Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This branch is based on the not-yet-merged vwhitchurch/keda-discovery branch, so its own changelog.d entries (numbered for PR #24459) show up in this PR's diff against master. CI's changelog check requires any non-deleted changelog.d entry in the diff to bear the current PR's number, so rename them to #24507 here; they will be superseded once #24459 merges and this branch is rebased onto master. Environment: Datadog workspace Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: e183434 | Docs | Datadog PR Page | Give us feedback! |
Environment: Datadog workspace Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2c0dc75 to
12fbb16
Compare
This branch is based on the not-yet-merged vwhitchurch/keda-discovery branch, so its own changelog.d entries (numbered for PR #24459) show up in this PR's diff against master. CI's changelog check requires any non-deleted changelog.d entry in the diff to bear the current PR's number, so rename them to #24507 here; they will be superseded once Environment: Datadog workspace Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
df763bb to
72480f7
Compare
This stack of pull requests is managed by Graphite. Learn more about stacking. |
72480f7 to
cadfc25
Compare
09a231c to
57e665d
Compare
ac0dd17 to
3b1ed7c
Compare
7e04aa5 to
c2e0447
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff084545e2
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
84f0c16 to
8daa754
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8daa754b16
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ] | ||
| dependencies = [ | ||
| "datadog-checks-base>=37.33.0", | ||
| "datadog-checks-base>=37.41.0", |
There was a problem hiding this comment.
Bump Velero's base dependency for named-port discovery
When Velero is installed outside this source tree, the resolver may satisfy this with datadog-checks-base 37.41.0 or 37.42.0, but the generated discovery module imports candidate_ports_by_name (velero/datadog_checks/velero/config_models/discovery.py:15), which was added by the unreleased base changelog entry in the parent commit. In that environment Autodiscovery fails with ImportError before producing any Velero configs; require the first base release that contains the named-port helper.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not sure how to handle this, the datadog-checks-base with the helper is unreleased as of writing.
|
|
||
| def generate_ipc_cert_pem() -> str: | ||
| """Generate the certificate and private key format expected by the Agent IPC loader.""" | ||
| from cryptography import x509 |
There was a problem hiding this comment.
Declare cryptography for the new dev helper
When setup_discovery_agent() runs from a clean datadog-checks-dev test/install environment, this function imports cryptography, but datadog_checks_dev/pyproject.toml does not declare that dependency and the ddev hatch collector skips installing datadog-checks-base for the dev package. That makes the new datadog_checks_dev tests and any standalone use of the helper fail with ModuleNotFoundError before Kubernetes setup starts; add the dependency or avoid requiring it here.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
[Claude] Checked this: datadog_checks_dev's own hatch test env does install datadog-checks-base[deps] (which pins cryptography==48.0.1), so cryptography is available there. The collector's is_dev_package check (in ddev/src/ddev/plugin/external/hatch/environment_collector.py) refers to the ddev CLI package itself, not datadog_checks_dev — the latter is tracked separately as is_test_package and isn't excluded from the base-package install. Ran ddev --no-interactive test datadog_checks_dev -- -k test_kube_discovery to confirm: all 30 tests pass, including the two that call through setup_discovery_agent() → generate_ipc_cert_pem() → from cryptography import x509 unmocked. So no ModuleNotFoundError in the supported ddev-managed environment; leaving this as-is.
8daa754 to
e183434
Compare
Review from joepeeples is dismissed. Related teams and files:
- documentation
- velero/assets/configuration/spec.yaml
- velero/datadog_checks/velero/data/auto_conf.yaml
Validation ReportAll 21 validations passed. Show details
|

What does this PR do?
Adds container-based config discovery support to velero.
Since this is the first integration which uses Kind for its e2e tests gaining config discovery support, we also add support for config discovery E2E testing with Kind.
The new
datadog_checks_dev/datadog_checks/dev/kube_discovery.pymodule provides Kubernetes Autodiscovery e2e helpers, similar in purpose to the Docker discovery helpers.Kubernetes discovery cannot use the normal
dd_agent_check()flow directly. That fixture is useful when the test can run a check from the test host against a static config, but Kubernetes Autodiscovery depends on the Agent running inside the cluster: it needs Kubernetes RBAC, kubelet pod/node metadata, the mountedauto_conf.yaml, and network access from an Agent pod to workload pod IPs.The helper therefore sets up a lightweight in-cluster Agent target:
setup_discovery_agentdeploys a sleeping, RBAC-scoped Agent pod in thekindcluster.auto_conf.yamlmounted underconf.d/<check>.d.Tests then run one-shot commands inside that pod with
kubectl execinstead of starting a long-lived Agent:run_discovery_check_kubernetesis the Kubernetes equivalent ofdd_agent_check_discovery.assert_all_discovery_candidates_stable_kubernetesis the Kubernetes equivalent ofassert_all_discovery_candidates_stable: it copies each generated candidate config into the Agent pod and runsagent check --config-filethere. That also verifies the generated config works from inside the cluster, where the Agent reaches the workload by pod IP.This PR also adds a new discovery strategy that will be re-used by other Kubernetes integrations which will get the metrics ports from named ports instead of having to probe all ports of the container.
Motivation
https://datadoghq.atlassian.net/browse/DSCVR-524.
Review checklist (to be filled by reviewers)
qa/requiredif this PR needs QA validation, orqa/skip-qaif it does not. Exactly one of the two is required.backport/<branch-name>label to the PR and it will automatically open a backport PR once this one is merged