diff --git a/pkg/descheduler/descheduler.go b/pkg/descheduler/descheduler.go index 8eae92b9fd..fa299edaf0 100644 --- a/pkg/descheduler/descheduler.go +++ b/pkg/descheduler/descheduler.go @@ -72,7 +72,7 @@ func RunDeschedulerStrategies(ctx context.Context, rs *options.DeschedulerServer sharedInformerFactory.Start(stopChannel) sharedInformerFactory.WaitForCacheSync(stopChannel) - strategyFuncs := map[string]strategyFunction{ + strategyFuncs := map[api.StrategyName]strategyFunction{ "RemoveDuplicates": strategies.RemoveDuplicatePods, "LowNodeUtilization": strategies.LowNodeUtilization, "RemovePodsViolatingInterPodAntiAffinity": strategies.RemovePodsViolatingInterPodAntiAffinity, @@ -136,9 +136,13 @@ func RunDeschedulerStrategies(ctx context.Context, rs *options.DeschedulerServer ignorePvcPods, ) - for name, f := range strategyFuncs { - if strategy := deschedulerPolicy.Strategies[api.StrategyName(name)]; strategy.Enabled { - f(ctx, rs.Client, strategy, nodes, podEvictor) + for name, strategy := range deschedulerPolicy.Strategies { + if f, ok := strategyFuncs[name]; ok { + if strategy.Enabled { + f(ctx, rs.Client, strategy, nodes, podEvictor) + } + } else { + klog.Errorf("Unknown strategy name '%s', skipping", name) } }