Skip to content

Commit 779c1ba

Browse files
authored
Merge pull request #6412 from shamil/validate_api_version_in_ds_v2
Allow draining when DaemonSet kind has custom API Group
2 parents ed25db1 + ea26159 commit 779c1ba

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

cluster-autoscaler/simulator/drainability/rules/replicacount/rule.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
apiv1 "k8s.io/api/core/v1"
2323
apierrors "k8s.io/apimachinery/pkg/api/errors"
24+
"k8s.io/apimachinery/pkg/runtime/schema"
2425
"k8s.io/autoscaler/cluster-autoscaler/simulator/drainability"
2526
"k8s.io/autoscaler/cluster-autoscaler/utils/drain"
2627
pod_util "k8s.io/autoscaler/cluster-autoscaler/utils/pod"
@@ -57,6 +58,12 @@ func (r *Rule) Drainable(drainCtx *drainability.DrainContext, pod *apiv1.Pod) dr
5758
if controllerRef == nil {
5859
return drainability.NewUndefinedStatus()
5960
}
61+
62+
refGroup, err := schema.ParseGroupVersion(controllerRef.APIVersion)
63+
if err != nil {
64+
return drainability.NewUndefinedStatus()
65+
}
66+
6067
refKind := controllerRef.Kind
6168

6269
if refKind == "ReplicationController" {
@@ -71,8 +78,8 @@ func (r *Rule) Drainable(drainCtx *drainability.DrainContext, pod *apiv1.Pod) dr
7178
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))
7279
}
7380
} else if pod_util.IsDaemonSetPod(pod) {
74-
if refKind != "DaemonSet" {
75-
// We don't have a listener for the other DaemonSet kind.
81+
if refGroup.Group != "apps" || refKind != "DaemonSet" {
82+
// We don't have a listener for the other DaemonSet group or kind.
7683
// TODO: Use a generic client for checking the reference.
7784
return drainability.NewUndefinedStatus()
7885
}

cluster-autoscaler/simulator/drainability/rules/replicacount/rule_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,30 @@ func TestDrainable(t *testing.T) {
145145
wantReason: drain.ControllerNotFound,
146146
wantError: true,
147147
},
148+
"DS-managed pod by a custom API Group": {
149+
pod: &apiv1.Pod{
150+
ObjectMeta: metav1.ObjectMeta{
151+
Name: "bar",
152+
Namespace: "default",
153+
OwnerReferences: test.GenerateOwnerReferences(ds.Name, "DaemonSet", "crd/v1", ""),
154+
},
155+
Spec: apiv1.PodSpec{
156+
NodeName: "node",
157+
},
158+
},
159+
},
160+
"DS-managed pod by a custom API Group with missing reference": {
161+
pod: &apiv1.Pod{
162+
ObjectMeta: metav1.ObjectMeta{
163+
Name: "bar",
164+
Namespace: "default",
165+
OwnerReferences: test.GenerateOwnerReferences("missing", "DaemonSet", "crd/v1", ""),
166+
},
167+
Spec: apiv1.PodSpec{
168+
NodeName: "node",
169+
},
170+
},
171+
},
148172
"DS-managed pod by a custom Daemonset": {
149173
pod: &apiv1.Pod{
150174
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)