|
9 | 9 | "net/http"
|
10 | 10 | "net/url"
|
11 | 11 | "os"
|
| 12 | + "regexp" |
12 | 13 | "strings"
|
13 | 14 | "text/tabwriter"
|
14 | 15 | "time"
|
@@ -38,6 +39,8 @@ const PruneImagesRecommendedName = "images"
|
38 | 39 |
|
39 | 40 | var errNoToken = errors.New("you must use a client config with a token")
|
40 | 41 |
|
| 42 | +const registryURLNotReachable = `(?:operation|connection) timed out|no such host` |
| 43 | + |
41 | 44 | var (
|
42 | 45 | imagesLongDesc = templates.LongDesc(`
|
43 | 46 | Remove image stream tags, images, and image layers by age or usage
|
|
48 | 51 | registry by supplying --all=false flag.
|
49 | 52 |
|
50 | 53 | 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. |
52 | 57 |
|
53 | 58 | Only a user with a cluster role %s or higher who is logged-in will be able to actually
|
54 | 59 | delete the images.
|
|
60 | 65 | Insecure connection is allowed in the following cases unless certificate-authority is
|
61 | 66 | specified:
|
62 | 67 |
|
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 |
66 | 71 | 4. user's config allows for insecure connection (the user logged in to the cluster with
|
67 | 72 | --insecure-skip-tls-verify or allowed for insecure connection)`)
|
68 | 73 |
|
@@ -139,7 +144,7 @@ func NewCmdPruneImages(f *clientcmd.Factory, parentName, name string, out io.Wri
|
139 | 144 | },
|
140 | 145 | }
|
141 | 146 |
|
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).") |
143 | 148 | cmd.Flags().BoolVar(opts.AllImages, "all", *opts.AllImages, "Include images that were not pushed to the registry but have been mirrored by pullthrough.")
|
144 | 149 | 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.")
|
145 | 150 | 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 {
|
310 | 315 |
|
311 | 316 | registryURL, err := registryPinger.Ping(registryHost)
|
312 | 317 | 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) |
314 | 322 | }
|
315 | 323 |
|
316 | 324 | options := prune.PrunerOptions{
|
|
0 commit comments