mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 23:15:14 +00:00
switch from golang-lru to the one in k8s.io/utils
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
parent
3a221b3332
commit
79d0c6cdc1
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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{}
|
||||
|
@ -21,14 +21,13 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/golang-lru"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apiserver/pkg/storage/etcd3"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
corev1listers "k8s.io/client-go/listers/core/v1"
|
||||
"k8s.io/utils/lru"
|
||||
)
|
||||
|
||||
// QuotaAccessor abstracts the get/set logic from the rest of the Evaluator. This could be a test stub, a straight passthrough,
|
||||
@ -61,14 +60,8 @@ type quotaAccessor struct {
|
||||
|
||||
// newQuotaAccessor creates an object that conforms to the QuotaAccessor interface to be used to retrieve quota objects.
|
||||
func newQuotaAccessor() (*quotaAccessor, error) {
|
||||
liveLookupCache, err := lru.New(100)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
updatedCache, err := lru.New(100)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
liveLookupCache := lru.New(100)
|
||||
updatedCache := lru.New(100)
|
||||
|
||||
// client and lister will be set when SetInternalKubeClientSet and SetInternalKubeInformerFactory are invoked
|
||||
return "aAccessor{
|
||||
|
@ -24,10 +24,10 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
"k8s.io/utils/lru"
|
||||
)
|
||||
|
||||
func TestLRUCacheLookup(t *testing.T) {
|
||||
@ -86,10 +86,7 @@ func TestLRUCacheLookup(t *testing.T) {
|
||||
|
||||
for _, tc := range testcases {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
liveLookupCache, err := lru.New(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
liveLookupCache := lru.New(1)
|
||||
kubeClient := fake.NewSimpleClientset(tc.clientInput...)
|
||||
informerFactory := informers.NewSharedInformerFactory(kubeClient, 0)
|
||||
|
||||
|
@ -26,8 +26,8 @@ import (
|
||||
"time"
|
||||
|
||||
"k8s.io/apiserver/pkg/storage/value"
|
||||
"k8s.io/utils/lru"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
"golang.org/x/crypto/cryptobyte"
|
||||
)
|
||||
|
||||
@ -64,14 +64,10 @@ type envelopeTransformer struct {
|
||||
func NewEnvelopeTransformer(envelopeService Service, cacheSize int, baseTransformerFunc func(cipher.Block) value.Transformer) (value.Transformer, error) {
|
||||
var (
|
||||
cache *lru.Cache
|
||||
err error
|
||||
)
|
||||
|
||||
if cacheSize > 0 {
|
||||
cache, err = lru.New(cacheSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cache = lru.New(cacheSize)
|
||||
}
|
||||
return &envelopeTransformer{
|
||||
envelopeService: envelopeService,
|
||||
|
@ -25,13 +25,13 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/golang-lru"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
"k8s.io/apiserver/pkg/util/x509metrics"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/utils/lru"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -65,10 +65,7 @@ type ClientManager struct {
|
||||
|
||||
// NewClientManager creates a clientManager.
|
||||
func NewClientManager(gvs []schema.GroupVersion, addToSchemaFuncs ...func(s *runtime.Scheme) error) (ClientManager, error) {
|
||||
cache, err := lru.New(defaultCacheSize)
|
||||
if err != nil {
|
||||
return ClientManager{}, err
|
||||
}
|
||||
cache := lru.New(defaultCacheSize)
|
||||
hookScheme := runtime.NewScheme()
|
||||
for _, addToSchemaFunc := range addToSchemaFuncs {
|
||||
if err := addToSchemaFunc(hookScheme); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user