Skip to content

Commit 7e32d44

Browse files
authored
Merge pull request #4509 from thaJeztah/23.0_backport_lazy_ping
[23.0 backport] cmd/docker: areFlagsSupported: don't Ping if not needed
2 parents 68f7636 + 35b5ac3 commit 7e32d44

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
@@ -402,14 +402,22 @@ func areFlagsSupported(cmd *cobra.Command, details versionDetails) error {
402402
errs := []string{}
403403

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

0 commit comments

Comments
 (0)