Skip to content

[CASCL-1323] Extract generic FindKarpenterInstallation helper#2970

Merged
L3n41c merged 2 commits into
mainfrom
lenaic/CASCL-1323-extract-find-karpenter-installation
May 4, 2026
Merged

[CASCL-1323] Extract generic FindKarpenterInstallation helper#2970
L3n41c merged 2 commits into
mainfrom
lenaic/CASCL-1323-extract-find-karpenter-installation

Conversation

@L3n41c

@L3n41c L3n41c commented May 4, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Extracts the Karpenter detection helper refactor from #2961 (Add update subcommand to kubectl-datadog autoscaling cluster) so that PR can be split into reviewable chunks.

  • Replaces guess.FindForeignKarpenterInstallation(ctx, clientset, targetNamespace) (*ForeignKarpenter, error) with a generic guess.FindKarpenterInstallation(ctx, clientset) (*KarpenterInstallation, error).
  • The new helper returns the first Karpenter controller Deployment found on the cluster, with the kubectl-datadog sentinel labels (InstalledBy, InstallerVersion) captured.
  • Adds an IsOwn() method on KarpenterInstallation (kubectl-datadog vs third-party).
  • Foreign-vs-ours classification now lives at the install caller:
    if k \!= nil && (\!k.IsOwn() || k.Namespace \!= karpenterNamespace) {
        return displayForeignKarpenterMessage(cmd, clusterName, k)
    }
    This preserves install's externally observable behaviour: empty cluster → proceed; ours in target namespace → proceed; ours in another namespace → foreign-message + nil; third-party → foreign-message + nil.

Motivation

The future kubectl datadog autoscaling cluster update subcommand (separate PR) needs the same cluster scan but the inverse decision (require an install AND require it to be ours). Sharing a single generic helper avoids duplicating the controller-detection logic.

The helper assumes at most one Karpenter installation per cluster — install/update guards prevent multiple controllers coexisting in normal use. The trade-off is documented in the helper's doc comment and pinned by the first match wins when multiple Karpenters coexist subtest so it cannot drift silently.

Additional Notes

This is a strict subset of #2961's guess/karpenter.go change plus the matching install callsite adjustment. None of #2961's other refactors (RunOptions/Run, IOStreams migration, KarpenterStackName/DDKarpenterStackName/DetectedInstallMode, the update command itself) ship here — they remain in #2961, which will rebase on main once this lands.

The InstallerVersion field is populated but no current caller reads it; it's exposed now so the upcoming update PR doesn't need to come back and widen the struct.

Minimum Agent Versions

N/A — kubectl plugin only.

Describe your test plan

  • make kubectl-datadog passes lint (0 issues) and builds.
  • go test ./cmd/kubectl-datadog/autoscaling/cluster/install/... is green, including the new TestFindKarpenterInstallation/first_match_wins_when_multiple_Karpenters_coexist subtest and TestKarpenterInstallationIsOwn.
  • git diff main -- cmd/kubectl-datadog/autoscaling/cluster/install/install.go shows only the foreign-detection block reshape and the displayForeignKarpenterMessage parameter type change — no other behavioural drift.

Checklist

  • PR has at least one valid label: refactoring
  • PR has a milestone or the qa/skip-qa label
  • All commits are signed

Replace install-specific FindForeignKarpenterInstallation with a generic
FindKarpenterInstallation that returns the first Karpenter controller
Deployment found, with InstalledBy / InstallerVersion sentinel labels
captured. Foreign-vs-ours classification moves to the install caller
(`\!k.IsOwn() || k.Namespace \!= karpenterNamespace`); install's behaviour
table is preserved. The helper assumes at most one Karpenter per cluster
— pinned by `first match wins when multiple Karpenters coexist`.

Prepares the upcoming `kubectl datadog autoscaling cluster update`
subcommand (separate PR), which needs the same scan but the inverse
decision (require an install AND require it to be ours).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@codecov-commenter

codecov-commenter commented May 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.41%. Comparing base (35814b5) to head (1086b72).

Files with missing lines Patch % Lines
...bectl-datadog/autoscaling/cluster/install/steps.go 20.00% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2970   +/-   ##
=======================================
  Coverage   41.41%   41.41%           
=======================================
  Files         331      331           
  Lines       28891    28895    +4     
=======================================
+ Hits        11964    11967    +3     
- Misses      16072    16073    +1     
  Partials      855      855           
Flag Coverage Δ
unittests 41.41% <90.00%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
...dog/autoscaling/cluster/install/guess/karpenter.go 100.00% <100.00%> (ø)
...bectl-datadog/autoscaling/cluster/install/steps.go 20.00% <20.00%> (-0.08%) ⬇️

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 35814b5...1086b72. Read the comment docs.

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

@datadog-prod-us1-5

datadog-prod-us1-5 Bot commented May 4, 2026

Copy link
Copy Markdown

Code Coverage

🎯 Code Coverage (details)
Patch Coverage: 88.57%
Overall Coverage: 41.56% (+0.00%)

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

@L3n41c

L3n41c commented May 4, 2026

Copy link
Copy Markdown
Member Author

@codex review

@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: 65d5b1ef0a

ℹ️ 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 cmd/kubectl-datadog/autoscaling/cluster/install/guess/karpenter.go
@L3n41c L3n41c changed the title [CASCL-1323] Extract generic FindKarpenterInstallation helper [CASCL-1323] Extract generic FindKarpenterInstallation helper May 4, 2026
@L3n41c
L3n41c marked this pull request as ready for review May 4, 2026 15:37
@L3n41c
L3n41c requested a review from a team May 4, 2026 15:37
@L3n41c
L3n41c requested a review from a team as a code owner May 4, 2026 15:37
@L3n41c
L3n41c force-pushed the lenaic/CASCL-1323-extract-find-karpenter-installation branch from 69ae116 to 46538ab Compare May 4, 2026 17:47
…tallation

PR #2968 split install.go into multiple files; the foreign-Karpenter
detection block and `displayForeignKarpenterMessage` moved to steps.go,
and the matching tests moved to steps_test.go. Conflicts resolved by
taking origin/main's slim install.go / install_test.go and re-applying
this branch's `FindKarpenterInstallation` + `KarpenterInstallation`
adaptation against the new locations (steps.go callsite + display
signature; steps_test.go type + assertion message).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@L3n41c
L3n41c force-pushed the lenaic/CASCL-1323-extract-find-karpenter-installation branch from 46538ab to 1086b72 Compare May 4, 2026 17:49
@L3n41c
L3n41c merged commit aad76e3 into main May 4, 2026
40 checks passed
@L3n41c
L3n41c deleted the lenaic/CASCL-1323-extract-find-karpenter-installation branch May 4, 2026 19:47
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.

4 participants