Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop hashicorp lru - switch to the lru impl in k8s.io/utils #103548

Merged
merged 3 commits into from Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
366 changes: 0 additions & 366 deletions LICENSES/vendor/github.com/hashicorp/golang-lru/LICENSE

This file was deleted.

5 changes: 2 additions & 3 deletions go.mod
Expand Up @@ -51,7 +51,6 @@ require (
github.com/google/gofuzz v1.1.0
github.com/google/uuid v1.1.2
github.com/googleapis/gnostic v0.5.5
github.com/hashicorp/golang-lru v0.5.1
github.com/heketi/heketi v10.3.0+incompatible
github.com/heketi/tests v0.0.0-20151005000721-f3775cbcefd6 // indirect
github.com/ishidawataru/sctp v0.0.0-20190723014705-7c296d48a2b5
Expand Down Expand Up @@ -132,7 +131,7 @@ require (
k8s.io/pod-security-admission v0.0.0
k8s.io/sample-apiserver v0.0.0
k8s.io/system-validators v1.5.0
k8s.io/utils v0.0.0-20210521133846-da695404a2bc
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9
sigs.k8s.io/structured-merge-diff/v4 v4.1.2
sigs.k8s.io/yaml v1.2.0
)
Expand Down Expand Up @@ -515,7 +514,7 @@ replace (
k8s.io/sample-cli-plugin => ./staging/src/k8s.io/sample-cli-plugin
k8s.io/sample-controller => ./staging/src/k8s.io/sample-controller
k8s.io/system-validators => k8s.io/system-validators v1.5.0
k8s.io/utils => k8s.io/utils v0.0.0-20210521133846-da695404a2bc
k8s.io/utils => k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9
modernc.org/cc => modernc.org/cc v1.0.0
modernc.org/golex => modernc.org/golex v1.0.0
modernc.org/mathutil => modernc.org/mathutil v1.0.0
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Expand Up @@ -260,7 +260,6 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
Expand Down Expand Up @@ -591,8 +590,8 @@ k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e h1:KLHHjkdQFomZy8+06csTWZ
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e/go.mod h1:vHXdDvt9+2spS2Rx9ql3I8tycm3H9FDfdUoIuKCefvw=
k8s.io/system-validators v1.5.0 h1:gGgluCTkpKc/zUszjamp4LFfMVM0wuYG2qjIFL4MMeQ=
k8s.io/system-validators v1.5.0/go.mod h1:bPldcLgkIUK22ALflnsXk8pvkTEndYdNuaHH6gRrl0Q=
k8s.io/utils v0.0.0-20210521133846-da695404a2bc h1:dx6VGe+PnOW/kD/2UV4aUSsRfJGd7+lcqgJ6Xg0HwUs=
k8s.io/utils v0.0.0-20210521133846-da695404a2bc/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9 h1:imL9YgXQ9p7xmPzHFm/vVd/cF78jad+n4wK1ABwYtMM=
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=
modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk=
modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=
Expand Down
3 changes: 1 addition & 2 deletions plugin/pkg/admission/eventratelimit/cache.go
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions plugin/pkg/admission/eventratelimit/cache_test.go
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions plugin/pkg/admission/eventratelimit/limitenforcer.go
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions plugin/pkg/admission/limitranger/admission.go
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion staging/src/k8s.io/apiextensions-apiserver/go.mod
Expand Up @@ -26,7 +26,7 @@ require (
k8s.io/component-base v0.0.0
k8s.io/klog/v2 v2.9.0
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e
k8s.io/utils v0.0.0-20210521133846-da695404a2bc
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9
sigs.k8s.io/structured-merge-diff/v4 v4.1.2
sigs.k8s.io/yaml v1.2.0
)
Expand Down
5 changes: 2 additions & 3 deletions staging/src/k8s.io/apiextensions-apiserver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions staging/src/k8s.io/apiserver/go.mod
Expand Up @@ -20,7 +20,6 @@ require (
github.com/google/uuid v1.1.2
github.com/googleapis/gnostic v0.5.5
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/hashicorp/golang-lru v0.5.1
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021 // indirect
github.com/spf13/pflag v1.0.5
Expand Down Expand Up @@ -48,7 +47,7 @@ require (
k8s.io/component-base v0.0.0
k8s.io/klog/v2 v2.9.0
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e
k8s.io/utils v0.0.0-20210521133846-da695404a2bc
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.21
sigs.k8s.io/structured-merge-diff/v4 v4.1.2
sigs.k8s.io/yaml v1.2.0
Expand Down
5 changes: 2 additions & 3 deletions staging/src/k8s.io/apiserver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -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,
Expand Down Expand Up @@ -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 &quotaAccessor{
Expand Down
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)

Expand Down
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions staging/src/k8s.io/apiserver/pkg/util/webhook/client.go
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions staging/src/k8s.io/cli-runtime/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion staging/src/k8s.io/client-go/go.mod
Expand Up @@ -33,7 +33,7 @@ require (
k8s.io/api v0.0.0
k8s.io/apimachinery v0.0.0
k8s.io/klog/v2 v2.9.0
k8s.io/utils v0.0.0-20210521133846-da695404a2bc
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9
sigs.k8s.io/structured-merge-diff/v4 v4.1.2
sigs.k8s.io/yaml v1.2.0
)
Expand Down
4 changes: 2 additions & 2 deletions staging/src/k8s.io/client-go/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion staging/src/k8s.io/cloud-provider/go.mod
Expand Up @@ -16,7 +16,7 @@ require (
k8s.io/component-base v0.0.0
k8s.io/controller-manager v0.0.0
k8s.io/klog/v2 v2.9.0
k8s.io/utils v0.0.0-20210521133846-da695404a2bc
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9
)

replace (
Expand Down
5 changes: 2 additions & 3 deletions staging/src/k8s.io/cloud-provider/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions staging/src/k8s.io/code-generator/examples/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion staging/src/k8s.io/component-base/go.mod
Expand Up @@ -30,7 +30,7 @@ require (
k8s.io/apimachinery v0.0.0
k8s.io/client-go v0.0.0
k8s.io/klog/v2 v2.9.0
k8s.io/utils v0.0.0-20210521133846-da695404a2bc
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9
)

replace (
Expand Down
4 changes: 2 additions & 2 deletions staging/src/k8s.io/component-base/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.