Merge pull request #27142 from nothiaki/feat-artifact-rm-ignore

Feat artifact rm ignore
This commit is contained in:
openshift-merge-bot[bot]
2025-10-03 15:45:28 +00:00
committed by GitHub
11 changed files with 76 additions and 0 deletions

View File

@ -169,6 +169,7 @@ func BatchRemoveArtifact(w http.ResponseWriter, r *http.Request) {
query := struct {
All bool `schema:"all"`
Artifacts []string `schema:"artifacts"`
Ignore bool `schema:"ignore"`
}{}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
@ -191,11 +192,16 @@ func BatchRemoveArtifact(w http.ResponseWriter, r *http.Request) {
removeOptions := entities.ArtifactRemoveOptions{
Artifacts: query.Artifacts,
All: query.All,
Ignore: query.Ignore,
}
artifacts, err := imageEngine.ArtifactRm(r.Context(), removeOptions)
if err != nil {
if errors.Is(err, libartifact_types.ErrArtifactNotExist) {
if removeOptions.Ignore {
utils.WriteResponse(w, http.StatusOK, artifacts)
return
}
utils.ArtifactNotFound(w, "", err)
return
}

View File

@ -116,6 +116,10 @@ func (s *APIServer) registerArtifactHandlers(r *mux.Router) error {
// in: query
// description: Remove all artifacts
// type: boolean
// - name: ignore
// in: query
// description: Ignore errors if artifact does not exist
// type: boolean
// responses:
// 200:
// $ref: "#/responses/artifactRemoveResponse"

View File

@ -52,6 +52,8 @@ type RemoveOptions struct {
All *bool
// Artifacts is a list of Artifact IDs or names to remove
Artifacts []string
// Ignore errors if IDs or names are not defined
Ignore *bool
}
// AddOptions are optional options for removing images

View File

@ -46,3 +46,18 @@ func (o *RemoveOptions) GetArtifacts() []string {
}
return o.Artifacts
}
// WithIgnore set field Ignore to given value
func (o *RemoveOptions) WithIgnore(value bool) *RemoveOptions {
o.Ignore = &value
return o
}
// GetIgnore returns value of field Ignore
func (o *RemoveOptions) GetIgnore() bool {
if o.Ignore == nil {
var z bool
return z
}
return *o.Ignore
}

View File

@ -96,6 +96,8 @@ type ArtifactRemoveOptions struct {
All bool
// Artifacts is a list of Artifact IDs or names to remove
Artifacts []string
// Ignore if a specified artifact does not exist and do not throw any error.
Ignore bool
}
type ArtifactRemoveReport = entitiesTypes.ArtifactRemoveReport

View File

@ -4,6 +4,7 @@ package abi
import (
"context"
"errors"
"fmt"
"io"
"os"
@ -12,6 +13,7 @@ import (
"github.com/containers/podman/v5/pkg/domain/entities"
"github.com/containers/podman/v5/pkg/libartifact/types"
"github.com/opencontainers/go-digest"
"github.com/sirupsen/logrus"
"go.podman.io/common/libimage"
)
@ -124,6 +126,10 @@ func (ir *ImageEngine) ArtifactRm(ctx context.Context, opts entities.ArtifactRem
for _, namesOrDigest := range namesOrDigests {
artifactDigest, err := artStore.Remove(ctx, namesOrDigest)
if err != nil {
if opts.Ignore && errors.Is(err, types.ErrArtifactNotExist) {
logrus.Debugf("Artifact with name or digest %q does not exist, ignoring error as request", namesOrDigest)
continue
}
return nil, err
}
artifactDigests = append(artifactDigests, artifactDigest)

View File

@ -57,6 +57,7 @@ func (ir *ImageEngine) ArtifactRm(_ context.Context, opts entities.ArtifactRemov
removeOptions := artifacts.RemoveOptions{
All: &opts.All,
Artifacts: opts.Artifacts,
Ignore: &opts.Ignore,
}
return artifacts.Remove(ir.ClientCtx, "", &removeOptions)