Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows doesn't reconcile "hostNetwork" Pod after agent is restarted #6943

Closed
wenyingd opened this issue Jan 20, 2025 · 0 comments · Fixed by #6944
Closed

Windows doesn't reconcile "hostNetwork" Pod after agent is restarted #6943

wenyingd opened this issue Jan 20, 2025 · 0 comments · Fixed by #6944
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@wenyingd
Copy link
Contributor

wenyingd commented Jan 20, 2025

Describe the bug

On Windows, a host-network Pod also uses Pod network as long as it is not configured with hostProcess. So antrea-agent receives the CmdAdd request when such a Pod is created. But antrea-agent may not reconcile such Pods after agent is restarted because of this code https://github.com/antrea-io/antrea/blob/main/pkg/agent/cniserver/pod_configuration.go#L449 . It may cause antrea-agent removes the Pod's OVS interface by mistake after agent is restarted.

kubelet has the below logic to set host-process as true if the Pod is using hostNetwork and all containers in it use hostProcess,

// If all of the containers in a pod are HostProcess containers, set the pod's HostProcess field
// explicitly because the container runtime requires this information at sandbox creation time.
if kubecontainer.HasWindowsHostProcessContainer(pod) {
    // At present Windows all containers in a Windows pod must be HostProcess containers
    // and HostNetwork is required to be set.
    if !kubecontainer.AllContainersAreWindowsHostProcess(pod) {
       return nil, fmt.Errorf("pod must not contain both HostProcess and non-HostProcess containers")
    }

    if !kubecontainer.IsHostNetworkPod(pod) {
       return nil, fmt.Errorf("hostNetwork is required if Pod contains HostProcess containers")
    }

    wc.SecurityContext.HostProcess = true
}

And with containerd, it calls CNI with cmdAdd request only if !hostNetwork(config), and hostNetwork is decided by the field spec.securityContext.windowsOptions.hostProcess but not by spec.hostNetwork.

func hostNetwork(config *runtime.PodSandboxConfig) bool {
	var hostNet bool
	switch goruntime.GOOS {
	case "windows":
		// Windows HostProcess pods can only run on the host network
		hostNet = config.GetWindows().GetSecurityContext().GetHostProcess()
	case "darwin":
		// No CNI on Darwin yet.
		hostNet = true
	default:
		// Even on other platforms, the logic containerd uses is to check if NamespaceMode == NODE.
		// So this handles Linux, as well as any other platforms not governed by the cases above
		// that have special quirks.
		hostNet = config.GetLinux().GetSecurityContext().GetNamespaceOptions().GetNetwork() == runtime.NamespaceMode_NODE
	}
	return hostNet
}

To Reproduce

Create a Pod on Windows configuring spec.hostNetwork: true and spec.securityContext.windowsOptions.hostProcess: fase on Windows, it is supposed to observe that antrea-agent CNI server should receive the CmdAdd request.
Then restart antrea-agent, the Pod is supposed to filter-out in the reconciling Pod list.

Expected

antrea-agent should reconcile such Pod after restart, since its CmdAdd request is handled by antrea (CNI).

Actual behavior

Such Pod is not reconciled after restart.

Versions:

All Antrea versions.

Additional context

@wenyingd wenyingd added the kind/bug Categorizes issue or PR as related to a bug. label Jan 20, 2025
@wenyingd wenyingd self-assigned this Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant