[kubectl] drain daemonSetFilter with other APIVersion

Signed-off-by: Aleksey Gavrilov <alexey.gavrilov@flant.com>

Kubernetes-commit: a52863827bafa64a678c1291f066d2c8b85217af
This commit is contained in:
Aleksey Gavrilov 2024-11-13 10:23:54 +03:00 committed by Kubernetes Publisher
parent 9892d492ab
commit 6323c5bc57
1 changed files with 7 additions and 1 deletions

View File

@ -171,6 +171,12 @@ func hasLocalStorage(pod corev1.Pod) bool {
return false
}
func isControllerRefDaemonSet(workloadRef *metav1.OwnerReference) bool {
// find if workloadRef is daemonSet
daemonSetAPIVersion, daemonSetKind := appsv1.SchemeGroupVersion.WithKind("DaemonSet").ToAPIVersionAndKind()
return workloadRef.Kind == daemonSetKind && workloadRef.APIVersion == daemonSetAPIVersion
}
func (d *Helper) daemonSetFilter(pod corev1.Pod) PodDeleteStatus {
// Note that we return false in cases where the pod is DaemonSet managed,
// regardless of flags.
@ -179,7 +185,7 @@ func (d *Helper) daemonSetFilter(pod corev1.Pod) PodDeleteStatus {
// management resource - including DaemonSet - is not found).
// Such pods will be deleted if --force is used.
controllerRef := metav1.GetControllerOf(&pod)
if controllerRef == nil || controllerRef.Kind != appsv1.SchemeGroupVersion.WithKind("DaemonSet").Kind {
if controllerRef == nil || !isControllerRefDaemonSet(controllerRef) {
return MakePodDeleteStatusOkay()
}
// Any finished pod can be removed.