Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow draining when DaemonSet kind has custom API Group #6412

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

apiv1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/autoscaler/cluster-autoscaler/simulator/drainability"
"k8s.io/autoscaler/cluster-autoscaler/utils/drain"
pod_util "k8s.io/autoscaler/cluster-autoscaler/utils/pod"
Expand Down Expand Up @@ -57,6 +58,12 @@ func (r *Rule) Drainable(drainCtx *drainability.DrainContext, pod *apiv1.Pod) dr
if controllerRef == nil {
return drainability.NewUndefinedStatus()
}

refGroup, err := schema.ParseGroupVersion(controllerRef.APIVersion)
if err != nil {
return drainability.NewUndefinedStatus()
}

refKind := controllerRef.Kind

if refKind == "ReplicationController" {
Expand All @@ -71,8 +78,8 @@ func (r *Rule) Drainable(drainCtx *drainability.DrainContext, pod *apiv1.Pod) dr
return drainability.NewBlockedStatus(drain.MinReplicasReached, fmt.Errorf("replication controller for %s/%s has too few replicas spec: %d min: %d", pod.Namespace, pod.Name, rc.Spec.Replicas, r.minReplicaCount))
}
} else if pod_util.IsDaemonSetPod(pod) {
if refKind != "DaemonSet" {
// We don't have a listener for the other DaemonSet kind.
if refGroup.Group != "apps" || refKind != "DaemonSet" {
// We don't have a listener for the other DaemonSet group or kind.
// TODO: Use a generic client for checking the reference.
return drainability.NewUndefinedStatus()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,30 @@ func TestDrainable(t *testing.T) {
wantReason: drain.ControllerNotFound,
wantError: true,
},
"DS-managed pod by a custom API Group": {
pod: &apiv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "default",
OwnerReferences: test.GenerateOwnerReferences(ds.Name, "DaemonSet", "crd/v1", ""),
},
Spec: apiv1.PodSpec{
NodeName: "node",
},
},
},
"DS-managed pod by a custom API Group with missing reference": {
pod: &apiv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "default",
OwnerReferences: test.GenerateOwnerReferences("missing", "DaemonSet", "crd/v1", ""),
},
Spec: apiv1.PodSpec{
NodeName: "node",
},
},
},
"DS-managed pod by a custom Daemonset": {
pod: &apiv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand Down
Loading