diff --git a/cluster-autoscaler/simulator/drainability/rules/replicacount/rule.go b/cluster-autoscaler/simulator/drainability/rules/replicacount/rule.go index 458ee234f777..e03c6d365e58 100644 --- a/cluster-autoscaler/simulator/drainability/rules/replicacount/rule.go +++ b/cluster-autoscaler/simulator/drainability/rules/replicacount/rule.go @@ -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" @@ -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" { @@ -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() } diff --git a/cluster-autoscaler/simulator/drainability/rules/replicacount/rule_test.go b/cluster-autoscaler/simulator/drainability/rules/replicacount/rule_test.go index 342a69738bb5..efe09e2072a9 100644 --- a/cluster-autoscaler/simulator/drainability/rules/replicacount/rule_test.go +++ b/cluster-autoscaler/simulator/drainability/rules/replicacount/rule_test.go @@ -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{