in deploy/kubernetes/operator/pkg/webhook/inspector/pod.go [42:102]
func (i *inspector) validateDeletingShuffleServer(ar *admissionv1.AdmissionReview) *admissionv1.AdmissionReview {
pod := &corev1.Pod{}
if err := json.Unmarshal(ar.Request.OldObject.Raw, pod); err != nil {
klog.Errorf("unmarshal object of AdmissionReview (%v) failed: %v",
string(ar.Request.Object.Raw), err)
return util.AdmissionReviewFailed(ar, err)
}
rssName := utils.GetRssNameByPod(pod)
// allow pods which are not shuffle servers or have been set deletion timestamp.
if rssName == "" || !util.NeedInspectPod(pod) {
klog.V(4).Infof("ignored non shuffle server or deleting pod: %v->(%+v/%+v/%v)",
utils.UniqueName(pod), pod.Labels, pod.Annotations, pod.DeletionTimestamp)
return util.AdmissionReviewAllow(ar)
}
klog.V(4).Infof("check shuffle server pod: %v", utils.BuildShuffleServerKey(pod))
rss, err := i.rssLister.RemoteShuffleServices(pod.Namespace).Get(rssName)
if err != nil {
if apierrors.IsNotFound(err) {
return util.AdmissionReviewAllow(ar)
}
return util.AdmissionReviewFailed(ar, err)
}
// we can only delete shuffle server pods when rss is in upgrading phase or pod is in failed status.
if !i.ifShuffleServerCanBeDeleted(rss, pod) {
message := fmt.Sprintf("can not delete the shuffle server pod (%v) directly, status:(%v)",
utils.UniqueName(pod), pod.Status.Phase)
klog.V(4).Info(message)
return util.AdmissionReviewForbidden(ar, message)
}
// when the rss uses specific upgrade mode, we need to check whether the pod is specific.
if rss.Spec.ShuffleServer.UpgradeStrategy.Type == unifflev1alpha1.SpecificUpgrade {
specificNames := rss.Spec.ShuffleServer.UpgradeStrategy.SpecificNames
isSpecific := false
for _, name := range specificNames {
if name == pod.Name {
isSpecific = true
break
}
}
if !isSpecific {
message := fmt.Sprintf("can not delete the shuffle server pod (%v) which is not specific",
utils.UniqueName(pod))
klog.V(4).Info(message)
return util.AdmissionReviewForbidden(ar, message)
}
}
// update targetKeys field in status of rss and exclude nodes in configMap used by coordinators.
if err = i.updateTargetKeysAndExcludeNodes(rss, pod); err != nil {
return util.AdmissionReviewFailed(ar, err)
}
// check whether the shuffle server pod can be deleted.
if i.ignoreLastApps || util.HasZeroApps(pod) {
klog.V(3).Infof("shuffle server pod (%v) will be deleted", utils.BuildShuffleServerKey(pod))
return util.AdmissionReviewAllow(ar)
}
message := "there are some apps still running in shuffle server: " + utils.GetShuffleServerNode(pod)
return util.AdmissionReviewForbidden(ar, message)
}