Skip to content

Commit 80ccef6

Browse files
author
Harry Li
committed
feat(webhook): add additional check for initContainers and log detail
Signed-off-by: Harry Li <[email protected]>
1 parent 6e77919 commit 80ccef6

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

pkg/scheduler/webhook.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,29 @@ func (h *webhook) Handle(_ context.Context, req admission.Request) admission.Res
6666
klog.Infof(template+" - Pod already has different scheduler assigned", req.Namespace, req.Name, req.UID)
6767
return admission.Allowed("pod already has different scheduler assigned")
6868
}
69-
klog.Infof(template, pod.Namespace, pod.Name, pod.UID)
69+
klog.Infof(template+" - Checking resources and scheduler assignment", pod.Namespace, pod.Name, pod.UID)
7070
hasResource := false
71-
for idx, ctr := range pod.Spec.Containers {
71+
for idx := range pod.Spec.InitContainers {
72+
c := &pod.Spec.InitContainers[idx]
73+
if c.SecurityContext != nil {
74+
if c.SecurityContext.Privileged != nil && *c.SecurityContext.Privileged {
75+
klog.Warningf(template+" - Denying admission as init container %s is privileged", pod.Namespace, pod.Name, pod.UID, c.Name)
76+
continue
77+
}
78+
}
79+
for _, val := range device.GetDevices() {
80+
found, err := val.MutateAdmission(c, pod)
81+
if err != nil {
82+
klog.Errorf("validating pod failed:%s", err.Error())
83+
return admission.Errored(http.StatusInternalServerError, err)
84+
}
85+
hasResource = hasResource || found
86+
}
87+
}
88+
for idx := range pod.Spec.Containers {
7289
c := &pod.Spec.Containers[idx]
73-
if ctr.SecurityContext != nil {
74-
if ctr.SecurityContext.Privileged != nil && *ctr.SecurityContext.Privileged {
90+
if c.SecurityContext != nil {
91+
if c.SecurityContext.Privileged != nil && *c.SecurityContext.Privileged {
7592
klog.Warningf(template+" - Denying admission as container %s is privileged", pod.Namespace, pod.Name, pod.UID, c.Name)
7693
continue
7794
}

0 commit comments

Comments
 (0)