mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Rename exported methods on EquivalenceCache.
This changes two methods in EquivalenceCache to be unexported, because they should no longer be called by users of this type. (Even users in the same package!)
This commit is contained in:
parent
55662f26f1
commit
b85184227d
@ -86,7 +86,7 @@ func (ec *EquivalenceCache) RunPredicate(
|
||||
) (bool, []algorithm.PredicateFailureReason, error) {
|
||||
ec.Lock()
|
||||
defer ec.Unlock()
|
||||
fit, reasons, invalid := ec.PredicateWithECache(pod.GetName(), nodeInfo.Node().GetName(), predicateKey, equivClassInfo.hash, false)
|
||||
fit, reasons, invalid := ec.lookupResult(pod.GetName(), nodeInfo.Node().GetName(), predicateKey, equivClassInfo.hash, false)
|
||||
if !invalid {
|
||||
return fit, reasons, nil
|
||||
}
|
||||
@ -96,13 +96,13 @@ func (ec *EquivalenceCache) RunPredicate(
|
||||
}
|
||||
// Skip update if NodeInfo is stale.
|
||||
if cache != nil && cache.IsUpToDate(nodeInfo) {
|
||||
ec.UpdateCachedPredicateItem(pod.GetName(), nodeInfo.Node().GetName(), predicateKey, fit, reasons, equivClassInfo.hash, false)
|
||||
ec.updateResult(pod.GetName(), nodeInfo.Node().GetName(), predicateKey, fit, reasons, equivClassInfo.hash, false)
|
||||
}
|
||||
return fit, reasons, nil
|
||||
}
|
||||
|
||||
// UpdateCachedPredicateItem updates pod predicate for equivalence class
|
||||
func (ec *EquivalenceCache) UpdateCachedPredicateItem(
|
||||
// updateResult updates the cached result of a predicate.
|
||||
func (ec *EquivalenceCache) updateResult(
|
||||
podName, nodeName, predicateKey string,
|
||||
fit bool,
|
||||
reasons []algorithm.PredicateFailureReason,
|
||||
@ -134,12 +134,11 @@ func (ec *EquivalenceCache) UpdateCachedPredicateItem(
|
||||
glog.V(5).Infof("Updated cached predicate: %v for pod: %v on node: %s, with item %v", predicateKey, podName, nodeName, predicateItem)
|
||||
}
|
||||
|
||||
// PredicateWithECache returns:
|
||||
// 1. if fit
|
||||
// 2. reasons if not fit
|
||||
// 3. if this cache is invalid
|
||||
// based on cached predicate results
|
||||
func (ec *EquivalenceCache) PredicateWithECache(
|
||||
// lookupResult returns cached predicate results:
|
||||
// 1. if pod fit
|
||||
// 2. reasons if pod did not fit
|
||||
// 3. if cache item is not found
|
||||
func (ec *EquivalenceCache) lookupResult(
|
||||
podName, nodeName, predicateKey string,
|
||||
equivalenceHash uint64, needLock bool,
|
||||
) (bool, []algorithm.PredicateFailureReason, bool) {
|
||||
|
@ -253,7 +253,7 @@ func TestRunPredicate(t *testing.T) {
|
||||
ecache := NewEquivalenceCache()
|
||||
equivClass := ecache.getEquivalenceClassInfo(pod)
|
||||
if test.expectCacheHit {
|
||||
ecache.UpdateCachedPredicateItem(pod.Name, node.Node().Name, "testPredicate", test.expectFit, test.expectedReasons, equivClass.hash)
|
||||
ecache.updateResult(pod.Name, node.Node().Name, "testPredicate", test.expectFit, test.expectedReasons, equivClass.hash)
|
||||
}
|
||||
|
||||
fit, reasons, err := ecache.RunPredicate(test.pred.predicate, "testPredicate", pod, meta, node, equivClass, test.cache)
|
||||
@ -287,7 +287,7 @@ func TestRunPredicate(t *testing.T) {
|
||||
if !test.expectCacheHit && test.pred.callCount == 0 {
|
||||
t.Errorf("Predicate should be called")
|
||||
}
|
||||
_, _, invalid := ecache.PredicateWithECache(pod.Name, node.Node().Name, "testPredicate", equivClass.hash)
|
||||
_, _, invalid := ecache.lookupResult(pod.Name, node.Node().Name, "testPredicate", equivClass.hash)
|
||||
if invalid && test.expectCacheWrite {
|
||||
t.Errorf("Cache write should happen")
|
||||
}
|
||||
@ -301,7 +301,7 @@ func TestRunPredicate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateCachedPredicateItem(t *testing.T) {
|
||||
func TestUpdateResult(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
pod string
|
||||
@ -350,7 +350,7 @@ func TestUpdateCachedPredicateItem(t *testing.T) {
|
||||
test.equivalenceHash: predicateItem,
|
||||
})
|
||||
}
|
||||
ecache.UpdateCachedPredicateItem(
|
||||
ecache.updateResult(
|
||||
test.pod,
|
||||
test.nodeName,
|
||||
test.predicateKey,
|
||||
@ -374,7 +374,7 @@ func TestUpdateCachedPredicateItem(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPredicateWithECache(t *testing.T) {
|
||||
func TestLookupResult(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
podName string
|
||||
@ -460,7 +460,7 @@ func TestPredicateWithECache(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
ecache := NewEquivalenceCache()
|
||||
// set cached item to equivalence cache
|
||||
ecache.UpdateCachedPredicateItem(
|
||||
ecache.updateResult(
|
||||
test.podName,
|
||||
test.nodeName,
|
||||
test.predicateKey,
|
||||
@ -476,7 +476,7 @@ func TestPredicateWithECache(t *testing.T) {
|
||||
ecache.InvalidateCachedPredicateItem(test.nodeName, predicateKeys)
|
||||
}
|
||||
// calculate predicate with equivalence cache
|
||||
fit, reasons, invalid := ecache.PredicateWithECache(test.podName,
|
||||
fit, reasons, invalid := ecache.lookupResult(test.podName,
|
||||
test.nodeName,
|
||||
test.predicateKey,
|
||||
test.equivalenceHashForCalPredicate,
|
||||
@ -668,7 +668,7 @@ func TestInvalidateCachedPredicateItemOfAllNodes(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
// set cached item to equivalence cache
|
||||
ecache.UpdateCachedPredicateItem(
|
||||
ecache.updateResult(
|
||||
test.podName,
|
||||
test.nodeName,
|
||||
testPredicate,
|
||||
@ -735,7 +735,7 @@ func TestInvalidateAllCachedPredicateItemOfNode(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
// set cached item to equivalence cache
|
||||
ecache.UpdateCachedPredicateItem(
|
||||
ecache.updateResult(
|
||||
test.podName,
|
||||
test.nodeName,
|
||||
testPredicate,
|
||||
|
Loading…
Reference in New Issue
Block a user