Skip to content

Commit b7706ef

Browse files
authored
Merge pull request kubernetes#133587 from pohly/dra-allocator-race
DRA allocator: fix data race around `claimsToAllocate`
2 parents 17d6c9c + 4ebe560 commit b7706ef

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

staging/src/k8s.io/dynamic-resource-allocation/structured/internal/experimental/allocator_experimental.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,11 @@ var SupportedFeatures = internal.Features{
8686
}
8787

8888
type Allocator struct {
89-
features Features
90-
claimsToAllocate []*resourceapi.ResourceClaim
91-
allocatedState AllocatedState
92-
classLister DeviceClassLister
93-
slices []*resourceapi.ResourceSlice
94-
celCache *cel.Cache
89+
features Features
90+
allocatedState AllocatedState
91+
classLister DeviceClassLister
92+
slices []*resourceapi.ResourceSlice
93+
celCache *cel.Cache
9594
// availableCounters contains the available counters for individual
9695
// ResourceSlices. It acts as a cache that is updated the first time
9796
// the available counters are needed for each ResourceSlice. The information
@@ -139,14 +138,14 @@ func (a *Allocator) Allocate(ctx context.Context, node *v1.Node, claims []*resou
139138
ctx: ctx, // all methods share the same a and thus ctx
140139
logger: klog.FromContext(ctx),
141140
node: node,
141+
claimsToAllocate: claims,
142142
deviceMatchesRequest: make(map[matchKey]bool),
143143
constraints: make([][]constraint, len(claims)),
144144
consumedCounters: make(map[string]counterSets),
145145
requestData: make(map[requestIndices]requestData),
146146
result: make([]internalAllocationResult, len(claims)),
147147
allocatingCapacity: NewConsumedCapacityCollection(),
148148
}
149-
alloc.claimsToAllocate = claims
150149
alloc.logger.V(5).Info("Starting allocation", "numClaims", len(alloc.claimsToAllocate))
151150
defer alloc.logger.V(5).Info("Done with allocation", "success", len(finalResult) == len(alloc.claimsToAllocate), "err", finalErr)
152151

@@ -577,6 +576,7 @@ type allocator struct {
577576
ctx context.Context
578577
logger klog.Logger
579578
node *v1.Node
579+
claimsToAllocate []*resourceapi.ResourceClaim
580580
pools []*Pool
581581
deviceMatchesRequest map[matchKey]bool
582582
constraints [][]constraint // one list of constraints per claim

staging/src/k8s.io/dynamic-resource-allocation/structured/internal/incubating/allocator_incubating.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ var SupportedFeatures = internal.Features{
5858

5959
type Allocator struct {
6060
features Features
61-
claimsToAllocate []*resourceapi.ResourceClaim
6261
allocatedDevices sets.Set[DeviceID]
6362
classLister DeviceClassLister
6463
slices []*resourceapi.ResourceSlice
@@ -110,13 +109,13 @@ func (a *Allocator) Allocate(ctx context.Context, node *v1.Node, claims []*resou
110109
ctx: ctx, // all methods share the same a and thus ctx
111110
logger: klog.FromContext(ctx),
112111
node: node,
112+
claimsToAllocate: claims,
113113
deviceMatchesRequest: make(map[matchKey]bool),
114114
constraints: make([][]constraint, len(claims)),
115115
consumedCounters: make(map[string]counterSets),
116116
requestData: make(map[requestIndices]requestData),
117117
result: make([]internalAllocationResult, len(claims)),
118118
}
119-
alloc.claimsToAllocate = claims
120119
alloc.logger.V(5).Info("Starting allocation", "numClaims", len(alloc.claimsToAllocate))
121120
defer alloc.logger.V(5).Info("Done with allocation", "success", len(finalResult) == len(alloc.claimsToAllocate), "err", finalErr)
122121

@@ -471,6 +470,7 @@ type allocator struct {
471470
ctx context.Context
472471
logger klog.Logger
473472
node *v1.Node
473+
claimsToAllocate []*resourceapi.ResourceClaim
474474
pools []*Pool
475475
deviceMatchesRequest map[matchKey]bool
476476
constraints [][]constraint // one list of constraints per claim

staging/src/k8s.io/dynamic-resource-allocation/structured/internal/stable/allocator_stable.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ var SupportedFeatures = internal.Features{}
5656

5757
type Allocator struct {
5858
features Features
59-
claimsToAllocate []*resourceapi.ResourceClaim
6059
allocatedDevices sets.Set[DeviceID]
6160
classLister DeviceClassLister
6261
slices []*resourceapi.ResourceSlice
@@ -101,13 +100,13 @@ func (a *Allocator) Allocate(ctx context.Context, node *v1.Node, claims []*resou
101100
ctx: ctx, // all methods share the same a and thus ctx
102101
logger: klog.FromContext(ctx),
103102
node: node,
103+
claimsToAllocate: claims,
104104
deviceMatchesRequest: make(map[matchKey]bool),
105105
constraints: make([][]constraint, len(claims)),
106106
consumedCounters: make(map[string]counterSets),
107107
requestData: make(map[requestIndices]requestData),
108108
result: make([]internalAllocationResult, len(claims)),
109109
}
110-
alloc.claimsToAllocate = claims
111110
alloc.logger.V(5).Info("Starting allocation", "numClaims", len(alloc.claimsToAllocate))
112111
defer alloc.logger.V(5).Info("Done with allocation", "success", len(finalResult) == len(alloc.claimsToAllocate), "err", finalErr)
113112

@@ -453,6 +452,7 @@ type allocator struct {
453452
ctx context.Context
454453
logger klog.Logger
455454
node *v1.Node
455+
claimsToAllocate []*resourceapi.ResourceClaim
456456
pools []*Pool
457457
deviceMatchesRequest map[matchKey]bool
458458
constraints [][]constraint // one list of constraints per claim

0 commit comments

Comments
 (0)