Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cosign clean: Don't log failure if the registry responds with 404 #1687

Merged
merged 2 commits into from
Mar 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions cmd/cosign/cli/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ package cli

import (
"context"
"errors"
"fmt"
"net/http"
"os"

"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/remote/transport"
"github.com/spf13/cobra"

"github.com/sigstore/cosign/cmd/cosign/cli/options"
Expand Down Expand Up @@ -92,11 +95,17 @@ func CleanCmd(ctx context.Context, regOpts options.RegistryOptions, cleanType, i
}

for _, t := range cleanTags {
fmt.Fprintf(os.Stderr, "Removing %s from %s\n", t.String(), imageRef)

err = remote.Delete(t, remoteOpts...)
if err != nil {
fmt.Fprintf(os.Stderr, "could not delete %s from %s\n: %v\n", t.String(), imageRef, err)
if err := remote.Delete(t, remoteOpts...); err != nil {
var te *transport.Error
if errors.As(err, &te) && te.StatusCode == http.StatusNotFound {
// If the tag doesn't exist, some registries may
// respond with a 404, which shouldn't be considered an
// error.
} else {
fmt.Fprintf(os.Stderr, "could not delete %s from %s\n: %v\n", t, imageRef, err)
}
} else {
fmt.Fprintf(os.Stderr, "Removed %s from %s\n", t, imageRef)
}
}

Expand Down