Skip to content

[CONTP-1604] When user updates k8s genericresource, force re-create if deleted#2909

Merged
tbavelier merged 12 commits intomainfrom
tbavelier/generic-resource-improvements
Apr 17, 2026
Merged

[CONTP-1604] When user updates k8s genericresource, force re-create if deleted#2909
tbavelier merged 12 commits intomainfrom
tbavelier/generic-resource-improvements

Conversation

@tbavelier
Copy link
Copy Markdown
Member

@tbavelier tbavelier commented Apr 16, 2026

What does this PR do?

During the update loop of a genericresource, sends a create instead of update if not found: 19d3182
Move test / mocking implementation to a _test files to avoid linter failures and decouple production code from test (not 100% due to the wiring still in getHandler) 1c5f8e6
Remove validation.go since it's enforced at CRD admission anyway: b83f014

Motivation

Avoid having to wait for defaultForceSync in the following scenario:

  1. Resource is created from DDGR
  2. Resource is deleted from an external source (e.g. the UI)
  3. User updates the source of truth (the DDGR manifest)
  4. Resource will be stuck in error until the next force sync that creates when not found
  5. Resource is reconciled properly (exists with the latest spec)

This PR removes step 4

Additional Notes

Anything else we should know when reviewing?

Minimum Agent Versions

Are there minimum versions of the Datadog Agent and/or Cluster Agent required?

  • Agent: vX.Y.Z
  • Cluster Agent: vX.Y.Z

Describe your test plan

Follow the steps from motivation, and ensure resource is created after the DDGR manifest update

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)

wdhif and others added 4 commits April 15, 2026 12:04
Signed-off-by: Wassim DHIF <wassim.dhif@datadoghq.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Wassim DHIF <wassim.dhif@datadoghq.com>
@tbavelier tbavelier added this to the v1.27.0 milestone Apr 16, 2026
@tbavelier tbavelier added the enhancement New feature or request label Apr 16, 2026
@tbavelier tbavelier changed the title When user updates k8s genericresource, force re-create if deleted [CONTP-1604] When user updates k8s genericresource, force re-create if deleted Apr 16, 2026
MockHandler and its state (mockGetErr, mockUpdateErr, etc.) lived in
utils.go but were only referenced from test files, causing golangci-lint
to flag them as unused (and the error vars as violating errname). Moved
all mock code to mock_handler_test.go and registered the handler via
init(), with a testHandlers map in utils.go as the bridge.
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 40.00%. Comparing base (7c966f8) to head (b83f014).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2909      +/-   ##
==========================================
+ Coverage   39.99%   40.00%   +0.01%     
==========================================
  Files         320      320              
  Lines       28122    28107      -15     
==========================================
- Hits        11247    11245       -2     
+ Misses      16052    16042      -10     
+ Partials      823      820       -3     
Flag Coverage Δ
unittests 40.00% <100.00%> (+0.01%) ⬆️

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

Files with missing lines Coverage Δ
...al/controller/datadoggenericresource/controller.go 63.77% <100.00%> (+9.87%) ⬆️
...nternal/controller/datadoggenericresource/utils.go 82.22% <100.00%> (-4.22%) ⬇️

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 7c966f8...b83f014. Read the comment docs.

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

Signed-off-by: Wassim DHIF <wassim.dhif@datadoghq.com>
@datadog-official
Copy link
Copy Markdown

datadog-official Bot commented Apr 16, 2026

Code Coverage

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 40.10% (+0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: b83f014 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

wdhif and others added 3 commits April 16, 2026 14:31
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Wassim DHIF <wassim.dhif@datadoghq.com>
Signed-off-by: Wassim DHIF <wassim.dhif@datadoghq.com>
@wdhif wdhif force-pushed the CONTP-1586/wassim.dhif/ddgr_dashboard branch from aedb981 to 070fc64 Compare April 16, 2026 12:44
Base automatically changed from CONTP-1586/wassim.dhif/ddgr_dashboard to main April 16, 2026 13:48
@tbavelier tbavelier marked this pull request as ready for review April 16, 2026 13:52
@tbavelier tbavelier requested a review from a team April 16, 2026 13:52
Copy link
Copy Markdown

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

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: c5452f09df

ℹ️ 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".

Comment thread internal/controller/datadoggenericresource/utils.go
// +kubebuilder:validation:Enum=dashboard;downtime;monitor;notebook;synthetics_api_test;synthetics_browser_test
Type SupportedResourcesType `json:"type"`
// JsonSpec is the specification of the API object
// +kubebuilder:validation:MinLength=1
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is what the validation.go used to do but it's better to enforce it at CRD level since we don't do any complex validation

@tbavelier tbavelier merged commit 99a6fc8 into main Apr 17, 2026
38 checks passed
@tbavelier tbavelier deleted the tbavelier/generic-resource-improvements branch April 17, 2026 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants