Skip to content

Commit 65d3f78

Browse files
authored
Merge pull request #3904 from thaJeztah/fix_lazy_evaluate
cmd/docker: make feature detection lazy again
2 parents 8fc1444 + 006c946 commit 65d3f78

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

cmd/docker/docker.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,21 @@ func areFlagsSupported(cmd *cobra.Command, details versionDetails) error {
416416
func areSubcommandsSupported(cmd *cobra.Command, details versionDetails) error {
417417
// Check recursively so that, e.g., `docker stack ls` returns the same output as `docker stack`
418418
for curr := cmd; curr != nil; curr = curr.Parent() {
419+
// Important: in the code below, calls to "details.CurrentVersion()" and
420+
// "details.ServerInfo()" are deliberately executed inline to make them
421+
// be executed "lazily". This is to prevent making a connection with the
422+
// daemon to perform a "ping" (even for commands that do not require a
423+
// daemon connection).
424+
//
425+
// See commit b39739123b845f872549e91be184cc583f5b387c for details.
426+
419427
if cmdVersion, ok := curr.Annotations["version"]; ok && versions.LessThan(details.CurrentVersion(), cmdVersion) {
420428
return fmt.Errorf("%s requires API version %s, but the Docker daemon API version is %s", cmd.CommandPath(), cmdVersion, details.CurrentVersion())
421429
}
422-
si := details.ServerInfo()
423-
if ost, ok := curr.Annotations["ostype"]; ok && si.OSType != "" && ost != si.OSType {
424-
return fmt.Errorf("%s is only supported on a Docker daemon running on %s, but the Docker daemon is running on %s", cmd.CommandPath(), ost, si.OSType)
430+
if ost, ok := curr.Annotations["ostype"]; ok && details.ServerInfo().OSType != "" && ost != details.ServerInfo().OSType {
431+
return fmt.Errorf("%s is only supported on a Docker daemon running on %s, but the Docker daemon is running on %s", cmd.CommandPath(), ost, details.ServerInfo().OSType)
425432
}
426-
if _, ok := curr.Annotations["experimental"]; ok && !si.HasExperimental {
433+
if _, ok := curr.Annotations["experimental"]; ok && !details.ServerInfo().HasExperimental {
427434
return fmt.Errorf("%s is only supported on a Docker daemon with experimental features enabled", cmd.CommandPath())
428435
}
429436
}

0 commit comments

Comments
 (0)