Skip to content

Commit 7a4d755

Browse files
authored
Merge pull request kubernetes#128507 from dims/use-k8s.io/utils/lru-instead-of-github.com/golang/groupcache/lru
Use k8s.io/utils/lru instead of github.com/golang/groupcache/lru
2 parents 3e3276e + 2b0592e commit 7a4d755

File tree

68 files changed

+130
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+130
-172
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ require (
3131
github.com/go-logr/logr v1.4.2
3232
github.com/godbus/dbus/v5 v5.1.0
3333
github.com/gogo/protobuf v1.3.2
34-
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
3534
github.com/golang/protobuf v1.5.4
3635
github.com/google/cadvisor v0.51.0
3736
github.com/google/cel-go v0.21.0
@@ -117,7 +116,7 @@ require (
117116
k8s.io/pod-security-admission v0.0.0
118117
k8s.io/sample-apiserver v0.0.0
119118
k8s.io/system-validators v1.9.1
120-
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
119+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
121120
sigs.k8s.io/knftables v0.0.17
122121
sigs.k8s.io/structured-merge-diff/v4 v4.4.2
123122
sigs.k8s.io/yaml v1.4.0
@@ -154,6 +153,7 @@ require (
154153
github.com/go-openapi/swag v0.23.0 // indirect
155154
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
156155
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
156+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
157157
github.com/google/btree v1.0.1 // indirect
158158
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
159159
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,8 @@ k8s.io/kube-openapi v0.0.0-20240827152857-f7e401e7b4c2 h1:GKE9U8BH16uynoxQii0auT
690690
k8s.io/kube-openapi v0.0.0-20240827152857-f7e401e7b4c2/go.mod h1:coRQXBK9NxO98XUv3ZD6AK3xzHCxV6+b7lrquKwaKzA=
691691
k8s.io/system-validators v1.9.1 h1:O8xrr08foamG+1uQjAdiTLt/fT+QQJ4QNREfCWvuOws=
692692
k8s.io/system-validators v1.9.1/go.mod h1:d4UVrxKu52s0BHU984Peb9VpIq4V9sd8xjTBV/waY/I=
693-
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A=
694-
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
693+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 h1:M3sRQVHv7vB20Xc2ybTt7ODCeFj6JSWYFzOFnYeS6Ro=
694+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
695695
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.0 h1:CPT0ExVicCzcpeN4baWEV2ko2Z/AsiZgEdwgcfwLgMo=
696696
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.0/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw=
697697
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 h1:/Rv+M11QRah1itp8VhT6HoVx1Ray9eB4DBr+K+/sCJ8=

hack/unwanted-dependencies.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"github.com/gogo/googleapis": "depends on unmaintained github.com/gogo/protobuf",
2424
"github.com/gogo/protobuf": "unmaintained",
2525
"github.com/golang/mock": "unmaintained, archive mode",
26+
"github.com/golang/groupcache": "unmaintained",
2627
"github.com/google/gofuzz": "unmaintained, archive mode",
2728
"github.com/google/s2a-go": "cloud dependency, unstable",
2829
"github.com/google/shlex": "unmaintained, archive mode",
@@ -152,6 +153,11 @@
152153
"k8s.io/kubernetes",
153154
"k8s.io/metrics"
154155
],
156+
"github.com/golang/groupcache": [
157+
"github.com/Microsoft/hnslib",
158+
"go.etcd.io/etcd/server/v3",
159+
"go.opencensus.io"
160+
],
155161
"github.com/google/gofuzz": [
156162
"github.com/json-iterator/go",
157163
"k8s.io/apiextensions-apiserver",
@@ -232,6 +238,7 @@
232238
},
233239
"unwantedVendored": [
234240
"github.com/gogo/protobuf",
241+
"github.com/golang/groupcache",
235242
"github.com/google/gofuzz",
236243
"github.com/google/shlex",
237244
"github.com/gregjones/httpcache",

pkg/controller/garbagecollector/garbagecollector_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import (
3131
"golang.org/x/time/rate"
3232

3333
"k8s.io/klog/v2"
34+
"k8s.io/utils/lru"
3435

35-
"github.com/golang/groupcache/lru"
3636
"github.com/google/go-cmp/cmp"
3737
"github.com/stretchr/testify/assert"
3838

@@ -2654,7 +2654,7 @@ func assertState(s state) step {
26542654
}
26552655
if len(s.absentOwnerCache) != ctx.gc.absentOwnerCache.cache.Len() {
26562656
// only way to inspect is to drain them all, but that's ok because we're failing the test anyway
2657-
ctx.gc.absentOwnerCache.cache.OnEvicted = func(key lru.Key, item interface{}) {
2657+
err := ctx.gc.absentOwnerCache.cache.SetEvictionFunc(func(key lru.Key, item interface{}) {
26582658
found := false
26592659
for _, absent := range s.absentOwnerCache {
26602660
if absent == key {
@@ -2665,6 +2665,9 @@ func assertState(s state) step {
26652665
if !found {
26662666
ctx.t.Errorf("unexpected item in absent owner cache: %s", key)
26672667
}
2668+
})
2669+
if err != nil {
2670+
ctx.t.Error("unexpected error setting eviction function: %w", err)
26682671
}
26692672
ctx.gc.absentOwnerCache.cache.Clear()
26702673
ctx.t.Error("unexpected items in absent owner cache")

pkg/controller/garbagecollector/uid_cache.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@ limitations under the License.
1717
package garbagecollector
1818

1919
import (
20-
"sync"
21-
22-
"github.com/golang/groupcache/lru"
20+
"k8s.io/utils/lru"
2321
)
2422

2523
// ReferenceCache is an LRU cache for uid.
2624
type ReferenceCache struct {
27-
mutex sync.Mutex
2825
cache *lru.Cache
2926
}
3027

@@ -37,15 +34,11 @@ func NewReferenceCache(maxCacheEntries int) *ReferenceCache {
3734

3835
// Add adds a uid to the cache.
3936
func (c *ReferenceCache) Add(reference objectReference) {
40-
c.mutex.Lock()
41-
defer c.mutex.Unlock()
4237
c.cache.Add(reference, nil)
4338
}
4439

4540
// Has returns if a uid is in the cache.
4641
func (c *ReferenceCache) Has(reference objectReference) bool {
47-
c.mutex.Lock()
48-
defer c.mutex.Unlock()
4942
_, found := c.cache.Get(reference)
5043
return found
5144
}

pkg/controller/resourceclaim/uid_cache.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@ limitations under the License.
1717
package resourceclaim
1818

1919
import (
20-
"sync"
21-
22-
"github.com/golang/groupcache/lru"
20+
"k8s.io/utils/lru"
2321

2422
"k8s.io/apimachinery/pkg/types"
2523
)
2624

2725
// uidCache is an LRU cache for uid.
2826
type uidCache struct {
29-
mutex sync.Mutex
3027
cache *lru.Cache
3128
}
3229

@@ -39,15 +36,11 @@ func newUIDCache(maxCacheEntries int) *uidCache {
3936

4037
// Add adds a uid to the cache.
4138
func (c *uidCache) Add(uid types.UID) {
42-
c.mutex.Lock()
43-
defer c.mutex.Unlock()
4439
c.cache.Add(uid, nil)
4540
}
4641

4742
// Has returns if a uid is in the cache.
4843
func (c *uidCache) Has(uid types.UID) bool {
49-
c.mutex.Lock()
50-
defer c.mutex.Unlock()
5144
_, found := c.cache.Get(uid)
5245
return found
5346
}

pkg/kubelet/reason_cache.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ package kubelet
1818

1919
import (
2020
"fmt"
21-
"sync"
22-
23-
"github.com/golang/groupcache/lru"
2421
"k8s.io/apimachinery/pkg/types"
22+
"k8s.io/utils/lru"
23+
2524
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
2625
)
2726

@@ -37,7 +36,6 @@ import (
3736
// TODO(random-liu): Use more reliable cache which could collect garbage of failed pod.
3837
// TODO(random-liu): Move reason cache to somewhere better.
3938
type ReasonCache struct {
40-
lock sync.Mutex
4139
cache *lru.Cache
4240
}
4341

@@ -63,8 +61,6 @@ func (c *ReasonCache) composeKey(uid types.UID, name string) string {
6361

6462
// add adds error reason into the cache
6563
func (c *ReasonCache) add(uid types.UID, name string, reason error, message string) {
66-
c.lock.Lock()
67-
defer c.lock.Unlock()
6864
c.cache.Add(c.composeKey(uid, name), ReasonItem{reason, message})
6965
}
7066

@@ -86,17 +82,13 @@ func (c *ReasonCache) Update(uid types.UID, result kubecontainer.PodSyncResult)
8682

8783
// Remove removes error reason from the cache
8884
func (c *ReasonCache) Remove(uid types.UID, name string) {
89-
c.lock.Lock()
90-
defer c.lock.Unlock()
9185
c.cache.Remove(c.composeKey(uid, name))
9286
}
9387

9488
// Get gets error reason from the cache. The return values are error reason, error message and
9589
// whether an error reason is found in the cache. If no error reason is found, empty string will
9690
// be returned for error reason and error message.
9791
func (c *ReasonCache) Get(uid types.UID, name string) (*ReasonItem, bool) {
98-
c.lock.Lock()
99-
defer c.lock.Unlock()
10092
value, ok := c.cache.Get(c.composeKey(uid, name))
10193
if !ok {
10294
return nil, false

staging/src/k8s.io/api/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ require (
3131
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
3232
gopkg.in/inf.v0 v0.9.1 // indirect
3333
k8s.io/klog/v2 v2.130.1 // indirect
34-
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
34+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
3535
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
3636
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
3737
sigs.k8s.io/yaml v1.4.0 // indirect

staging/src/k8s.io/api/go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/apiextensions-apiserver/go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ require (
3333
k8s.io/component-base v0.0.0
3434
k8s.io/klog/v2 v2.130.1
3535
k8s.io/kube-openapi v0.0.0-20240827152857-f7e401e7b4c2
36-
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
36+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
3737
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3
3838
sigs.k8s.io/structured-merge-diff/v4 v4.4.2
3939
sigs.k8s.io/yaml v1.4.0
@@ -59,7 +59,6 @@ require (
5959
github.com/go-openapi/jsonreference v0.20.2 // indirect
6060
github.com/go-openapi/swag v0.23.0 // indirect
6161
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
62-
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
6362
github.com/golang/protobuf v1.5.4 // indirect
6463
github.com/google/btree v1.0.1 // indirect
6564
github.com/gorilla/websocket v1.5.0 // indirect

0 commit comments

Comments
 (0)