diff --git a/pkg/cmd/container/kill.go b/pkg/cmd/container/kill.go index ceb4ef9ac88..6a6b5ea0809 100644 --- a/pkg/cmd/container/kill.go +++ b/pkg/cmd/container/kill.go @@ -143,7 +143,8 @@ func cleanupNetwork(ctx context.Context, container containerd.Container, globalO networksJSON := spec.Annotations[labels.Networks] var networks []string if err := json.Unmarshal([]byte(networksJSON), &networks); err != nil { - return err + log.G(ctx).WithError(err).Infof("unable to retrieve networking information for that container, which is likely managed by another tool") + return nil } netType, err := nettype.Detect(networks) if err != nil { diff --git a/pkg/cmd/container/remove.go b/pkg/cmd/container/remove.go index d425b718972..02e086da146 100644 --- a/pkg/cmd/container/remove.go +++ b/pkg/cmd/container/remove.go @@ -191,19 +191,18 @@ func RemoveContainer(ctx context.Context, c containerd.Container, globalOptions } netOpts, err := containerutil.NetworkOptionsFromSpec(spec) - if err != nil { - retErr = fmt.Errorf("failed to load container networking options from specs: %s", err) - return - } - - networkManager, err := containerutil.NewNetworkingOptionsManager(globalOptions, netOpts, client) - if err != nil { - retErr = fmt.Errorf("failed to instantiate network options manager: %s", err) - return - } + if err == nil { + networkManager, err := containerutil.NewNetworkingOptionsManager(globalOptions, netOpts, client) + if err != nil { + retErr = fmt.Errorf("failed to instantiate network options manager: %s", err) + return + } - if err := networkManager.CleanupNetworking(ctx, c); err != nil { - log.G(ctx).WithError(err).Warnf("failed to clean up container networking: %q", id) + if err := networkManager.CleanupNetworking(ctx, c); err != nil { + log.G(ctx).WithError(err).Warnf("failed to clean up container networking: %q", id) + } + } else { + log.G(ctx).WithError(err).Infof("unable to retrieve networking information for that container, which is likely managed by another tool: %q", id) } // Delete the container now. If it fails, try again without snapshot cleanup