Skip to content

Commit

Permalink
sched: always set the leader election parameters
Browse files Browse the repository at this point in the history
Because of a overlook, we used to set the leader election
params only if replicas > 1 was requested. This left
the key *and default* corner case of replicas=1 with
compiled in defaults, which are questionable at best
and most likely harmful for our use case.

Make sure to always set sane parameters, obviously
taking into account the user desires from the spec
(Replicas field).

Add more logs to make troubleshooting easier

Signed-off-by: Francesco Romani <[email protected]>
  • Loading branch information
ffromani committed Nov 19, 2024
1 parent a001efc commit 26e2d61
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions controllers/numaresourcesscheduler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,23 +264,29 @@ 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,
Cache: &k8swgmanifests.ConfigCacheParams{
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
Expand Down Expand Up @@ -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
}
Expand All @@ -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"
Expand Down

0 comments on commit 26e2d61

Please sign in to comment.