Skip to content

Commit 59acb65

Browse files
committed
DRA: remove immediate allocation
As agreed in kubernetes/enhancements#4709, immediate allocation is one of those features which can be removed because it makes no sense for structured parameters and the justification for classic DRA is weak.
1 parent d49a23d commit 59acb65

File tree

50 files changed

+1125
-1190
lines changed

Some content is hidden

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

50 files changed

+1125
-1190
lines changed

api/openapi-spec/swagger.json

-4
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__v1alpha2_openapi.json

-4
Original file line numberDiff line numberDiff line change
@@ -762,10 +762,6 @@
762762
"io.k8s.api.resource.v1alpha2.ResourceClaimSpec": {
763763
"description": "ResourceClaimSpec defines how a resource is to be allocated.",
764764
"properties": {
765-
"allocationMode": {
766-
"description": "Allocation can start immediately or when a Pod wants to use the resource. \"WaitForFirstConsumer\" is the default.",
767-
"type": "string"
768-
},
769765
"parametersRef": {
770766
"allOf": [
771767
{

pkg/api/testing/defaulting_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ func TestDefaulting(t *testing.T) {
135135
{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBindingList"}: {},
136136
{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "RoleBinding"}: {},
137137
{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "RoleBindingList"}: {},
138-
{Group: "resource.k8s.io", Version: "v1alpha2", Kind: "ResourceClaim"}: {},
139-
{Group: "resource.k8s.io", Version: "v1alpha2", Kind: "ResourceClaimList"}: {},
140-
{Group: "resource.k8s.io", Version: "v1alpha2", Kind: "ResourceClaimTemplate"}: {},
141-
{Group: "resource.k8s.io", Version: "v1alpha2", Kind: "ResourceClaimTemplateList"}: {},
142138
{Group: "admissionregistration.k8s.io", Version: "v1alpha1", Kind: "ValidatingAdmissionPolicy"}: {},
143139
{Group: "admissionregistration.k8s.io", Version: "v1alpha1", Kind: "ValidatingAdmissionPolicyList"}: {},
144140
{Group: "admissionregistration.k8s.io", Version: "v1alpha1", Kind: "ValidatingAdmissionPolicyBinding"}: {},

pkg/apis/resource/fuzzer/fuzzer.go

+1-15
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,10 @@ limitations under the License.
1717
package fuzzer
1818

1919
import (
20-
fuzz "github.com/google/gofuzz"
21-
2220
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
23-
"k8s.io/kubernetes/pkg/apis/resource"
2421
)
2522

2623
// Funcs contains the fuzzer functions for the resource group.
2724
var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
28-
return []interface{}{
29-
func(obj *resource.ResourceClaimSpec, c fuzz.Continue) {
30-
c.FuzzNoCustom(obj) // fuzz self without calling this function again
31-
32-
// Custom fuzzing for allocation mode: pick one valid mode randomly.
33-
modes := []resource.AllocationMode{
34-
resource.AllocationModeImmediate,
35-
resource.AllocationModeWaitForFirstConsumer,
36-
}
37-
obj.AllocationMode = modes[c.Rand.Intn(len(modes))]
38-
},
39-
}
25+
return nil
4026
}

pkg/apis/resource/types.go

+1-27
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,7 @@ type ResourceClaimSpec struct {
6262
// The object must be in the same namespace as the ResourceClaim.
6363
// +optional
6464
ParametersRef *ResourceClaimParametersReference
65-
66-
// Allocation can start immediately or when a Pod wants to use the
67-
// resource. "WaitForFirstConsumer" is the default.
68-
// +optional
69-
AllocationMode AllocationMode
70-
}
71-
72-
// AllocationMode describes whether a ResourceClaim gets allocated immediately
73-
// when it gets created (AllocationModeImmediate) or whether allocation is
74-
// delayed until it is needed for a Pod
75-
// (AllocationModeWaitForFirstConsumer). Other modes might get added in the
76-
// future.
77-
type AllocationMode string
78-
79-
const (
80-
// When a ResourceClaim has AllocationModeWaitForFirstConsumer, allocation is
81-
// delayed until a Pod gets scheduled that needs the ResourceClaim. The
82-
// scheduler will consider all resource requirements of that Pod and
83-
// trigger allocation for a node that fits the Pod.
84-
AllocationModeWaitForFirstConsumer AllocationMode = "WaitForFirstConsumer"
85-
86-
// When a ResourceClaim has AllocationModeImmediate, allocation starts
87-
// as soon as the ResourceClaim gets created. This is done without
88-
// considering the needs of Pods that will use the ResourceClaim
89-
// because those Pods are not known yet.
90-
AllocationModeImmediate AllocationMode = "Immediate"
91-
)
65+
}
9266

9367
// ResourceClaimStatus tracks whether the resource has been allocated and what
9468
// the resulting attributes are.

pkg/apis/resource/v1alpha2/defaults.go

-7
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,9 @@ limitations under the License.
1717
package v1alpha2
1818

1919
import (
20-
"k8s.io/api/resource/v1alpha2"
2120
"k8s.io/apimachinery/pkg/runtime"
2221
)
2322

2423
func addDefaultingFuncs(scheme *runtime.Scheme) error {
2524
return RegisterDefaults(scheme)
2625
}
27-
28-
func SetDefaults_ResourceClaimSpec(obj *v1alpha2.ResourceClaimSpec) {
29-
if obj.AllocationMode == "" {
30-
obj.AllocationMode = v1alpha2.AllocationModeWaitForFirstConsumer
31-
}
32-
}

pkg/apis/resource/v1alpha2/defaults_test.go

-75
This file was deleted.

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

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/resource/v1alpha2/zz_generated.defaults.go

-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/resource/validation/validation.go

-5
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@ func validateResourceClaimSpec(spec *resource.ResourceClaimSpec, fldPath *field.
4646
allErrs = append(allErrs, field.Invalid(fldPath.Child("resourceClassName"), spec.ResourceClassName, msg))
4747
}
4848
allErrs = append(allErrs, validateResourceClaimParametersRef(spec.ParametersRef, fldPath.Child("parametersRef"))...)
49-
if !supportedAllocationModes.Has(string(spec.AllocationMode)) {
50-
allErrs = append(allErrs, field.NotSupported(fldPath.Child("allocationMode"), spec.AllocationMode, supportedAllocationModes.List()))
51-
}
5249
return allErrs
5350
}
5451

55-
var supportedAllocationModes = sets.NewString(string(resource.AllocationModeImmediate), string(resource.AllocationModeWaitForFirstConsumer))
56-
5752
// It would have been nice to use Go generics to reuse the same validation
5853
// function for Kind and Name in both types, but generics cannot be used to
5954
// access common fields in structs.

pkg/apis/resource/validation/validation_resourceclaim_test.go

-25
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,11 @@ func testClaim(name, namespace string, spec resource.ResourceClaimSpec) *resourc
4242
}
4343

4444
func TestValidateClaim(t *testing.T) {
45-
validMode := resource.AllocationModeImmediate
46-
invalidMode := resource.AllocationMode("invalid")
4745
goodName := "foo"
4846
badName := "!@#$%^"
4947
goodNS := "ns"
5048
goodClaimSpec := resource.ResourceClaimSpec{
5149
ResourceClassName: goodName,
52-
AllocationMode: validMode,
5350
}
5451
now := metav1.Now()
5552
badValue := "spaces not allowed"
@@ -200,14 +197,6 @@ func TestValidateClaim(t *testing.T) {
200197
return claim
201198
}(),
202199
},
203-
"bad-mode": {
204-
wantFailures: field.ErrorList{field.NotSupported(field.NewPath("spec", "allocationMode"), invalidMode, supportedAllocationModes.List())},
205-
claim: func() *resource.ResourceClaim {
206-
claim := testClaim(goodName, goodNS, goodClaimSpec)
207-
claim.Spec.AllocationMode = invalidMode
208-
return claim
209-
}(),
210-
},
211200
"good-parameters": {
212201
claim: func() *resource.ResourceClaim {
213202
claim := testClaim(goodName, goodNS, goodClaimSpec)
@@ -279,7 +268,6 @@ func TestValidateClaimUpdate(t *testing.T) {
279268
}
280269
validClaim := testClaim("foo", "ns", resource.ResourceClaimSpec{
281270
ResourceClassName: name,
282-
AllocationMode: resource.AllocationModeImmediate,
283271
ParametersRef: parameters,
284272
})
285273

@@ -316,18 +304,6 @@ func TestValidateClaimUpdate(t *testing.T) {
316304
return claim
317305
},
318306
},
319-
"invalid-update-mode": {
320-
wantFailures: field.ErrorList{field.Invalid(field.NewPath("spec"), func() resource.ResourceClaimSpec {
321-
spec := validClaim.Spec.DeepCopy()
322-
spec.AllocationMode = resource.AllocationModeWaitForFirstConsumer
323-
return *spec
324-
}(), "field is immutable")},
325-
oldClaim: validClaim,
326-
update: func(claim *resource.ResourceClaim) *resource.ResourceClaim {
327-
claim.Spec.AllocationMode = resource.AllocationModeWaitForFirstConsumer
328-
return claim
329-
},
330-
},
331307
}
332308

333309
for name, scenario := range scenarios {
@@ -343,7 +319,6 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
343319
invalidName := "!@#$%^"
344320
validClaim := testClaim("foo", "ns", resource.ResourceClaimSpec{
345321
ResourceClassName: "valid",
346-
AllocationMode: resource.AllocationModeImmediate,
347322
})
348323

349324
validAllocatedClaim := validClaim.DeepCopy()

pkg/apis/resource/validation/validation_resourceclaimtemplate_test.go

-24
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,11 @@ func testClaimTemplate(name, namespace string, spec resource.ResourceClaimSpec)
4040
}
4141

4242
func TestValidateClaimTemplate(t *testing.T) {
43-
validMode := resource.AllocationModeImmediate
44-
invalidMode := resource.AllocationMode("invalid")
4543
goodName := "foo"
4644
badName := "!@#$%^"
4745
goodNS := "ns"
4846
goodClaimSpec := resource.ResourceClaimSpec{
4947
ResourceClassName: goodName,
50-
AllocationMode: validMode,
5148
}
5249
now := metav1.Now()
5350
badValue := "spaces not allowed"
@@ -198,14 +195,6 @@ func TestValidateClaimTemplate(t *testing.T) {
198195
return template
199196
}(),
200197
},
201-
"bad-mode": {
202-
wantFailures: field.ErrorList{field.NotSupported(field.NewPath("spec", "spec", "allocationMode"), invalidMode, supportedAllocationModes.List())},
203-
template: func() *resource.ResourceClaimTemplate {
204-
template := testClaimTemplate(goodName, goodNS, goodClaimSpec)
205-
template.Spec.Spec.AllocationMode = invalidMode
206-
return template
207-
}(),
208-
},
209198
"good-parameters": {
210199
template: func() *resource.ResourceClaimTemplate {
211200
template := testClaimTemplate(goodName, goodNS, goodClaimSpec)
@@ -277,7 +266,6 @@ func TestValidateClaimTemplateUpdate(t *testing.T) {
277266
}
278267
validClaimTemplate := testClaimTemplate("foo", "ns", resource.ResourceClaimSpec{
279268
ResourceClassName: name,
280-
AllocationMode: resource.AllocationModeImmediate,
281269
ParametersRef: parameters,
282270
})
283271

@@ -314,18 +302,6 @@ func TestValidateClaimTemplateUpdate(t *testing.T) {
314302
return template
315303
},
316304
},
317-
"invalid-update-mode": {
318-
wantFailures: field.ErrorList{field.Invalid(field.NewPath("spec"), func() resource.ResourceClaimTemplateSpec {
319-
spec := validClaimTemplate.Spec.DeepCopy()
320-
spec.Spec.AllocationMode = resource.AllocationModeWaitForFirstConsumer
321-
return *spec
322-
}(), "field is immutable")},
323-
oldClaimTemplate: validClaimTemplate,
324-
update: func(template *resource.ResourceClaimTemplate) *resource.ResourceClaimTemplate {
325-
template.Spec.Spec.AllocationMode = resource.AllocationModeWaitForFirstConsumer
326-
return template
327-
},
328-
},
329305
}
330306

331307
for name, scenario := range scenarios {

0 commit comments

Comments
 (0)