Skip to content

kubectl-datadog: redistribute autoscaling cluster packages by concern#3012

Merged
L3n41c merged 5 commits into
mainfrom
lenaic/refactor-cluster-packages
May 13, 2026
Merged

kubectl-datadog: redistribute autoscaling cluster packages by concern#3012
L3n41c merged 5 commits into
mainfrom
lenaic/refactor-cluster-packages

Conversation

@L3n41c
Copy link
Copy Markdown
Member

@L3n41c L3n41c commented May 13, 2026

What does this PR do?

Continues the refactoring started by PRs #2980 and #3000 of the cmd/kubectl-datadog/autoscaling/cluster/ tree: empties the guess/ package and removes the misnamed cluster/k8s/ package by redistributing their contents into focused common/<concern>/ packages.

Final layout under common/:

Package Role
aws/ Generic AWS-SDK primitives only — now contains just cloudformation.go
awsauth/ NEW — reads & mutates the kube-system/aws-auth ConfigMap (was split between guess/aws-auth.go and the misplaced common/aws/aws-auth.go)
clients/ AWS+k8s client factory; now also owns the kubeconfig-parsing helper (was guess.GetClusterNameFromKubeconfig, folded as unexported)
clusterautoscaler/ unchanged (introduced in #2980)
clusterinfo/ unchanged
display/ unchanged
eks/ NEW — EKS-cluster-shape helpers: authmode.go, oidcprovider.go, podidentityagent.go, privatesubnets.go (was guess/)
eksautomode/ unchanged (introduced in #2980)
helm/ unchanged
k8s/ Generic k8s primitives only — object.go (CRUD), deployment.go (finder)
karpenter/ Grew: detection (existing) + intermediate model (nodepoolsset.go) + producers (fromnodes.go, fromnodegroups.go) + CR builders (ec2nodeclass.go, nodepool.go)

After this PR, guess/ no longer exists and cluster/k8s/ no longer exists.

Motivation

  • common/aws/aws-auth.go was misnamed: it manipulates a Kubernetes ConfigMap, not an AWS-SDK resource. Together with the read-only detection in guess/aws-auth.go, it belongs in a dedicated common/awsauth/ package.
  • cluster/k8s/ was misnamed: its two files (ec2nodeclass.go, nodepool.go) build Karpenter CRDs. Karpenter-specific code belongs alongside the other Karpenter code in common/karpenter/.
  • The remaining guess/ files mixed AWS-SDK and Kubernetes API concerns under a name that no longer described any abstraction. Each file moves to a concern-focused package (common/eks/ for EKS-API helpers; common/karpenter/ for Karpenter-shape inference; common/clients/ for kubeconfig parsing).
  • Guiding rubric: common/aws/ and common/k8s/ hold generic primitives only; every concrete concern (EKS, Karpenter, aws-auth, …) gets its own common/<concern>/ package. This continues the pattern PRs [CASCL-1304] kubectl-datadog: enrich dd-cluster-info ConfigMap #2980 and [CASCL-1304] Fix Fargate profile name in dd-cluster-info ConfigMap #3000 introduced.

Branched off lenaic/merge_2980_3000 (which bundles the in-flight PRs #2980 and #3000) to minimize merge conflicts.

Additional Notes

  • Symbol renames in common/awsauth/ strip the now-redundant AwsAuth prefix: IsAwsAuthConfigMapPresentIsConfigMapPresent, EnsureAwsAuthRoleEnsureRole, RemoveAwsAuthRoleRemoveRole. RoleMapping is unchanged.
  • common/eks/ is imported as commoneks everywhere (alias) to avoid colliding with the AWS SDK's github.com/aws/aws-sdk-go-v2/service/eks already aliased eks. Same idiom as the existing commonaws/commonk8s aliases.
  • guess.GetClusterNameFromKubeconfig had a single caller (the wrapper in common/clients/clients.go) — moved next to it as the unexported clusterNameFromKubeconfig. The public clients.GetClusterNameFromKubeconfig API is unchanged.
  • Five commits, each bisectable and one concern at a time.
  • Should be reviewed AFTER [CASCL-1304] kubectl-datadog: enrich dd-cluster-info ConfigMap #2980 and [CASCL-1304] Fix Fargate profile name in dd-cluster-info ConfigMap #3000 are merged. Base branch will be re-pointed to main once those land.

Minimum Agent Versions

Not applicable — no behavior change.

  • Agent: n/a
  • Cluster Agent: n/a

Describe your test plan

  • go build ./... — passes
  • go vet ./... — passes
  • go test ./cmd/kubectl-datadog/autoscaling/cluster/... — all packages pass
  • make kubectl-datadog (includes golangci-lint) — 0 issues

No behavior change is intended; existing unit tests cover the moved functions. Manual end-to-end smoke (autoscaling cluster install / update / uninstall against a test EKS cluster) recommended before merge to validate that no call site was missed.

Checklist

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

@L3n41c L3n41c changed the title kubectl-datadog: redistribute autoscaling cluster packages by concern kubectl-datadog: redistribute autoscaling cluster packages by concern May 13, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 13, 2026

Codecov Report

❌ Patch coverage is 9.09091% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.03%. Comparing base (2c675b3) to head (ffb2176).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...d/kubectl-datadog/autoscaling/cluster/apply/run.go 0.00% 12 Missing ⚠️
...adog/autoscaling/cluster/common/awsauth/awsauth.go 16.66% 9 Missing and 1 partial ⚠️
...toscaling/cluster/common/karpenter/ec2nodeclass.go 0.00% 4 Missing ⚠️
...datadog/autoscaling/cluster/uninstall/uninstall.go 0.00% 2 Missing ⚠️
...adog/autoscaling/cluster/common/clients/clients.go 0.00% 1 Missing ⚠️
...g/autoscaling/cluster/common/karpenter/nodepool.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3012      +/-   ##
==========================================
+ Coverage   40.86%   41.03%   +0.16%     
==========================================
  Files         334      333       -1     
  Lines       28307    28388      +81     
==========================================
+ Hits        11568    11648      +80     
+ Misses      15960    15959       -1     
- Partials      779      781       +2     
Flag Coverage Δ
unittests 41.03% <9.09%> (+0.16%) ⬆️

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

Files with missing lines Coverage Δ
.../autoscaling/cluster/common/clients/clustername.go 65.00% <100.00%> (ø)
...datadog/autoscaling/cluster/common/eks/authmode.go 0.00% <ø> (ø)
...dog/autoscaling/cluster/common/eks/oidcprovider.go 71.87% <ø> (ø)
...autoscaling/cluster/common/eks/podidentityagent.go 0.00% <ø> (ø)
...g/autoscaling/cluster/common/eks/privatesubnets.go 87.23% <ø> (ø)
...scaling/cluster/common/karpenter/fromnodegroups.go 0.00% <ø> (ø)
.../autoscaling/cluster/common/karpenter/fromnodes.go 11.93% <ø> (ø)
...toscaling/cluster/common/karpenter/nodepoolsset.go 83.62% <ø> (ø)
...adog/autoscaling/cluster/common/clients/clients.go 11.81% <0.00%> (ø)
...g/autoscaling/cluster/common/karpenter/nodepool.go 0.00% <0.00%> (ø)
... and 4 more

... and 1 file 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 2c675b3...ffb2176. Read the comment docs.

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

@L3n41c
Copy link
Copy Markdown
Member Author

L3n41c commented May 13, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

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

@datadog-datadog-prod-us1
Copy link
Copy Markdown

datadog-datadog-prod-us1 Bot commented May 13, 2026

Code Coverage

Fix all issues with BitsAI

🛑 Gate Violations

🎯 1 Code Coverage issue detected

A Patch coverage percentage gate may be blocking this PR.

Patch coverage: 4.00% (threshold: 80.00%)

ℹ️ Info

🎯 Code Coverage (details)
Patch Coverage: 4.00%
Overall Coverage: 41.34% (+0.13%)

Useful? React with 👍 / 👎

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

@L3n41c
Copy link
Copy Markdown
Member Author

L3n41c commented May 13, 2026

Note on the failing Datadog PR Gates / Patch coverage percentage check

This advisory (non-blocking) gate reports ~9% patch coverage. The "uncovered" lines are the import-path updates in apply/run.go and uninstall/uninstall.go — they get counted as newly-added lines by the patch-coverage gate even though they are pure import rewrites resulting from the package moves.

No new logic was introduced by this PR; every moved function retained its existing tests (see common/eks/oidcprovider_test.go, common/eks/privatesubnets_test.go, common/awsauth/awsauth_test.go, common/clients/clustername_test.go, common/karpenter/{ec2nodeclass,nodepoolsset,fromnodes}_test.go).

Copy link
Copy Markdown
Collaborator

@clamoriniere clamoriniere left a comment

Choose a reason for hiding this comment

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

look good, only minor change linked to package refactoring

@L3n41c L3n41c marked this pull request as ready for review May 13, 2026 16:59
@L3n41c L3n41c requested review from a team as code owners May 13, 2026 16:59
Copy link
Copy Markdown
Collaborator

@clamoriniere clamoriniere left a comment

Choose a reason for hiding this comment

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

Approve again after PR move to ready state

@L3n41c L3n41c deleted the branch main May 13, 2026 21:15
@L3n41c L3n41c closed this May 13, 2026
@L3n41c L3n41c reopened this May 13, 2026
@L3n41c L3n41c changed the base branch from lenaic/merge_2980_3000 to main May 13, 2026 21:19
L3n41c and others added 5 commits May 13, 2026 23:25
Continue the redistribution of `guess/` started by PRs #2980 and #3000:
move every helper that operates on an EKS cluster object or the EKS API
into a dedicated `common/eks/` package. After this commit, `common/eks/`
contains:
  - authmode.go (was guess/clusterauthmode.go)
  - podidentityagent.go (was guess/ekspodidentityagent.go)
  - oidcprovider.go (was guess/oidcprovider.go)
  - privatesubnets.go (was guess/privatesubnets.go)

Import alias `commoneks` is used to avoid colliding with the existing
`github.com/aws/aws-sdk-go-v2/service/eks` (aliased `eks`).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`common/aws/aws-auth.go` was misnamed: it manipulates a Kubernetes
ConfigMap (`kube-system/aws-auth`), not an AWS-SDK resource. Together
with `guess/aws-auth.go` (read-only presence check), it belongs in a
dedicated `common/awsauth/` package: both files operate on the same
ConfigMap.

Function names lose the now-redundant `AwsAuth` prefix:
  - `IsAwsAuthConfigMapPresent` -> `IsConfigMapPresent`
  - `EnsureAwsAuthRole`         -> `EnsureRole`
  - `RemoveAwsAuthRole`         -> `RemoveRole`

`common/aws/` now contains only cloudformation.go (pure AWS-SDK).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The only caller of `guess.GetClusterNameFromKubeconfig` is the wrapper
`clients.GetClusterNameFromKubeconfig` in `common/clients/clients.go`.
Move the helper next to its caller as an unexported function
`clusterNameFromKubeconfig`. The public API of `common/clients/` is
unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Consolidate everything Karpenter-shaped into `common/karpenter/`,
alongside the existing detection helper:

- Intermediate model: NodePoolsSet, EC2NodeClass, NodePool,
  MetadataOptions, BlockDeviceMapping (from guess/nodepoolsset.go)
- Producers from EKS node groups: GetNodeGroupsProperties (from
  guess/nodegroupproperties.go -> fromnodegroups.go)
- Producers from running k8s Nodes: GetNodesProperties (from
  guess/nodesproperties.go -> fromnodes.go)
- CR builders: CreateOrUpdateEC2NodeClass, CreateOrUpdateNodePool
  (from cluster/k8s/{ec2nodeclass,nodepool}.go)

`cluster/k8s/` is gone (it was misnamed: those files build Karpenter
CRDs, they aren't generic k8s primitives). `common/k8s/` keeps its
narrow scope: generic object CRUD + deployment-finder.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`kube-system` and `aws-auth` each appeared 5 times across the three
functions. Promote them to package-level constants so the package's
single-ConfigMap scope is explicit at a glance.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@L3n41c L3n41c force-pushed the lenaic/refactor-cluster-packages branch from b2fc6f5 to ffb2176 Compare May 13, 2026 21:28
@L3n41c L3n41c merged commit 7f86fa0 into main May 13, 2026
36 of 39 checks passed
@L3n41c L3n41c deleted the lenaic/refactor-cluster-packages branch May 13, 2026 22:45
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.

3 participants