switch from golang-lru to the one in k8s.io/utils

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
Davanum Srinivas
2021-07-07 13:45:07 -04:00
parent 3a221b3332
commit 79d0c6cdc1
8 changed files with 16 additions and 46 deletions

View File

@@ -17,9 +17,8 @@ limitations under the License.
package eventratelimit
import (
"github.com/hashicorp/golang-lru"
"k8s.io/client-go/util/flowcontrol"
"k8s.io/utils/lru"
)
// cache is an interface for caching the limits of a particular type

View File

@@ -19,9 +19,8 @@ package eventratelimit
import (
"testing"
"github.com/hashicorp/golang-lru"
"k8s.io/client-go/util/flowcontrol"
"k8s.io/utils/lru"
)
func TestSingleCache(t *testing.T) {
@@ -51,10 +50,7 @@ func TestLRUCache(t *testing.T) {
nextRateLimiter++
return rateLimiter
}
underlyingCache, err := lru.New(2)
if err != nil {
t.Fatalf("Could not create LRU cache: %v", err)
}
underlyingCache := lru.New(2)
cache := lruCache{
rateLimiterFactory: rateLimiterFactory,
cache: underlyingCache,

View File

@@ -20,12 +20,11 @@ import (
"fmt"
"strings"
"github.com/hashicorp/golang-lru"
"k8s.io/apiserver/pkg/admission"
"k8s.io/client-go/util/flowcontrol"
api "k8s.io/kubernetes/pkg/apis/core"
eventratelimitapi "k8s.io/kubernetes/plugin/pkg/admission/eventratelimit/apis/eventratelimit"
"k8s.io/utils/lru"
)
const (
@@ -62,10 +61,7 @@ func newLimitEnforcer(config eventratelimitapi.Limit, clock flowcontrol.Clock) (
if cacheSize == 0 {
cacheSize = defaultCacheSize
}
underlyingCache, err := lru.New(cacheSize)
if err != nil {
return nil, fmt.Errorf("could not create lru cache: %v", err)
}
underlyingCache := lru.New(cacheSize)
cache := &lruCache{
rateLimiterFactory: rateLimiterFactory,
cache: underlyingCache,

View File

@@ -24,8 +24,6 @@ import (
"strings"
"time"
"github.com/hashicorp/golang-lru"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/resource"
@@ -39,6 +37,7 @@ import (
"k8s.io/client-go/kubernetes"
corev1listers "k8s.io/client-go/listers/core/v1"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/utils/lru"
)
const (
@@ -191,10 +190,7 @@ func (l *LimitRanger) GetLimitRanges(a admission.Attributes) ([]*corev1.LimitRan
// NewLimitRanger returns an object that enforces limits based on the supplied limit function
func NewLimitRanger(actions LimitRangerActions) (*LimitRanger, error) {
liveLookupCache, err := lru.New(10000)
if err != nil {
return nil, err
}
liveLookupCache := lru.New(10000)
if actions == nil {
actions = &DefaultLimitRangerActions{}