@@ -62,12 +62,13 @@ func (h *webhook) Handle(_ context.Context, req admission.Request) admission.Res
6262 }
6363 klog .Infof (template , req .Namespace , req .Name , req .UID )
6464 hasResource := false
65+ privileged := false
6566 for idx , ctr := range pod .Spec .Containers {
6667 c := & pod .Spec .Containers [idx ]
6768 if ctr .SecurityContext != nil {
6869 if ctr .SecurityContext .Privileged != nil && * ctr .SecurityContext .Privileged {
6970 klog .Warningf (template + " - Denying admission as container %s is privileged" , req .Namespace , req .Name , req .UID , c .Name )
70- continue
71+ privileged = true
7172 }
7273 }
7374 for _ , val := range device .GetDevices () {
@@ -79,11 +80,13 @@ func (h *webhook) Handle(_ context.Context, req admission.Request) admission.Res
7980 hasResource = hasResource || found
8081 }
8182 }
82-
83- if ! hasResource {
83+ switch {
84+ case ! hasResource :
8485 klog .Infof (template + " - Allowing admission for pod: no resource found" , req .Namespace , req .Name , req .UID )
85- //return admission.Allowed("no resource found")
86- } else if len (config .SchedulerName ) > 0 {
86+ case privileged :
87+ klog .Infof (template + " - Denying admission for pod: privileged container found" , req .Namespace , req .Name , req .UID )
88+ return admission .Denied ("privileged container found" )
89+ case len (config .SchedulerName ) > 0 :
8790 pod .Spec .SchedulerName = config .SchedulerName
8891 if pod .Spec .NodeName != "" {
8992 klog .Infof (template + " - Pod already has node assigned" , req .Namespace , req .Name , req .UID )
0 commit comments