Skip to content

[CASCL-1323] kubectl-datadog: delegate OCI image parsing to go-containerregistry#2971

Merged
L3n41c merged 3 commits intomainfrom
worktree-std_docker_image_parse
May 5, 2026
Merged

[CASCL-1323] kubectl-datadog: delegate OCI image parsing to go-containerregistry#2971
L3n41c merged 3 commits intomainfrom
worktree-std_docker_image_parse

Conversation

@L3n41c
Copy link
Copy Markdown
Member

@L3n41c L3n41c commented May 5, 2026

What does this PR do?

Replaces two hand-rolled OCI image-reference parsers under cmd/kubectl-datadog/autoscaling/cluster/ with calls to github.com/google/go-containerregistry/pkg/name (already a direct dependency of the project).

  • imageRepoEndsWith → renamed imageRepoPathHasSuffix to reflect component-aware suffix matching against the registry-stripped repository path.
  • imageTag → returns the OCI tag, or empty for digest-only / tagless images.

Both helpers pre-strip a trailing @digest so combined tag@digest forms (which pkg/name parses as a name.Digest, dropping the tag) and malformed digests parse uniformly.

Motivation

The two helpers re-implemented the subtle ": is a registry port vs. a tag separator" logic by hand. Delegating to the canonical pkg/name parser makes the intent clearer and removes a chunk of bespoke parsing.

Additional Notes

No behavior change on the existing test corpus (combined tag@digest, registries with port, digest-only, single-component image names, plural-form false-positive guard).

Minimum Agent Versions

N/A — kubectl-datadog plugin only.

  • Agent: N/A
  • Cluster Agent: N/A

Describe your test plan

  • go test ./cmd/kubectl-datadog/autoscaling/cluster/install/guess/... ./cmd/kubectl-datadog/autoscaling/cluster/common/clusterinfo/... — passes
  • make lint — passes
  • make kubectl-datadog — builds

Checklist

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

/label refactoring
/label qa/skip-qa

@L3n41c L3n41c changed the title [CASCL-1323] kubectl-datadog: delegate OCI image parsing to go-containerregistry [CASCL-1323] kubectl-datadog: delegate OCI image parsing to go-containerregistry May 5, 2026
…nerregistry

imageRepoEndsWith (renamed to imageRepoPathHasSuffix) and imageTag now use
name.ParseReference from github.com/google/go-containerregistry/pkg/name
(already a direct dep) instead of open-coding the registry-port-vs-tag
heuristic. The @digest pre-strip handles combined tag@digest forms (parsed
as Digest by pkg/name) and malformed digests.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@L3n41c L3n41c force-pushed the worktree-std_docker_image_parse branch from 4d7fcf9 to 995ae59 Compare May 5, 2026 08:02
@L3n41c L3n41c marked this pull request as ready for review May 5, 2026 08:04
@L3n41c L3n41c requested a review from a team May 5, 2026 08:04
@L3n41c L3n41c requested a review from a team as a code owner May 5, 2026 08:04
@L3n41c
Copy link
Copy Markdown
Member Author

L3n41c commented May 5, 2026

@codex review

1 similar comment
@L3n41c
Copy link
Copy Markdown
Member Author

L3n41c commented May 5, 2026

@codex review

The new dependency introduced when delegating OCI image parsing to
go-containerregistry must be recorded in LICENSE-3rdparty.csv;
fix the failing `verify-licenses` CI check.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

ℹ️ 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-2
Copy link
Copy Markdown

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

Code Coverage

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 41.55% (-0.00%)

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

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.39%. Comparing base (aad76e3) to head (1b0e22f).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2971      +/-   ##
==========================================
- Coverage   41.40%   41.39%   -0.01%     
==========================================
  Files         331      331              
  Lines       28908    28911       +3     
==========================================
  Hits        11969    11969              
- Misses      16084    16086       +2     
- Partials      855      856       +1     
Flag Coverage Δ
unittests 41.39% <100.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
...autoscaling/cluster/common/clusterinfo/classify.go 90.90% <100.00%> (-0.62%) ⬇️
...dog/autoscaling/cluster/install/guess/karpenter.go 94.28% <100.00%> (-5.72%) ⬇️

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 aad76e3...1b0e22f. Read the comment docs.

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

Add a malformed-input case to TestImageRepoPathHasSuffix and a
"malformed image falls back to label" case to TestClassify_ClusterAutoscalerVersion
to exercise the `name.ParseReference` error branches in
imageRepoPathHasSuffix and imageTag. Lifts patch coverage above the
Datadog gate threshold.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@L3n41c L3n41c merged commit e49c18f into main May 5, 2026
40 checks passed
@L3n41c L3n41c deleted the worktree-std_docker_image_parse branch May 5, 2026 12:15
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