mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +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) {
|
) (bool, []algorithm.PredicateFailureReason, error) {
|
||||||
ec.Lock()
|
ec.Lock()
|
||||||
defer ec.Unlock()
|
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 {
|
if !invalid {
|
||||||
return fit, reasons, nil
|
return fit, reasons, nil
|
||||||
}
|
}
|
||||||
@ -96,13 +96,13 @@ func (ec *EquivalenceCache) RunPredicate(
|
|||||||
}
|
}
|
||||||
// Skip update if NodeInfo is stale.
|
// Skip update if NodeInfo is stale.
|
||||||
if cache != nil && cache.IsUpToDate(nodeInfo) {
|
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
|
return fit, reasons, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateCachedPredicateItem updates pod predicate for equivalence class
|
// updateResult updates the cached result of a predicate.
|
||||||
func (ec *EquivalenceCache) UpdateCachedPredicateItem(
|
func (ec *EquivalenceCache) updateResult(
|
||||||
podName, nodeName, predicateKey string,
|
podName, nodeName, predicateKey string,
|
||||||
fit bool,
|
fit bool,
|
||||||
reasons []algorithm.PredicateFailureReason,
|
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)
|
glog.V(5).Infof("Updated cached predicate: %v for pod: %v on node: %s, with item %v", predicateKey, podName, nodeName, predicateItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PredicateWithECache returns:
|
// lookupResult returns cached predicate results:
|
||||||
// 1. if fit
|
// 1. if pod fit
|
||||||
// 2. reasons if not fit
|
// 2. reasons if pod did not fit
|
||||||
// 3. if this cache is invalid
|
// 3. if cache item is not found
|
||||||
// based on cached predicate results
|
func (ec *EquivalenceCache) lookupResult(
|
||||||
func (ec *EquivalenceCache) PredicateWithECache(
|
|
||||||
podName, nodeName, predicateKey string,
|
podName, nodeName, predicateKey string,
|
||||||
equivalenceHash uint64, needLock bool,
|
equivalenceHash uint64, needLock bool,
|
||||||
) (bool, []algorithm.PredicateFailureReason, bool) {
|
) (bool, []algorithm.PredicateFailureReason, bool) {
|
||||||
|
@ -253,7 +253,7 @@ func TestRunPredicate(t *testing.T) {
|
|||||||
ecache := NewEquivalenceCache()
|
ecache := NewEquivalenceCache()
|
||||||
equivClass := ecache.getEquivalenceClassInfo(pod)
|
equivClass := ecache.getEquivalenceClassInfo(pod)
|
||||||
if test.expectCacheHit {
|
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)
|
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 {
|
if !test.expectCacheHit && test.pred.callCount == 0 {
|
||||||
t.Errorf("Predicate should be called")
|
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 {
|
if invalid && test.expectCacheWrite {
|
||||||
t.Errorf("Cache write should happen")
|
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 {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
pod string
|
pod string
|
||||||
@ -350,7 +350,7 @@ func TestUpdateCachedPredicateItem(t *testing.T) {
|
|||||||
test.equivalenceHash: predicateItem,
|
test.equivalenceHash: predicateItem,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ecache.UpdateCachedPredicateItem(
|
ecache.updateResult(
|
||||||
test.pod,
|
test.pod,
|
||||||
test.nodeName,
|
test.nodeName,
|
||||||
test.predicateKey,
|
test.predicateKey,
|
||||||
@ -374,7 +374,7 @@ func TestUpdateCachedPredicateItem(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPredicateWithECache(t *testing.T) {
|
func TestLookupResult(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
podName string
|
podName string
|
||||||
@ -460,7 +460,7 @@ func TestPredicateWithECache(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
ecache := NewEquivalenceCache()
|
ecache := NewEquivalenceCache()
|
||||||
// set cached item to equivalence cache
|
// set cached item to equivalence cache
|
||||||
ecache.UpdateCachedPredicateItem(
|
ecache.updateResult(
|
||||||
test.podName,
|
test.podName,
|
||||||
test.nodeName,
|
test.nodeName,
|
||||||
test.predicateKey,
|
test.predicateKey,
|
||||||
@ -476,7 +476,7 @@ func TestPredicateWithECache(t *testing.T) {
|
|||||||
ecache.InvalidateCachedPredicateItem(test.nodeName, predicateKeys)
|
ecache.InvalidateCachedPredicateItem(test.nodeName, predicateKeys)
|
||||||
}
|
}
|
||||||
// calculate predicate with equivalence cache
|
// calculate predicate with equivalence cache
|
||||||
fit, reasons, invalid := ecache.PredicateWithECache(test.podName,
|
fit, reasons, invalid := ecache.lookupResult(test.podName,
|
||||||
test.nodeName,
|
test.nodeName,
|
||||||
test.predicateKey,
|
test.predicateKey,
|
||||||
test.equivalenceHashForCalPredicate,
|
test.equivalenceHashForCalPredicate,
|
||||||
@ -668,7 +668,7 @@ func TestInvalidateCachedPredicateItemOfAllNodes(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
// set cached item to equivalence cache
|
// set cached item to equivalence cache
|
||||||
ecache.UpdateCachedPredicateItem(
|
ecache.updateResult(
|
||||||
test.podName,
|
test.podName,
|
||||||
test.nodeName,
|
test.nodeName,
|
||||||
testPredicate,
|
testPredicate,
|
||||||
@ -735,7 +735,7 @@ func TestInvalidateAllCachedPredicateItemOfNode(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
// set cached item to equivalence cache
|
// set cached item to equivalence cache
|
||||||
ecache.UpdateCachedPredicateItem(
|
ecache.updateResult(
|
||||||
test.podName,
|
test.podName,
|
||||||
test.nodeName,
|
test.nodeName,
|
||||||
testPredicate,
|
testPredicate,
|
||||||
|
Loading…
Reference in New Issue
Block a user