diff --git a/cluster-autoscaler/utils/drain/drain.go b/cluster-autoscaler/utils/drain/drain.go index 81eef9ad858a..00f66e673fb5 100644 --- a/cluster-autoscaler/utils/drain/drain.go +++ b/cluster-autoscaler/utils/drain/drain.go @@ -17,6 +17,7 @@ limitations under the License. package drain import ( + "fmt" "strings" "time" @@ -68,6 +69,31 @@ const ( UnexpectedError ) +func (e BlockingPodReason) String() string { + switch e { + case NoReason: + return "NoReason" + case ControllerNotFound: + return "ControllerNotFound" + case MinReplicasReached: + return "MinReplicasReached" + case NotReplicated: + return "NotReplicated" + case LocalStorageRequested: + return "LocalStorageRequested" + case NotSafeToEvictAnnotation: + return "NotSafeToEvictAnnotation" + case UnmovableKubeSystemPod: + return "UnmovableKubeSystemPod" + case NotEnoughPdb: + return "NotEnoughPdb" + case UnexpectedError: + return "UnexpectedError" + default: + return fmt.Sprintf("unrecognized reason: %d", int(e)) + } +} + // ControllerRef returns the OwnerReference to pod's controller. func ControllerRef(pod *apiv1.Pod) *metav1.OwnerReference { return metav1.GetControllerOf(pod) diff --git a/cluster-autoscaler/utils/drain/drain_test.go b/cluster-autoscaler/utils/drain/drain_test.go index 02cd6aa0eb5e..ba65b3a8f38c 100644 --- a/cluster-autoscaler/utils/drain/drain_test.go +++ b/cluster-autoscaler/utils/drain/drain_test.go @@ -137,43 +137,43 @@ func TestBlockingPodReasonFormatting(t *testing.T) { }{ { bpr: NoReason, - want: "0", + want: "NoReason", }, { bpr: ControllerNotFound, - want: "1", + want: "ControllerNotFound", }, { - bpr: MinReplicasReached, - want: "2", + bpr: ControllerNotFound, + want: "ControllerNotFound", }, { bpr: NotReplicated, - want: "3", + want: "NotReplicated", }, { bpr: LocalStorageRequested, - want: "4", + want: "LocalStorageRequested", }, { bpr: NotSafeToEvictAnnotation, - want: "5", + want: "NotSafeToEvictAnnotation", }, { bpr: UnmovableKubeSystemPod, - want: "6", + want: "UnmovableKubeSystemPod", }, { bpr: NotEnoughPdb, - want: "7", + want: "NotEnoughPdb", }, { bpr: UnexpectedError, - want: "8", + want: "UnexpectedError", }, { bpr: BlockingPodReason(9), - want: "9", + want: "unrecognized reason: 9", }, } { t.Run(tc.want, func(t *testing.T) {