Skip to content

Commit

Permalink
Fix network not found not being detected on new Docker versions
Browse files Browse the repository at this point in the history
  • Loading branch information
spowelljr committed Sep 29, 2023
1 parent f881b33 commit 25c1f32
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/drivers/kic/oci/network_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"net"
"os/exec"
"regexp"
"strings"

"github.com/blang/semver/v4"
Expand Down Expand Up @@ -207,8 +208,7 @@ func dockerNetworkInspect(name string) (netInfo, error) {
rr, err := dockerInspectGetter(name)
if err != nil {
logDockerNetworkInspect(Docker, name)
if strings.Contains(rr.Output(), "No such network") {

if isNetworkNotFound(rr.Output()) {
return info, ErrNetworkNotFound
}
return info, err
Expand Down Expand Up @@ -293,7 +293,7 @@ func RemoveNetwork(ociBin string, name string) error {
}
rr, err := runCmd(exec.Command(ociBin, "network", "rm", name))
if err != nil {
if strings.Contains(rr.Output(), "No such network") {
if isNetworkNotFound(rr.Output()) {
return ErrNetworkNotFound
}
// Error response from daemon: error while removing network: network mynet123 id f9e1c50b89feb0b8f4b687f3501a81b618252c9907bc20666e386d0928322387 has active endpoints
Expand Down Expand Up @@ -347,3 +347,9 @@ func DeleteKICNetworksByLabel(ociBin string, label string) []error {
}
return nil
}

func isNetworkNotFound(output string) bool {
// "No such network" on Docker 20.X.X and before, "network %s not found" on Docker 23.X.X and later
re := regexp.MustCompile(`(No such network)|(network .+ not found)`)
return re.MatchString(output)
}

0 comments on commit 25c1f32

Please sign in to comment.