feat: wip check only controller ref to decide if a pod is replicated
Signed-off-by: vadasambar <surajrbanakar@gmail.com>
This commit is contained in:
parent
1e1e88d6e1
commit
144a64a402
|
@ -121,25 +121,7 @@ func GetPodsForDeletionOnNodeDrain(
|
|||
// so OwnerReference doesn't have its own Namespace field
|
||||
controllerNamespace := pod.Namespace
|
||||
|
||||
if refKind == "ReplicationController" {
|
||||
if checkReferences {
|
||||
rc, err := listers.ReplicationControllerLister().ReplicationControllers(controllerNamespace).Get(controllerRef.Name)
|
||||
// Assume a reason for an error is because the RC is either
|
||||
// gone/missing or that the rc has too few replicas configured.
|
||||
// TODO: replace the minReplica check with pod disruption budget.
|
||||
if err == nil && rc != nil {
|
||||
if rc.Spec.Replicas != nil && *rc.Spec.Replicas < minReplica {
|
||||
return []*apiv1.Pod{}, []*apiv1.Pod{}, &BlockingPod{Pod: pod, Reason: MinReplicasReached}, fmt.Errorf("replication controller for %s/%s has too few replicas spec: %d min: %d",
|
||||
pod.Namespace, pod.Name, rc.Spec.Replicas, minReplica)
|
||||
}
|
||||
replicated = true
|
||||
} else {
|
||||
return []*apiv1.Pod{}, []*apiv1.Pod{}, &BlockingPod{Pod: pod, Reason: ControllerNotFound}, fmt.Errorf("replication controller for %s/%s is not available, err: %v", pod.Namespace, pod.Name, err)
|
||||
}
|
||||
} else {
|
||||
replicated = true
|
||||
}
|
||||
} else if pod_util.IsDaemonSetPod(pod) {
|
||||
if pod_util.IsDaemonSetPod(pod) {
|
||||
isDaemonSetPod = true
|
||||
// don't have listener for other DaemonSet kind
|
||||
// TODO: we should use a generic client for checking the reference.
|
||||
|
@ -151,55 +133,6 @@ func GetPodsForDeletionOnNodeDrain(
|
|||
return []*apiv1.Pod{}, []*apiv1.Pod{}, &BlockingPod{Pod: pod, Reason: UnexpectedError}, fmt.Errorf("error when trying to get daemonset for %s/%s , err: %v", pod.Namespace, pod.Name, err)
|
||||
}
|
||||
}
|
||||
} else if refKind == "Job" {
|
||||
if checkReferences {
|
||||
job, err := listers.JobLister().Jobs(controllerNamespace).Get(controllerRef.Name)
|
||||
|
||||
// Assume the only reason for an error is because the Job is
|
||||
// gone/missing, not for any other cause. TODO(mml): something more
|
||||
// sophisticated than this
|
||||
if err == nil && job != nil {
|
||||
replicated = true
|
||||
} else {
|
||||
return []*apiv1.Pod{}, []*apiv1.Pod{}, &BlockingPod{Pod: pod, Reason: ControllerNotFound}, fmt.Errorf("job for %s/%s is not available: err: %v", pod.Namespace, pod.Name, err)
|
||||
}
|
||||
} else {
|
||||
replicated = true
|
||||
}
|
||||
} else if refKind == "ReplicaSet" {
|
||||
if checkReferences {
|
||||
rs, err := listers.ReplicaSetLister().ReplicaSets(controllerNamespace).Get(controllerRef.Name)
|
||||
|
||||
// Assume the only reason for an error is because the RS is
|
||||
// gone/missing, not for any other cause. TODO(mml): something more
|
||||
// sophisticated than this
|
||||
if err == nil && rs != nil {
|
||||
if rs.Spec.Replicas != nil && *rs.Spec.Replicas < minReplica {
|
||||
return []*apiv1.Pod{}, []*apiv1.Pod{}, &BlockingPod{Pod: pod, Reason: MinReplicasReached}, fmt.Errorf("replication controller for %s/%s has too few replicas spec: %d min: %d",
|
||||
pod.Namespace, pod.Name, rs.Spec.Replicas, minReplica)
|
||||
}
|
||||
replicated = true
|
||||
} else {
|
||||
return []*apiv1.Pod{}, []*apiv1.Pod{}, &BlockingPod{Pod: pod, Reason: ControllerNotFound}, fmt.Errorf("replication controller for %s/%s is not available, err: %v", pod.Namespace, pod.Name, err)
|
||||
}
|
||||
} else {
|
||||
replicated = true
|
||||
}
|
||||
} else if refKind == "StatefulSet" {
|
||||
if checkReferences {
|
||||
ss, err := listers.StatefulSetLister().StatefulSets(controllerNamespace).Get(controllerRef.Name)
|
||||
|
||||
// Assume the only reason for an error is because the StatefulSet is
|
||||
// gone/missing, not for any other cause. TODO(mml): something more
|
||||
// sophisticated than this
|
||||
if err == nil && ss != nil {
|
||||
replicated = true
|
||||
} else {
|
||||
return []*apiv1.Pod{}, []*apiv1.Pod{}, &BlockingPod{Pod: pod, Reason: ControllerNotFound}, fmt.Errorf("statefulset for %s/%s is not available: err: %v", pod.Namespace, pod.Name, err)
|
||||
}
|
||||
} else {
|
||||
replicated = true
|
||||
}
|
||||
}
|
||||
if isDaemonSetPod {
|
||||
daemonSetPods = append(daemonSetPods, pod)
|
||||
|
|
Loading…
Reference in New Issue