@@ -28,15 +28,19 @@ import (
28
28
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29
29
"k8s.io/apimachinery/pkg/fields"
30
30
"k8s.io/apimachinery/pkg/util/uuid"
31
+ "k8s.io/apimachinery/pkg/util/wait"
31
32
clientset "k8s.io/client-go/kubernetes"
33
+ "k8s.io/client-go/kubernetes/scheme"
32
34
"k8s.io/kubernetes/pkg/kubelet/events"
33
35
"k8s.io/kubernetes/test/e2e/feature"
34
36
"k8s.io/kubernetes/test/e2e/framework"
35
37
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
36
38
e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"
37
39
testutils "k8s.io/kubernetes/test/utils"
40
+ "k8s.io/kubernetes/test/utils/format"
38
41
imageutils "k8s.io/kubernetes/test/utils/image"
39
42
admissionapi "k8s.io/pod-security-admission/api"
43
+ "k8s.io/utils/ptr"
40
44
)
41
45
42
46
const runAsUserNameContainerName = "run-as-username-container"
@@ -193,6 +197,67 @@ var _ = sigDescribe(feature.Windows, "SecurityContext", skipUnlessWindows(func()
193
197
})
194
198
}))
195
199
200
+ var _ = sigDescribe (feature .Windows , "SecurityContext" , skipUnlessWindows (func () {
201
+ f := framework .NewDefaultFramework ("windows-with-unsupported-fields" )
202
+ f .NamespacePodSecurityLevel = admissionapi .LevelPrivileged
203
+
204
+ ginkgo .It ("should be able to create pod and run containers" , func (ctx context.Context ) {
205
+ ginkgo .By ("Creating 1 pods: run with unsupported fields" )
206
+
207
+ pod := & v1.Pod {
208
+ ObjectMeta : metav1.ObjectMeta {
209
+ Name : "run-ignore-unsupported-fields" ,
210
+ Namespace : f .Namespace .Name ,
211
+ },
212
+ Spec : v1.PodSpec {
213
+ NodeSelector : map [string ]string {"kubernetes.io/os" : "windows" },
214
+ Containers : []v1.Container {
215
+ {
216
+ Name : "test-container" ,
217
+ Image : imageutils .GetE2EImage (imageutils .Pause ),
218
+ },
219
+ },
220
+ SecurityContext : & v1.PodSecurityContext {
221
+ RunAsUser : ptr.To [int64 ](999 ), // windows does not support
222
+ RunAsGroup : ptr.To [int64 ](999 ), // windows does not support
223
+ RunAsNonRoot : ptr .To (true ),
224
+ },
225
+ RestartPolicy : v1 .RestartPolicyNever ,
226
+ },
227
+ }
228
+
229
+ pod , err := f .ClientSet .CoreV1 ().Pods (f .Namespace .Name ).Create (ctx , pod , metav1.CreateOptions {})
230
+ framework .ExpectNoError (err , "Error creating pod" )
231
+
232
+ podErr := e2epod .WaitForPodRunningInNamespace (ctx , f .ClientSet , pod )
233
+
234
+ // Get the logs and events before calling ExpectNoError, so we can debug any errors.
235
+ var logs string
236
+ var events * v1.EventList
237
+ if err := wait .PollUntilContextTimeout (ctx , 30 * time .Second , 2 * time .Minute , true , func (ctx context.Context ) (done bool , err error ) {
238
+ framework .Logf ("polling logs" )
239
+ logs , err = e2epod .GetPodLogs (ctx , f .ClientSet , f .Namespace .Name , pod .Name , pod .Spec .Containers [0 ].Name )
240
+ if err != nil {
241
+ framework .Logf ("Error pulling logs: %v" , err )
242
+ return false , nil
243
+ }
244
+
245
+ events , err = f .ClientSet .CoreV1 ().Events (pod .Namespace ).Search (scheme .Scheme , pod )
246
+ if err != nil {
247
+ return false , fmt .Errorf ("error in listing events: %w" , err )
248
+ }
249
+ return true , nil
250
+ }); err != nil {
251
+ framework .Failf ("Unexpected error getting pod logs/events: %v" , err )
252
+ } else {
253
+ framework .Logf ("Pod logs: \n %v" , logs )
254
+ framework .Logf ("Pod events: \n %v" , format .Object (events , 1 ))
255
+ }
256
+
257
+ framework .ExpectNoError (podErr )
258
+ })
259
+ }))
260
+
196
261
func runAsUserNamePod (username * string ) * v1.Pod {
197
262
podName := "run-as-username-" + string (uuid .NewUUID ())
198
263
return & v1.Pod {
0 commit comments