From 41757b2e4ebfe18d929620b5458504331eae70da Mon Sep 17 00:00:00 2001 From: apostasie Date: Mon, 16 Dec 2024 15:32:42 -0800 Subject: [PATCH] Relax error on annotations read failure Signed-off-by: apostasie --- pkg/cmd/container/kill.go | 3 ++- pkg/cmd/container/remove.go | 23 +++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) 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