Skip to content

Commit 79b369a

Browse files
committed
Added windows hostProcess cni skip
Signed-off-by: Peri Thompson <[email protected]>
1 parent 7d4c95f commit 79b369a

8 files changed

Lines changed: 36 additions & 1 deletion

pkg/cri/annotations/annotations.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,7 @@ const (
5959

6060
// PodAnnotations are the annotations of the pod
6161
PodAnnotations = "io.kubernetes.cri.pod-annotations"
62+
63+
// WindowsHostProcess is used by hcsshim to identify windows pods that are running HostProcesses
64+
WindowsHostProcess = "microsoft.com/hostprocess-container"
6265
)

pkg/cri/server/container_create_windows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package server
1818

1919
import (
20+
"strconv"
21+
2022
"github.com/containerd/containerd/oci"
2123
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
2224
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
@@ -118,6 +120,7 @@ func (c *criService) containerSpec(
118120
customopts.WithAnnotation(annotations.SandboxName, sandboxConfig.GetMetadata().GetName()),
119121
customopts.WithAnnotation(annotations.ContainerName, containerName),
120122
customopts.WithAnnotation(annotations.ImageName, imageName),
123+
customopts.WithAnnotation(annotations.WindowsHostProcess, strconv.FormatBool(sandboxConfig.GetWindows().GetSecurityContext().GetHostProcess())),
121124
)
122125
return c.runtimeSpec(id, ociRuntime.BaseRuntimeSpec, specOpts...)
123126
}

pkg/cri/server/container_create_windows_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func getCreateContainerTestData() (*runtime.ContainerConfig, *runtime.PodSandbox
7272
SecurityContext: &runtime.WindowsContainerSecurityContext{
7373
RunAsUsername: "test-user",
7474
CredentialSpec: "{\"test\": \"spec\"}",
75+
HostProcess: false,
7576
},
7677
},
7778
}
@@ -130,6 +131,9 @@ func getCreateContainerTestData() (*runtime.ContainerConfig, *runtime.PodSandbox
130131

131132
assert.Contains(t, spec.Annotations, annotations.SandboxName)
132133
assert.EqualValues(t, spec.Annotations[annotations.SandboxName], "test-sandbox-name")
134+
135+
assert.Contains(t, spec.Annotations, annotations.WindowsHostProcess)
136+
assert.EqualValues(t, spec.Annotations[annotations.WindowsHostProcess], "false")
133137
}
134138
return config, sandboxConfig, imageConfig, specCheck
135139
}

pkg/cri/server/restart.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ func (c *criService) loadSandbox(ctx context.Context, cntr containerd.Container)
414414
// Don't need to load netns for host network sandbox.
415415
return sandbox, nil
416416
}
417+
if goruntime.GOOS == "windows" && meta.Config.GetWindows().GetSecurityContext().GetHostProcess() {
418+
return sandbox, nil
419+
}
417420
sandbox.NetNS = netns.LoadNetNS(meta.NetNSPath)
418421

419422
// It doesn't matter whether task is running or not. If it is running, sandbox

pkg/cri/server/sandbox_run.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,18 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
110110
log.G(ctx).Debugf("Use OCI %+v for sandbox %q", ociRuntime, id)
111111

112112
podNetwork := true
113-
// Pod network is always needed on windows.
113+
114114
if goruntime.GOOS != "windows" &&
115115
config.GetLinux().GetSecurityContext().GetNamespaceOptions().GetNetwork() == runtime.NamespaceMode_NODE {
116116
// Pod network is not needed on linux with host network.
117117
podNetwork = false
118118
}
119+
if goruntime.GOOS == "windows" &&
120+
config.GetWindows().GetSecurityContext().GetHostProcess() {
121+
//Windows HostProcess pods can only run on the host network
122+
podNetwork = false
123+
}
124+
119125
if podNetwork {
120126
// If it is not in host network namespace then create a namespace and set the sandbox
121127
// handle. NetNSPath in sandbox metadata and NetNS is non empty only for non host network

pkg/cri/server/sandbox_run_windows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package server
1818

1919
import (
20+
"strconv"
21+
2022
"github.com/containerd/containerd"
2123
"github.com/containerd/containerd/oci"
2224
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -65,6 +67,7 @@ func (c *criService) sandboxContainerSpec(id string, config *runtime.PodSandboxC
6567
customopts.WithAnnotation(annotations.SandboxNamespace, config.GetMetadata().GetNamespace()),
6668
customopts.WithAnnotation(annotations.SandboxName, config.GetMetadata().GetName()),
6769
customopts.WithAnnotation(annotations.SandboxLogDir, config.GetLogDirectory()),
70+
customopts.WithAnnotation(annotations.WindowsHostProcess, strconv.FormatBool(config.GetWindows().GetSecurityContext().GetHostProcess())),
6871
)
6972

7073
return c.runtimeSpec(id, "", specOpts...)

pkg/cri/server/sandbox_run_windows_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ func getRunPodSandboxTestData() (*runtime.PodSandboxConfig, *imagespec.ImageConf
4040
LogDirectory: "test-log-directory",
4141
Labels: map[string]string{"a": "b"},
4242
Annotations: map[string]string{"c": "d"},
43+
Windows: &runtime.WindowsPodSandboxConfig{
44+
SecurityContext: &runtime.WindowsSandboxSecurityContext{
45+
RunAsUsername: "test-user",
46+
CredentialSpec: "{\"test\": \"spec\"}",
47+
HostProcess: false,
48+
},
49+
},
4350
}
4451
imageConfig := &imagespec.ImageConfig{
4552
Env: []string{"a=b", "c=d"},
@@ -70,6 +77,9 @@ func getRunPodSandboxTestData() (*runtime.PodSandboxConfig, *imagespec.ImageConf
7077

7178
assert.Contains(t, spec.Annotations, annotations.SandboxLogDir)
7279
assert.EqualValues(t, spec.Annotations[annotations.SandboxLogDir], "test-log-directory")
80+
81+
assert.Contains(t, spec.Annotations, annotations.WindowsHostProcess)
82+
assert.EqualValues(t, spec.Annotations[annotations.WindowsHostProcess], "false")
7383
}
7484
return config, imageConfig, specCheck
7585
}

pkg/cri/server/sandbox_status.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ func (c *criService) getIPs(sandbox sandboxstore.Sandbox) (string, []string, err
7676
// responsible for reporting the IP.
7777
return "", nil, nil
7878
}
79+
if goruntime.GOOS == "windows" && config.GetWindows().GetSecurityContext().GetHostProcess() {
80+
return "", nil, nil
81+
}
7982

8083
if closed, err := sandbox.NetNS.Closed(); err != nil {
8184
return "", nil, errors.Wrap(err, "check network namespace closed")

0 commit comments

Comments
 (0)