Skip to content

Commit

Permalink
koord-manager: forbid use internal statements
Browse files Browse the repository at this point in the history
Signed-off-by: acejilam <acejilam@gmail.com>
  • Loading branch information
ls-2018 committed Feb 21, 2024
1 parent b634779 commit f90d4a1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/webhook/pod/validating/cluster_colocation_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (h *PodValidatingHandler) clusterColocationProfileValidatingPod(ctx context
}

allErrs = append(allErrs, validateRequiredQoSClass(newPod)...)
allErrs = append(allErrs, forbidReservationAnnotations(newPod)...)
allErrs = append(allErrs, forbidSpecialQoSClassAndPriorityClass(newPod, extension.QoSBE, extension.PriorityNone, extension.PriorityProd)...)
allErrs = append(allErrs, forbidSpecialQoSClassAndPriorityClass(newPod, extension.QoSLSR, extension.PriorityNone, extension.PriorityMid, extension.PriorityBatch, extension.PriorityFree)...)
allErrs = append(allErrs, validateResources(newPod)...)
Expand All @@ -68,6 +69,16 @@ func (h *PodValidatingHandler) clusterColocationProfileValidatingPod(ctx context
return allowed, reason, nil
}

func forbidReservationAnnotations(pod *corev1.Pod) field.ErrorList {
if pod.Annotations == nil {
return nil
}
if _, ok := pod.Annotations[extension.AnnotationReservationAllocated]; ok {
return field.ErrorList{field.Required(field.NewPath("annotations", extension.AnnotationReservationAllocated), "cannot specify reservation allocated in annotations")}
}
return nil
}

func validateRequiredQoSClass(pod *corev1.Pod) field.ErrorList {
request := util.GetPodRequest(pod)
batchCPUQuantity := request[extension.BatchCPU]
Expand Down
13 changes: 13 additions & 0 deletions pkg/webhook/pod/validating/cluster_colocation_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,19 @@ func TestClusterColocationProfileValidatingPod(t *testing.T) {
wantAllowed: false,
wantReason: `pod.spec.containers[*].resources.requests: Invalid value: "100m": the requested CPUs of LSR Pod must be integer`,
},
{
name: "forbidden resources annotations",
operation: admissionv1.Create,
newPod: &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
extension.AnnotationReservationAllocated: "",
},
},
},
wantAllowed: false,
wantReason: `annotations.scheduling.koordinator.sh/reservation-allocated: Required value: cannot specify reservation allocated in annotations`,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit f90d4a1

Please sign in to comment.