Snapshot cluster state for scheduler every loop

Change-Id: If9d162b83ccc914fe1b02e4689bfe1f4b264407f
This commit is contained in:
Łukasz Osipiuk 2019-11-27 17:06:17 +01:00
parent 247111eaf1
commit b67854e800
2 changed files with 15 additions and 0 deletions

View File

@ -194,6 +194,10 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) errors.AutoscalerError
klog.V(4).Info("Starting main loop") klog.V(4).Info("Starting main loop")
stateUpdateStart := time.Now() stateUpdateStart := time.Now()
if err := a.PredicateChecker.SnapshotClusterState(); err != nil {
return errors.ToAutoscalerError(errors.ApiCallError, fmt.Errorf("could not snapshot cluster state in scheduler; %v", err))
}
allNodes, readyNodes, typedErr := a.obtainNodeLists(a.CloudProvider) allNodes, readyNodes, typedErr := a.obtainNodeLists(a.CloudProvider)
if typedErr != nil { if typedErr != nil {
klog.Errorf("Failed to get node list: %v", typedErr) klog.Errorf("Failed to get node list: %v", typedErr)

View File

@ -63,6 +63,7 @@ type PredicateChecker struct {
predicates []PredicateInfo predicates []PredicateInfo
predicateMetadataProducer predicates.MetadataProducer predicateMetadataProducer predicates.MetadataProducer
enableAffinityPredicate bool enableAffinityPredicate bool
scheduler *scheduler.Scheduler
} }
// We run some predicates first as they are cheap to check and they should be enough // We run some predicates first as they are cheap to check and they should be enough
@ -162,6 +163,7 @@ func NewPredicateChecker(kubeClient kube_client.Interface, stop <-chan struct{})
predicates: predicateList, predicates: predicateList,
predicateMetadataProducer: sched.Algorithm.PredicateMetadataProducer(), predicateMetadataProducer: sched.Algorithm.PredicateMetadataProducer(),
enableAffinityPredicate: true, enableAffinityPredicate: true,
scheduler: sched,
}, nil }, nil
} }
@ -199,6 +201,15 @@ func NewCustomTestPredicateChecker(predicateInfos []PredicateInfo) *PredicateChe
} }
} }
// SnapshotClusterState updates cluster snapshot used by the predicate checker.
// It should be called every CA loop iteration.
func (p *PredicateChecker) SnapshotClusterState() error {
if p.scheduler != nil {
return p.scheduler.Algorithm.Snapshot()
}
return nil
}
// SetAffinityPredicateEnabled can be used to enable or disable checking MatchInterPodAffinity // SetAffinityPredicateEnabled can be used to enable or disable checking MatchInterPodAffinity
// predicate. This will cause incorrect CA behavior if there is at least a single pod in // predicate. This will cause incorrect CA behavior if there is at least a single pod in
// cluster using affinity/antiaffinity. However, checking affinity predicate is extremely // cluster using affinity/antiaffinity. However, checking affinity predicate is extremely