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

Update system prune flag --all confirmation prompt #2044

Merged
merged 1 commit into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
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: 9 additions & 10 deletions cmd/nerdctl/system_prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/containerd/nerdctl/pkg/api/types"
"github.com/containerd/nerdctl/pkg/clientutil"
"github.com/containerd/nerdctl/pkg/cmd/system"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -80,12 +79,6 @@ func grantSystemPrunePermission(cmd *cobra.Command, options types.SystemPruneOpt
return false, err
}

if !options.All {
logrus.Warn("Currently, `nerdctl system prune` requires --all to be specified. Skip pruning.")
// NOP
return false, nil
}

if !force {
var confirm string
msg := `This will remove:
Expand All @@ -95,10 +88,16 @@ func grantSystemPrunePermission(cmd *cobra.Command, options types.SystemPruneOpt
msg += `
- all volumes not used by at least one container`
}
msg += `
if options.All {
msg += `
- all images without at least one container associated to them
- all build cache
`
- all build cache`
} else {
msg += `
- all dangling images
- all dangling build cache`
}

msg += "\nAre you sure you want to continue? [y/N] "
fmt.Fprintf(options.Stdout, "WARNING! %s", msg)
fmt.Fscanf(cmd.InOrStdin(), "%s", &confirm)
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/types/builder_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ type BuilderBuildOptions struct {
BuildContext string
}

// BuilderPruneOptions specifies options for `nerdctl builder build`.
// BuilderPruneOptions specifies options for `nerdctl builder prune`.
type BuilderPruneOptions struct {
Stderr io.Writer
// GOptions is the global options
GOptions GlobalCommandOptions
// BuildKitHost is the buildkit host
BuildKitHost string
// All will remove all unused build cache, not just dangling ones
// All will remove all unused images and all build cache, not just dangling ones
All bool
}
2 changes: 1 addition & 1 deletion pkg/cmd/system/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Prune(ctx context.Context, client *containerd.Client, options types.SystemP
if err := image.Prune(ctx, client, types.ImagePruneOptions{
Stdout: options.Stdout,
GOptions: options.GOptions,
All: true,
All: options.All,
}); err != nil {
return nil
}
Expand Down