-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
What would you like to be added (User Story)?
As a developer, I would like to be able filter out certain pods (certain pods won't be deleted) during the node draining process.
Detailed Description
I used Portworx as a distributed storage for container storage interface (CSI) drivers. When I upgraded my cluster, it caused “repaving” — replacing old nodes in the cluster one by one with new nodes that have the new desired state in place. When worker machines were repaving, CAPI continuously kill px-<cluster-name>
pods, which caused CSI plugin never getting re-registered and the node hanging forever. Therefore, cluster upgrades got stuck.
In this case, if we can have a field in machine spec to filter out the pods that we don't want CAPI to delete during the node draining process, then pods like px-<cluster-name>
can be re-registered and repaving will be done successfully. As discussion, we may need to not delete pods that have such toleration.
- effect: NoSchedule
key: node.kubernetes.io/unschedulable
operator: Exists
var (
unreachableToleration = corev1.Toleration{
Key: nodeUnreachableKey,
Effect: corev1.TaintEffectNoSchedule,
Operator: corev1.TolerationOpExists,
}
)
drainer := []kubedrain.PodFilter{
SkipFuncGenerator(m.Spec.NodeDrainPodFilters),
},
func skipUnreachableTolerationPods(pod corev1.Pod) kubedrain.PodDeleteStatus {
if pod.Spec.Tolerations == nil {
return kubedrain.MakePodDeleteStatusOkay()
}
if HasTolerations(&pod, &unreachableToleration) {
return kubedrain.MakePodDeleteStatusSkip()
}
return kubedrain.MakePodDeleteStatusOkay()
}
With helper function
func HasTolerations(pod *corev1.Pod, toleration *corev1.Toleration) bool {
for _, t := range pod.Spec.Tolerations {
if t.MatchToleration(toleration) {
return true
}
}
return false
}
We may add a field called NodeDrainPodFilters
in MachineSpec
. We can also add this field in KubeadmControlPlaneTemplateMachineTemplate
struct
NodeDrainPodFilters *metav1.LabelSelector json:"nodeDrainPodFilters,omitempty"
Anything else you would like to add?
No response
Label(s) to be applied
/kind feature