Skip to content

Commit

Permalink
refactor: use ParseGroupVersion to parse GV
Browse files Browse the repository at this point in the history
Signed-off-by: vadasambar <[email protected]>
  • Loading branch information
vadasambar committed Jan 31, 2023
1 parent f8438b1 commit 7408206
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cluster-autoscaler/utils/drain/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package drain

import (
"fmt"
"strings"
"time"

apiv1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -120,16 +119,21 @@ func GetPodsForDeletionOnNodeDrain(
}

if refKind != "" {
gv := strings.Split(controllerRef.APIVersion, "/")

gv, err := schema.ParseGroupVersion(controllerRef.APIVersion)
if err != nil {
return []*apiv1.Pod{}, []*apiv1.Pod{}, &BlockingPod{Pod: pod, Reason: UnexpectedError}, fmt.Errorf("%s/%s pod's owner %s/%s has invalid group version: %v", pod.Namespace, pod.Name, refKind, controllerName, err)
}

// controllerRef doesn't have a namespace by design
// The controller/owner is either in the same namespace as the pod
// or it's assumed to be a cluster-scoped resource
// The assumption in the code below is that the controllerRef/owner of
// a pod resource will always be in the same namespace
// TODO: find a better way to handle this
l := listers.GenericListerFactory().GetLister(schema.GroupVersionResource{
Group: gv[0],
Version: gv[1],
Group: gv.Group,
Version: gv.Version,
Resource: controllerRef.Kind,
}, pod.GetNamespace())

Expand Down

0 comments on commit 7408206

Please sign in to comment.