Skip to content

Commit 4419568

Browse files
committed
DRA: treat AdminAccess as a new feature gated field
Using the "normal" logic for a feature gated field simplifies the implementation of the feature gate. There is one (entirely theoretic!) problem with updating from 1.31: if a claim was allocated in 1.31 with admin access, the status field was not set because it didn't exist yet. If a driver now follows the current definition of "unset = off", then it will not grant admin access even though it should. This is theoretic because drivers are starting to support admin access with 1.32, so there shouldn't be any claim where this problem could occur.
1 parent 9a7e4cc commit 4419568

File tree

24 files changed

+247
-245
lines changed

24 files changed

+247
-245
lines changed

api/openapi-spec/swagger.json

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

api/openapi-spec/v3/apis__resource.k8s.io__v1alpha3_openapi.json

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

pkg/apis/resource/types.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,12 @@ type DeviceRequest struct {
443443
// any resource allocations.
444444
//
445445
// This is an alpha field and requires enabling the DRAAdminAccess
446-
// feature gate.
446+
// feature gate. Admin access is disabled if this field is unset or
447+
// set to false, otherwise it is enabled.
447448
//
448449
// +optional
449-
// +default=false
450450
// +featureGate=DRAAdminAccess
451-
AdminAccess bool
451+
AdminAccess *bool
452452
}
453453

454454
const (
@@ -787,19 +787,15 @@ type DeviceRequestAllocationResult struct {
787787
// +required
788788
Device string
789789

790-
// AdminAccess is a copy of the AdminAccess value in the
791-
// request which caused this device to be allocated.
792-
//
793-
// New allocations are required to have this set when the DRAAdminAccess
794-
// feature gate is enabled. Old allocations made
795-
// by Kubernetes 1.31 do not have it yet. Clients which want to
796-
// support Kubernetes 1.31 need to look up the request and retrieve
797-
// the value from there if this field is not set.
790+
// AdminAccess indicates that this device was allocated for
791+
// administrative access. See the corresponding request field
792+
// for a definition of mode.
798793
//
799794
// This is an alpha field and requires enabling the DRAAdminAccess
800-
// feature gate.
795+
// feature gate. Admin access is disabled if this field is unset or
796+
// set to false, otherwise it is enabled.
801797
//
802-
// +required
798+
// +optional
803799
// +featureGate=DRAAdminAccess
804800
AdminAccess *bool
805801
}

pkg/apis/resource/v1alpha3/zz_generated.conversion.go

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

pkg/apis/resource/validation/validation.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ import (
3232
"k8s.io/apimachinery/pkg/util/validation/field"
3333
"k8s.io/apiserver/pkg/cel"
3434
"k8s.io/apiserver/pkg/cel/environment"
35-
utilfeature "k8s.io/apiserver/pkg/util/feature"
3635
dracel "k8s.io/dynamic-resource-allocation/cel"
3736
corevalidation "k8s.io/kubernetes/pkg/apis/core/validation"
3837
"k8s.io/kubernetes/pkg/apis/resource"
39-
"k8s.io/kubernetes/pkg/features"
4038
)
4139

4240
var (
@@ -345,9 +343,6 @@ func validateDeviceRequestAllocationResult(result resource.DeviceRequestAllocati
345343
allErrs = append(allErrs, validateDriverName(result.Driver, fldPath.Child("driver"))...)
346344
allErrs = append(allErrs, validatePoolName(result.Pool, fldPath.Child("pool"))...)
347345
allErrs = append(allErrs, validateDeviceName(result.Device, fldPath.Child("device"))...)
348-
if result.AdminAccess == nil && utilfeature.DefaultFeatureGate.Enabled(features.DRAAdminAccess) {
349-
allErrs = append(allErrs, field.Required(fldPath.Child("adminAccess"), ""))
350-
}
351346
return allErrs
352347
}
353348

pkg/apis/resource/validation/validation_resourceclaim_test.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -478,27 +478,6 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
478478
return claim
479479
},
480480
},
481-
"invalid-add-allocation-missing-admin-access": {
482-
adminAccess: true,
483-
wantFailures: field.ErrorList{
484-
field.Required(field.NewPath("status", "allocation", "devices", "results").Index(0).Child("adminAccess"), ""),
485-
},
486-
oldClaim: validClaim,
487-
update: func(claim *resource.ResourceClaim) *resource.ResourceClaim {
488-
claim.Status.Allocation = &resource.AllocationResult{
489-
Devices: resource.DeviceAllocationResult{
490-
Results: []resource.DeviceRequestAllocationResult{{
491-
Request: goodName,
492-
Driver: goodName,
493-
Pool: goodName,
494-
Device: goodName,
495-
AdminAccess: nil, // Intentionally not set.
496-
}},
497-
},
498-
}
499-
return claim
500-
},
501-
},
502481
"okay-add-allocation-missing-admin-access": {
503482
adminAccess: false,
504483
oldClaim: validClaim,

pkg/apis/resource/zz_generated.deepcopy.go

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

pkg/controller/resourceclaim/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ func (ec *Controller) handleClaim(ctx context.Context, pod *v1.Pod, podClaim v1.
681681

682682
func needsAdminAccess(claimTemplate *resourceapi.ResourceClaimTemplate) bool {
683683
for _, request := range claimTemplate.Spec.Spec.Devices.Requests {
684-
if request.AdminAccess {
684+
if ptr.Deref(request.AdminAccess, false) {
685685
return true
686686
}
687687
}

pkg/generated/openapi/zz_generated.openapi.go

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

pkg/quota/v1/evaluator/core/resource_claims_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"k8s.io/apimachinery/pkg/api/resource"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
api "k8s.io/kubernetes/pkg/apis/resource"
28+
"k8s.io/utils/ptr"
2829
)
2930

3031
func testResourceClaim(name string, namespace string, spec api.ResourceClaimSpec) *api.ResourceClaim {
@@ -101,7 +102,7 @@ func TestResourceClaimEvaluatorUsage(t *testing.T) {
101102
claim: func() *api.ResourceClaim {
102103
claim := validClaim.DeepCopy()
103104
// Admins are *not* exempt from quota.
104-
claim.Spec.Devices.Requests[0].AdminAccess = true
105+
claim.Spec.Devices.Requests[0].AdminAccess = ptr.To(true)
105106
return claim
106107
}(),
107108
usage: corev1.ResourceList{

0 commit comments

Comments
 (0)