diff --git a/controllers/numaresourcesscheduler_controller.go b/controllers/numaresourcesscheduler_controller.go index 14d2bebd3..a25ea61d7 100644 --- a/controllers/numaresourcesscheduler_controller.go +++ b/controllers/numaresourcesscheduler_controller.go @@ -264,6 +264,10 @@ func unpackAPIResyncPeriod(reconcilePeriod *metav1.Duration) time.Duration { func configParamsFromSchedSpec(schedSpec nropv1.NUMAResourcesSchedulerSpec, cacheResyncPeriod time.Duration, namespace string) k8swgmanifests.ConfigParams { resyncPeriod := int64(cacheResyncPeriod.Seconds()) + // if no actual replicas are required, leader election is unnecessary, so + // we force it to off to reduce the background noise. + // note: the api validation/normalization layer must ensure this value is != nil + leaderElect := (*schedSpec.Replicas > 1) params := k8swgmanifests.ConfigParams{ ProfileName: schedSpec.SchedulerName, @@ -271,16 +275,18 @@ func configParamsFromSchedSpec(schedSpec nropv1.NUMAResourcesSchedulerSpec, cach ResyncPeriodSeconds: &resyncPeriod, }, ScoringStrategy: &k8swgmanifests.ScoringStrategyParams{}, - } - - if schedSpec.Replicas != nil && *schedSpec.Replicas > 1 { - params.LeaderElection = &k8swgmanifests.LeaderElectionParams{ - LeaderElect: true, + LeaderElection: &k8swgmanifests.LeaderElectionParams{ + // Make sure to always set explicitly the value and override the configmap defaults. + LeaderElect: leaderElect, + // unconditionally set those to make sure + // to play nice with the cluster and the main scheduler ResourceNamespace: namespace, ResourceName: leaderElectionResourceName, - } + }, } + klog.V(2).InfoS("setting leader election parameters", dumpLeaderElectionParams(params.LeaderElection)...) + var foreignPodsDetect string var resyncMethod string = k8swgmanifests.CacheResyncAutodetect var informerMode string @@ -317,7 +323,7 @@ func configParamsFromSchedSpec(schedSpec nropv1.NUMAResourcesSchedulerSpec, cach params.Cache.ResyncMethod = &resyncMethod params.Cache.ForeignPodsDetectMode = &foreignPodsDetect params.Cache.InformerMode = &informerMode - klog.InfoS("setting cache parameters", dumpConfigCacheParams(params.Cache)...) + klog.V(2).InfoS("setting cache parameters", dumpConfigCacheParams(params.Cache)...) return params } @@ -331,6 +337,14 @@ func dumpConfigCacheParams(ccp *k8swgmanifests.ConfigCacheParams) []interface{} } } +func dumpLeaderElectionParams(lep *k8swgmanifests.LeaderElectionParams) []interface{} { + return []interface{}{ + "leaderElect", lep.LeaderElect, + "resourceNamespace", lep.ResourceNamespace, + "resourceName", lep.ResourceName, + } +} + func strInt64Ptr(ip *int64) string { if ip == nil { return "N/A"