Skip to content

Commit

Permalink
Merge pull request #6412 from shamil/validate_api_version_in_ds_v2
Browse files Browse the repository at this point in the history
Allow draining when DaemonSet kind has custom API Group
  • Loading branch information
k8s-ci-robot authored Jan 23, 2024
2 parents ed25db1 + ea26159 commit 779c1ba
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
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

0 comments on commit 779c1ba

Please sign in to comment.