Skip to content

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Sep 24, 2025

This commit implements the --replace functionality for the artifact add command, allowing users to replace existing artifacts without having to manually remove them first.

Changes made:

  • Add Replace field to ArtifactAddOptions entity types
  • Add --replace CLI flag with validation to prevent conflicts with --append
  • Implement replace logic in ABI backend to remove existing artifacts before adding
  • Update API handlers and tunnel implementation for podman-remote support
  • Add comprehensive documentation and examples to man page
  • Add e2e and system BATS tests for --replace functionality
  • Fix code formatting in pkg/bindings/artifacts/types_pull_options.go:
    • Reorder imports with proper spacing
    • Fix function declaration spacing
    • Convert spaces to proper tab indentation
    • Remove extraneous blank lines

The --replace option follows the same pattern as other podman replace options like 'podman container create --replace' and 'podman pod create --replace'. It gracefully handles cases where no existing artifact exists (no error thrown).

Usage examples:
podman artifact add --replace quay.io/myimage/artifact:latest /path/to/file
podman artifact add --replace localhost/test/artifact /tmp/newfile.txt

Fixes: Implements requested --replace functionality for artifact add command

Fixes: #27082

Does this PR introduce a user-facing change?

podman artifact add --replace option now exists.

Copy link
Contributor

openshift-ci bot commented Sep 24, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rhatdan
Once this PR has been reviewed and has the lgtm label, please assign tomsweeneyredhat for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@github-actions github-actions bot added the kind/api-change Change to remote API; merits scrutiny label Sep 24, 2025
Copy link

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.


Print usage statement.

#### **--replace**
Copy link
Member

Choose a reason for hiding this comment

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

This is duplicated, you can use @@option replace and do a small edit in options/replace.md to add artifacts in there

Copy link
Member Author

Choose a reason for hiding this comment

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

This only works with pods and containers, and would take a lot more hacking to get it to work with artifacts.

// If replace is true, try to remove existing artifact (ignore errors if it doesn't exist)
if opts.Replace {
_, _ = artStore.Remove(ctx, name)
}
Copy link
Member

Choose a reason for hiding this comment

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

my preference would be to examine the error here, and if it is a notexists error, move on; otherwise, blow up OR at the least, drop some debug out.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

Expect(listSession.OutputToStringArray()).To(HaveLen(2)) // header + 1 artifact
})

It("podman artifact add --replace nonexistent artifact", func() {
Copy link
Member

Choose a reason for hiding this comment

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

could this be added to the beginning of the previous test? at one time, @Luap99 and I were trying to combine more things like this, where they make sense, so the e2e suite didn't need to set up a new environment for the test. you're call @rhatdan

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes this is just the AI not thinking about test times. I will make the change.

@baude
Copy link
Member

baude commented Sep 24, 2025

thanks for the submission @rhatdan

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

and I guess subsequently an API test for it as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I told cursor:

You missed registering the new --replace option with @https://github.com/rhatdan/podman/blob/0bbf989fceb05f3c0f037550890bc2af0a0ef9d1/pkg/api/server/register_artifacts.go#L149-L195 and we need an API test as well

Will see how it does.

@rhatdan rhatdan force-pushed the cursor branch 2 times, most recently from ad1abd3 to a93f41c Compare September 25, 2025 13:42
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 30, 2025
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 30, 2025
This commit implements the --replace functionality for the artifact add command,
allowing users to replace existing artifacts without having to manually remove
them first.

Changes made:
- Add Replace field to ArtifactAddOptions entity types
- Add --replace CLI flag with validation to prevent conflicts with --append
- Implement replace logic in ABI backend to remove existing artifacts before adding
- Update API handlers and tunnel implementation for podman-remote support
- Add comprehensive documentation and examples to man page
- Add e2e and system BATS tests for --replace functionality
- Fix code formatting in pkg/bindings/artifacts/types_pull_options.go:
  * Reorder imports with proper spacing
  * Fix function declaration spacing
  * Convert spaces to proper tab indentation
  * Remove extraneous blank lines

The --replace option follows the same pattern as other podman replace options
like 'podman container create --replace' and 'podman pod create --replace'.
It gracefully handles cases where no existing artifact exists (no error thrown).

Usage examples:
  podman artifact add --replace quay.io/myimage/artifact:latest /path/to/file
  podman artifact add --replace localhost/test/artifact /tmp/newfile.txt

Fixes: Implements requested --replace functionality for artifact add command
Signed-off-by: Daniel J Walsh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/api-change Change to remote API; merits scrutiny release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add --replace option to podman artifact add.
5 participants