Skip to content

Commit bb57783

Browse files
committed
cmd/docker: areFlagsSupported: don't Ping if not needed
This is a similar fix as 006c946, which fixed this for detection of commands that were executed. Make sure we don't call the "/_ping" endpoint if we don't need to. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent cdabfa2 commit bb57783

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

cmd/docker/docker.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,22 @@ func areFlagsSupported(cmd *cobra.Command, details versionDetails) error {
401401
errs := []string{}
402402

403403
cmd.Flags().VisitAll(func(f *pflag.Flag) {
404-
if !f.Changed {
404+
if !f.Changed || len(f.Annotations) == 0 {
405405
return
406406
}
407-
if !isVersionSupported(f, details.CurrentVersion()) {
407+
// Important: in the code below, calls to "details.CurrentVersion()" and
408+
// "details.ServerInfo()" are deliberately executed inline to make them
409+
// be executed "lazily". This is to prevent making a connection with the
410+
// daemon to perform a "ping" (even for flags that do not require a
411+
// daemon connection).
412+
//
413+
// See commit b39739123b845f872549e91be184cc583f5b387c for details.
414+
415+
if _, ok := f.Annotations["version"]; ok && !isVersionSupported(f, details.CurrentVersion()) {
408416
errs = append(errs, fmt.Sprintf(`"--%s" requires API version %s, but the Docker daemon API version is %s`, f.Name, getFlagAnnotation(f, "version"), details.CurrentVersion()))
409417
return
410418
}
411-
if !isOSTypeSupported(f, details.ServerInfo().OSType) {
419+
if _, ok := f.Annotations["ostype"]; ok && !isOSTypeSupported(f, details.ServerInfo().OSType) {
412420
errs = append(errs, fmt.Sprintf(
413421
`"--%s" is only supported on a Docker daemon running on %s, but the Docker daemon is running on %s`,
414422
f.Name,

0 commit comments

Comments
 (0)