Skip to content

cmd/oras/root/attach: pass --annotation $config:* through to PackManifestOptions - #2037

Merged
TerryHowe merged 4 commits into
oras-project:mainfrom
SAY-5:fix/attach-config-annotations-2022
May 26, 2026
Merged

TerryHowe merged 4 commits into
oras-project:mainfrom
SAY-5:fix/attach-config-annotations-2022

Conversation

@SAY-5

@SAY-5 SAY-5 commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #2022.

runAttach built oras.PackManifestOptions without a ConfigAnnotations entry, so --annotation $config:key=val was silently dropped whenever the user did not also pass --config: oras-go generated the default config descriptor and never saw the annotations. runPush already wires ConfigAnnotations unconditionally, so this was strictly an attach-path oversight.

Fix

Add the same ConfigAnnotations: opts.Annotations[option.AnnotationConfig] line to the attach packOpts. When the caller did not pass any $config:* annotations the map lookup returns nil and PackManifest keeps its current default-config behaviour.

Test plan

  • go build ./cmd/oras/... clean
  • go vet ./cmd/oras/... clean
  • go test ./cmd/oras/... ./internal/... green
  • Manual: oras attach --artifact-type doc/example --annotation '$config:org.example.key=value' localhost:5000/hello:v1 hi.txt produces a manifest whose config descriptor carries {"org.example.key": "value"}.

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there any way to add a test for this?

@SAY-5

SAY-5 commented May 25, 2026

Copy link
Copy Markdown
Contributor Author

Added a unit test: Test_attachCmd_configAnnotationsWiredFromFile in attach_test.go. It writes an annotation file with a $config entry, calls opts.Packer.Parse, and asserts opts.Annotations[option.AnnotationConfig] is populated and correct.

Comment thread cmd/oras/root/attach_test.go Resolved
@SAY-5

SAY-5 commented May 25, 2026

Copy link
Copy Markdown
Contributor Author

Extracted buildAttachPackOpts helper and updated the test to call it directly, asserting PackManifestOptions.ConfigAnnotations is populated from the annotation file.

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@codecov

codecov Bot commented May 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.22%. Comparing base (4b28613) to head (830de03).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2037   +/-   ##
=======================================
  Coverage   87.22%   87.22%           
=======================================
  Files         138      138           
  Lines        5462     5465    +3     
=======================================
+ Hits         4764     4767    +3     
  Misses        417      417           
  Partials      281      281           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@TerryHowe

Copy link
Copy Markdown
Member

uggh, lint error. Please rebase too.

SAY-5 and others added 4 commits May 25, 2026 17:11
…festOptions

runAttach built PackManifestOptions without ConfigAnnotations, so
users who supplied --annotation $config:key=val (and no explicit
--config flag) saw their config annotations silently dropped: oras-go
generated the default config descriptor with no annotations. The push
subcommand already sets ConfigAnnotations unconditionally, so this is
strictly an attach-path regression; the field is harmless when the
user didn't pass any $config annotations (the map lookup returns nil).

Wire ConfigAnnotations alongside the existing ManifestAnnotations
entry. Fixes oras-project#2022

Signed-off-by: SAY-5 <[email protected]>
@SAY-5
SAY-5 force-pushed the fix/attach-config-annotations-2022 branch from 8439aa7 to 830de03 Compare May 26, 2026 00:11
@SAY-5

SAY-5 commented May 26, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main and dropped the explicit Packer. selector in the test (QF1008 fix) in 830de03.

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@TerryHowe
TerryHowe merged commit 70c20f3 into oras-project:main May 26, 2026
9 checks passed
@TerryHowe

Copy link
Copy Markdown
Member

Thanks!

TerryHowe pushed a commit to TerryHowe/oras that referenced this pull request Jun 28, 2026
…festOptions (oras-project#2037)

Signed-off-by: SAY-5 <[email protected]>
Signed-off-by: Sai Asish Y <[email protected]>
Signed-off-by: say <[email protected]>
Co-authored-by: SAY-5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

oras attach ignores --annotation $config:key=val when --config is not provided

2 participants