Skip to content

Commit 5d7f1b8

Browse files
Merge pull request openshift#16655 from miminar/image-pruning-better-help
Automatic merge from submit-queue (batch tested with PRs 16657, 16607, 16647, 16639, 16655). image-pruning: Improve help and error reporting Resolves: [bz#1469654](https://bugzilla.redhat.com/show_bug.cgi?id=1469654)
2 parents 105055e + abdaa62 commit 5d7f1b8

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

pkg/oc/admin/prune/images.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/http"
1010
"net/url"
1111
"os"
12+
"regexp"
1213
"strings"
1314
"text/tabwriter"
1415
"time"
@@ -38,6 +39,8 @@ const PruneImagesRecommendedName = "images"
3839

3940
var errNoToken = errors.New("you must use a client config with a token")
4041

42+
const registryURLNotReachable = `(?:operation|connection) timed out|no such host`
43+
4144
var (
4245
imagesLongDesc = templates.LongDesc(`
4346
Remove image stream tags, images, and image layers by age or usage
@@ -48,7 +51,9 @@ var (
4851
registry by supplying --all=false flag.
4952
5053
By default, the prune operation performs a dry run making no changes to internal registry. A
51-
--confirm flag is needed for changes to be effective.
54+
--confirm flag is needed for changes to be effective. The flag requires a valid route to the
55+
integrated Docker registry. If this command is run outside of the cluster network, the route
56+
needs to be provided using --registry-url.
5257
5358
Only a user with a cluster role %s or higher who is logged-in will be able to actually
5459
delete the images.
@@ -60,9 +65,9 @@ var (
6065
Insecure connection is allowed in the following cases unless certificate-authority is
6166
specified:
6267
63-
1. --force-insecure is given
64-
2. provided registry-url is prefixed with http://
65-
3. registry url is a private or link-local address
68+
1. --force-insecure is given
69+
2. provided registry-url is prefixed with http://
70+
3. registry url is a private or link-local address
6671
4. user's config allows for insecure connection (the user logged in to the cluster with
6772
--insecure-skip-tls-verify or allowed for insecure connection)`)
6873

@@ -139,7 +144,7 @@ func NewCmdPruneImages(f *clientcmd.Factory, parentName, name string, out io.Wri
139144
},
140145
}
141146

142-
cmd.Flags().BoolVar(&opts.Confirm, "confirm", opts.Confirm, "If true, specify that image pruning should proceed. Defaults to false, displaying what would be deleted but not actually deleting anything.")
147+
cmd.Flags().BoolVar(&opts.Confirm, "confirm", opts.Confirm, "If true, specify that image pruning should proceed. Defaults to false, displaying what would be deleted but not actually deleting anything. Requires a valid route to the integrated Docker registry (see --registry-url).")
143148
cmd.Flags().BoolVar(opts.AllImages, "all", *opts.AllImages, "Include images that were not pushed to the registry but have been mirrored by pullthrough.")
144149
cmd.Flags().DurationVar(opts.KeepYoungerThan, "keep-younger-than", *opts.KeepYoungerThan, "Specify the minimum age of an image for it to be considered a candidate for pruning.")
145150
cmd.Flags().IntVar(opts.KeepTagRevisions, "keep-tag-revisions", *opts.KeepTagRevisions, "Specify the number of image revisions for a tag in an image stream that will be preserved.")
@@ -310,7 +315,10 @@ func (o PruneImagesOptions) Run() error {
310315

311316
registryURL, err := registryPinger.Ping(registryHost)
312317
if err != nil {
313-
return fmt.Errorf("error communicating with registry %s: %v", registryHost, err)
318+
if len(o.RegistryUrlOverride) == 0 && regexp.MustCompile(registryURLNotReachable).MatchString(err.Error()) {
319+
err = fmt.Errorf("%s\n* Please provide a reachable route to the integrated registry using --registry-url.", err.Error())
320+
}
321+
return fmt.Errorf("failed to ping registry %s: %v", registryHost, err)
314322
}
315323

316324
options := prune.PrunerOptions{

0 commit comments

Comments
 (0)