diff --git a/pkg/agent/cniserver/interface_configuration_windows.go b/pkg/agent/cniserver/interface_configuration_windows.go index 367e58b7252..cab813634af 100644 --- a/pkg/agent/cniserver/interface_configuration_windows.go +++ b/pkg/agent/cniserver/interface_configuration_windows.go @@ -326,7 +326,7 @@ func (ic *ifConfigurator) removeHNSEndpoint(endpoint *hcsshim.HNSEndpoint, conta // Remove HNSEndpoint. go func() { hcnEndpoint, _ := hcn.GetEndpointByID(endpoint.Id) - if hcnEndpoint != nil && hcnEndpoint.HostComputeNamespace != "" { + if hcnEndpoint != nil && isValidHostNamespace(hcnEndpoint.HostComputeNamespace) { err := hcn.RemoveNamespaceEndpoint(hcnEndpoint.HostComputeNamespace, hcnEndpoint.Id) if err != nil { klog.Errorf("Failed to remove HostComputeEndpoint %s from HostComputeNameSpace %s: %v", hcnEndpoint.Name, hcnEndpoint.HostComputeNamespace, err) @@ -363,6 +363,13 @@ func (ic *ifConfigurator) removeHNSEndpoint(endpoint *hcsshim.HNSEndpoint, conta return nil } +// isValidHostNamespace checks if the hostNamespace is valid or not. When the runtime is docker, the hostNamespace +// is not set, and Windows HCN should use a default value "00000000-0000-0000-0000-000000000000". An error returns +// when removing HostComputeEndpoint in this namespace. This field is set with a valid value when containerd is used. +func isValidHostNamespace(hostNamespace string) bool { + return hostNamespace != "" && hostNamespace != "00000000-0000-0000-0000-000000000000" +} + func parseContainerIfaceFromResults(cfgArgs *cnipb.CniCmdArgs, prevResult *current.Result) *current.Interface { for _, intf := range prevResult.Interfaces { if strings.HasSuffix(intf.Name, cfgArgs.Ifname) {