Skip to content

Commit d1f0d24

Browse files
committed
DRA API: check "AdminAccess in use" only once
This is simpler and an opportunity to explain the concept.
1 parent 4419568 commit d1f0d24

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

pkg/registry/resource/resourceclaim/strategy.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,25 @@ func dropDisabledDRAAdminAccessFields(newClaim, oldClaim *resource.ResourceClaim
182182
// No need to drop anything.
183183
return
184184
}
185+
if draAdminAccessFeatureInUse(oldClaim) {
186+
// If anything was set in the past, then fields must not get
187+
// dropped on potentially unrelated updates and, for example,
188+
// adding a status with AdminAccess=true is allowed. The
189+
// scheduler typically doesn't do that (it also checks the
190+
// feature gate and refuses to schedule), but the apiserver
191+
// would allow it.
192+
return
193+
}
185194

186195
for i := range newClaim.Spec.Devices.Requests {
187-
if newClaim.Spec.Devices.Requests[i].AdminAccess != nil && !draAdminAccessFeatureInUse(oldClaim) {
188-
newClaim.Spec.Devices.Requests[i].AdminAccess = nil
189-
}
196+
newClaim.Spec.Devices.Requests[i].AdminAccess = nil
190197
}
191198

192199
if newClaim.Status.Allocation == nil {
193200
return
194201
}
195202
for i := range newClaim.Status.Allocation.Devices.Results {
196-
if newClaim.Status.Allocation.Devices.Results[i].AdminAccess != nil && !draAdminAccessFeatureInUse(oldClaim) {
197-
newClaim.Status.Allocation.Devices.Results[i].AdminAccess = nil
198-
}
203+
newClaim.Status.Allocation.Devices.Results[i].AdminAccess = nil
199204
}
200205
}
201206

pkg/registry/resource/resourceclaimtemplate/strategy.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,14 @@ func dropDisabledDRAAdminAccessFields(newClaimTemplate, oldClaimTemplate *resour
108108
// No need to drop anything.
109109
return
110110
}
111+
if draAdminAccessFeatureInUse(oldClaimTemplate) {
112+
// If anything was set in the past, then fields must not get
113+
// dropped on potentially unrelated updates.
114+
return
115+
}
111116

112117
for i := range newClaimTemplate.Spec.Spec.Devices.Requests {
113-
if newClaimTemplate.Spec.Spec.Devices.Requests[i].AdminAccess != nil && !draAdminAccessFeatureInUse(oldClaimTemplate) {
114-
newClaimTemplate.Spec.Spec.Devices.Requests[i].AdminAccess = nil
115-
}
118+
newClaimTemplate.Spec.Spec.Devices.Requests[i].AdminAccess = nil
116119
}
117120
}
118121

0 commit comments

Comments
 (0)