Skip to content

Commit 5d972f0

Browse files
committed
Rename nodeCache to nodeResourcesCache
1 parent c86f85a commit 5d972f0

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

cluster-autoscaler/resourcequotas/cache.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ import (
2626
"k8s.io/autoscaler/cluster-autoscaler/processors/customresources"
2727
)
2828

29-
type nodeCache struct {
29+
type nodeResourcesCache struct {
3030
crp customresources.CustomResourcesProcessor
3131
resources map[string]resourceList
3232
}
3333

34-
func newNodeCache(crp customresources.CustomResourcesProcessor) *nodeCache {
35-
return &nodeCache{
34+
func newNodeResourcesCache(crp customresources.CustomResourcesProcessor) *nodeResourcesCache {
35+
return &nodeResourcesCache{
3636
crp: crp,
3737
resources: make(map[string]resourceList),
3838
}
3939
}
4040

41-
func (nc *nodeCache) nodeResources(autoscalingCtx *cacontext.AutoscalingContext, node *corev1.Node, nodeGroup cloudprovider.NodeGroup) (resourceList, error) {
41+
func (nc *nodeResourcesCache) nodeResources(autoscalingCtx *cacontext.AutoscalingContext, node *corev1.Node, nodeGroup cloudprovider.NodeGroup) (resourceList, error) {
4242
if nodeGroup != nil {
4343
if delta, ok := nc.resources[nodeGroup.Id()]; ok {
4444
return delta, nil

cluster-autoscaler/resourcequotas/cache_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type mockCustomResourcesProcessor struct {
3535
mock.Mock
3636
}
3737

38-
func (m *mockCustomResourcesProcessor) FilterOutNodesWithUnreadyResources(autoscalingCtx *context.AutoscalingContext, allNodes, readyNodes []*apiv1.Node, draSnapshot *drasnapshot.Snapshot) ([]*apiv1.Node, []*apiv1.Node) {
38+
func (m *mockCustomResourcesProcessor) FilterOutNodesWithUnreadyResources(_ *context.AutoscalingContext, allNodes, readyNodes []*apiv1.Node, _ *drasnapshot.Snapshot) ([]*apiv1.Node, []*apiv1.Node) {
3939
return allNodes, readyNodes
4040
}
4141

@@ -48,7 +48,7 @@ func (m *mockCustomResourcesProcessor) CleanUp() {
4848
return
4949
}
5050

51-
func TestNodeCache(t *testing.T) {
51+
func TestNodeResourcesCache(t *testing.T) {
5252
node := test.BuildTestNode("n1", 1000, 2000)
5353
autoscalingCtx := &context.AutoscalingContext{}
5454
ng1 := cptest.NewTestNodeGroup("ng1", 1, 10, 1, true, false, "n1-template", nil, nil)
@@ -104,7 +104,7 @@ func TestNodeCache(t *testing.T) {
104104
t.Run(tc.name, func(t *testing.T) {
105105
mockCRP := &mockCustomResourcesProcessor{}
106106
tc.setupCRPExpectations(&mockCRP.Mock)
107-
nc := newNodeCache(mockCRP)
107+
nc := newNodeResourcesCache(mockCRP)
108108
for _, call := range tc.calls {
109109
resources, err := nc.nodeResources(autoscalingCtx, call.node, call.nodeGroup)
110110
if err != nil {

cluster-autoscaler/resourcequotas/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (f *TrackerFactory) NewQuotasTracker(autoscalingCtx *context.AutoscalingCon
5555
if err != nil {
5656
return nil, err
5757
}
58-
nc := newNodeCache(f.crp)
58+
nc := newNodeResourcesCache(f.crp)
5959
uc := newUsageCalculator(f.nodeFilter, nc)
6060
usages, err := uc.calculateUsages(autoscalingCtx, nodes, quotas)
6161
if err != nil {

cluster-autoscaler/resourcequotas/tracker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type resourceList map[string]int64
4242
// Tracker tracks resource quotas.
4343
type Tracker struct {
4444
quotaStatuses []*quotaStatus
45-
nodeCache *nodeCache
45+
nodeCache *nodeResourcesCache
4646
}
4747

4848
type quotaStatus struct {
@@ -51,7 +51,7 @@ type quotaStatus struct {
5151
}
5252

5353
// newTracker creates a new Tracker.
54-
func newTracker(quotaStatuses []*quotaStatus, nodeCache *nodeCache) *Tracker {
54+
func newTracker(quotaStatuses []*quotaStatus, nodeCache *nodeResourcesCache) *Tracker {
5555
return &Tracker{
5656
quotaStatuses: quotaStatuses,
5757
nodeCache: nodeCache,

cluster-autoscaler/resourcequotas/tracker_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestCheckDelta(t *testing.T) {
4545
quota: &fakeQuota{id: "limiter1", appliesToFn: func(*apiv1.Node) bool { return true }},
4646
limitsLeft: resourceList{"cpu": 10, "memory": 1000, "nodes": 5},
4747
},
48-
}, newNodeCache(&fakeCustomResourcesProcessor{})),
48+
}, newNodeResourcesCache(&fakeCustomResourcesProcessor{})),
4949
node: test.BuildTestNode("n1", 1000, 200),
5050
nodeDelta: 2,
5151
wantResult: &CheckDeltaResult{
@@ -59,7 +59,7 @@ func TestCheckDelta(t *testing.T) {
5959
quota: &fakeQuota{id: "limiter1", appliesToFn: func(*apiv1.Node) bool { return true }},
6060
limitsLeft: resourceList{"cpu": 1, "memory": 1000, "nodes": 5},
6161
},
62-
}, newNodeCache(&fakeCustomResourcesProcessor{})),
62+
}, newNodeResourcesCache(&fakeCustomResourcesProcessor{})),
6363
node: test.BuildTestNode("n1", 1000, 200),
6464
nodeDelta: 2,
6565
wantResult: &CheckDeltaResult{
@@ -77,7 +77,7 @@ func TestCheckDelta(t *testing.T) {
7777
quota: &fakeQuota{id: "limiter1", appliesToFn: func(*apiv1.Node) bool { return true }},
7878
limitsLeft: resourceList{"cpu": 1, "memory": 300, "nodes": 5},
7979
},
80-
}, newNodeCache(&fakeCustomResourcesProcessor{})),
80+
}, newNodeResourcesCache(&fakeCustomResourcesProcessor{})),
8181
node: test.BuildTestNode("n1", 1000, 200),
8282
nodeDelta: 2,
8383
wantResult: &CheckDeltaResult{
@@ -99,7 +99,7 @@ func TestCheckDelta(t *testing.T) {
9999
quota: &fakeQuota{id: "limiter2", appliesToFn: func(*apiv1.Node) bool { return true }},
100100
limitsLeft: resourceList{"cpu": 10, "memory": 300, "nodes": 5},
101101
},
102-
}, newNodeCache(&fakeCustomResourcesProcessor{})),
102+
}, newNodeResourcesCache(&fakeCustomResourcesProcessor{})),
103103
node: test.BuildTestNode("n1", 1000, 200),
104104
nodeDelta: 2,
105105
wantResult: &CheckDeltaResult{
@@ -122,7 +122,7 @@ func TestCheckDelta(t *testing.T) {
122122
quota: &fakeQuota{id: "limiter2", appliesToFn: func(*apiv1.Node) bool { return false }},
123123
limitsLeft: resourceList{"cpu": 10, "memory": 300, "nodes": 5},
124124
},
125-
}, newNodeCache(&fakeCustomResourcesProcessor{})),
125+
}, newNodeResourcesCache(&fakeCustomResourcesProcessor{})),
126126
node: test.BuildTestNode("n1", 1000, 200),
127127
nodeDelta: 2,
128128
wantResult: &CheckDeltaResult{
@@ -140,7 +140,7 @@ func TestCheckDelta(t *testing.T) {
140140
quota: &fakeQuota{id: "limiter1", appliesToFn: func(*apiv1.Node) bool { return false }},
141141
limitsLeft: resourceList{"cpu": 1, "memory": 100, "nodes": 1},
142142
},
143-
}, newNodeCache(&fakeCustomResourcesProcessor{})),
143+
}, newNodeResourcesCache(&fakeCustomResourcesProcessor{})),
144144
node: test.BuildTestNode("n1", 1000, 200),
145145
nodeDelta: 2,
146146
wantResult: &CheckDeltaResult{
@@ -154,7 +154,7 @@ func TestCheckDelta(t *testing.T) {
154154
quota: &fakeQuota{id: "limiter1", appliesToFn: func(*apiv1.Node) bool { return true }},
155155
limitsLeft: resourceList{"cpu": 4, "memory": 32 * units.GiB, "gpu": 2},
156156
},
157-
}, newNodeCache(&fakeCustomResourcesProcessor{})),
157+
}, newNodeResourcesCache(&fakeCustomResourcesProcessor{})),
158158
node: test.BuildTestNode("n1", 1000, 2000),
159159
nodeDelta: 2,
160160
wantResult: &CheckDeltaResult{
@@ -168,7 +168,7 @@ func TestCheckDelta(t *testing.T) {
168168
quota: &fakeQuota{id: "limiter1", appliesToFn: func(*apiv1.Node) bool { return true }},
169169
limitsLeft: resourceList{"cpu": 4, "memory": 32 * units.GiB},
170170
},
171-
}, newNodeCache(&fakeCustomResourcesProcessor{NodeResourceTargets: func(node *apiv1.Node) []customresources.CustomResourceTarget {
171+
}, newNodeResourcesCache(&fakeCustomResourcesProcessor{NodeResourceTargets: func(node *apiv1.Node) []customresources.CustomResourceTarget {
172172
return []customresources.CustomResourceTarget{
173173
{
174174
ResourceType: "gpu",
@@ -219,7 +219,7 @@ func TestApplyDelta(t *testing.T) {
219219
quota: &fakeQuota{id: "limiter1", appliesToFn: func(*apiv1.Node) bool { return true }},
220220
limitsLeft: resourceList{"cpu": 10, "memory": 1000, "nodes": 5},
221221
},
222-
}, newNodeCache(&fakeCustomResourcesProcessor{})),
222+
}, newNodeResourcesCache(&fakeCustomResourcesProcessor{})),
223223
node: test.BuildTestNode("n1", 1000, 200),
224224
nodeDelta: 2,
225225
wantResult: &CheckDeltaResult{
@@ -236,7 +236,7 @@ func TestApplyDelta(t *testing.T) {
236236
quota: &fakeQuota{id: "limiter1", appliesToFn: func(*apiv1.Node) bool { return true }},
237237
limitsLeft: resourceList{"cpu": 3, "memory": 1000, "nodes": 5},
238238
},
239-
}, newNodeCache(&fakeCustomResourcesProcessor{})),
239+
}, newNodeResourcesCache(&fakeCustomResourcesProcessor{})),
240240
node: test.BuildTestNode("n1", 2000, 200),
241241
nodeDelta: 2,
242242
wantResult: &CheckDeltaResult{
@@ -256,7 +256,7 @@ func TestApplyDelta(t *testing.T) {
256256
quota: &fakeQuota{id: "limiter1", appliesToFn: func(*apiv1.Node) bool { return true }},
257257
limitsLeft: resourceList{"cpu": 1, "memory": 100, "nodes": 5},
258258
},
259-
}, newNodeCache(&fakeCustomResourcesProcessor{})),
259+
}, newNodeResourcesCache(&fakeCustomResourcesProcessor{})),
260260
node: test.BuildTestNode("n1", 2000, 200),
261261
nodeDelta: 1,
262262
wantResult: &CheckDeltaResult{
@@ -276,7 +276,7 @@ func TestApplyDelta(t *testing.T) {
276276
quota: &fakeQuota{id: "limiter1", appliesToFn: func(*apiv1.Node) bool { return true }},
277277
limitsLeft: resourceList{"cpu": 2, "memory": 500, "nodes": 10},
278278
},
279-
}, newNodeCache(&fakeCustomResourcesProcessor{})),
279+
}, newNodeResourcesCache(&fakeCustomResourcesProcessor{})),
280280
node: test.BuildTestNode("n1", 1000, 200),
281281
nodeDelta: 2,
282282
wantResult: &CheckDeltaResult{

cluster-autoscaler/resourcequotas/usage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ type NodeFilter interface {
3131

3232
type usageCalculator struct {
3333
nodeFilter NodeFilter
34-
nodeCache *nodeCache
34+
nodeCache *nodeResourcesCache
3535
}
3636

37-
func newUsageCalculator(nodeFilter NodeFilter, nodeCache *nodeCache) *usageCalculator {
37+
func newUsageCalculator(nodeFilter NodeFilter, nodeCache *nodeResourcesCache) *usageCalculator {
3838
return &usageCalculator{
3939
nodeFilter: nodeFilter,
4040
nodeCache: nodeCache,

cluster-autoscaler/resourcequotas/usage_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func TestCalculateUsages(t *testing.T) {
198198
if tc.nodeFilter != nil {
199199
nf = &fakeNodeFilter{NodeFilterFn: tc.nodeFilter}
200200
}
201-
calculator := newUsageCalculator(nf, newNodeCache(crp))
201+
calculator := newUsageCalculator(nf, newNodeResourcesCache(crp))
202202
usages, err := calculator.calculateUsages(ctx, tc.nodes, tc.quotas)
203203
if err != nil {
204204
t.Errorf("unexpected error: %v", err)

0 commit comments

Comments
 (0)