From 4fe3d778064dc1fa534e3c420f70eaf317b01a50 Mon Sep 17 00:00:00 2001 From: Igor Sarkisov Date: Thu, 10 Nov 2022 16:27:37 -0800 Subject: [PATCH] Do not explicitly set Privileged to false. Setting SecurityContext.Privileged bit to false, which is default, prevents GKE from admitting Windows pods. Privileged bit is not supported on Windows. --- controllers/new_runner_pod_test.go | 16 ++++------------ controllers/runner_controller.go | 10 ++++------ 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/controllers/new_runner_pod_test.go b/controllers/new_runner_pod_test.go index 2d95601e6e..54fd75ada1 100644 --- a/controllers/new_runner_pod_test.go +++ b/controllers/new_runner_pod_test.go @@ -160,9 +160,7 @@ func TestNewRunnerPod(t *testing.T) { }, }, ImagePullPolicy: corev1.PullAlways, - SecurityContext: &corev1.SecurityContext{ - Privileged: func() *bool { v := false; return &v }(), - }, + SecurityContext: &corev1.SecurityContext{}, }, { Name: "docker", @@ -366,9 +364,7 @@ func TestNewRunnerPod(t *testing.T) { }, }, ImagePullPolicy: corev1.PullAlways, - SecurityContext: &corev1.SecurityContext{ - Privileged: boolPtr(false), - }, + SecurityContext: &corev1.SecurityContext{}, }, }, RestartPolicy: corev1.RestartPolicyNever, @@ -690,9 +686,7 @@ func TestNewRunnerPodFromRunnerController(t *testing.T) { }, }, ImagePullPolicy: corev1.PullAlways, - SecurityContext: &corev1.SecurityContext{ - Privileged: func() *bool { v := false; return &v }(), - }, + SecurityContext: &corev1.SecurityContext{}, }, { Name: "docker", @@ -930,9 +924,7 @@ func TestNewRunnerPodFromRunnerController(t *testing.T) { }, }, ImagePullPolicy: corev1.PullAlways, - SecurityContext: &corev1.SecurityContext{ - Privileged: boolPtr(false), - }, + SecurityContext: &corev1.SecurityContext{}, }, }, RestartPolicy: corev1.RestartPolicyNever, diff --git a/controllers/runner_controller.go b/controllers/runner_controller.go index ae306edcbc..f217cd5961 100644 --- a/controllers/runner_controller.go +++ b/controllers/runner_controller.go @@ -849,10 +849,6 @@ func newRunnerPodWithContainerMode(containerMode string, template corev1.Pod, ru runnerContainerIndex = -1 runnerContainer = &corev1.Container{ Name: containerName, - SecurityContext: &corev1.SecurityContext{ - // Runner need to run privileged if it contains DinD - Privileged: &dockerdInRunnerPrivileged, - }, } } @@ -887,8 +883,10 @@ func newRunnerPodWithContainerMode(containerMode string, template corev1.Pod, ru runnerContainer.SecurityContext = &corev1.SecurityContext{} } - if runnerContainer.SecurityContext.Privileged == nil { - // Runner need to run privileged if it contains DinD + // Runner need to run privileged if it contains DinD. + // Do not explicitly set SecurityContext.Privileged to false which is default, + // otherwise Windows pods don't get admitted on GKE. + if dockerdInRunnerPrivileged { runnerContainer.SecurityContext.Privileged = &dockerdInRunnerPrivileged }