From 11d68ecc4ebb2a6fc0308a6a5f554b8440ed8697 Mon Sep 17 00:00:00 2001 From: Lionel Jouin Date: Sat, 14 Dec 2024 18:59:59 +0100 Subject: [PATCH] ResourceClaim.Status.Devices.Data as pointer Signed-off-by: Lionel Jouin --- pkg/apis/resource/fuzzer/fuzzer.go | 2 +- pkg/apis/resource/types.go | 2 +- pkg/apis/resource/validation/validation.go | 4 ++-- .../validation/validation_resourceclaim_test.go | 10 +++++----- staging/src/k8s.io/api/resource/v1alpha3/types.go | 2 +- staging/src/k8s.io/api/resource/v1beta1/types.go | 2 +- test/e2e/dra/dra.go | 4 ++-- .../resourceclaim/feature_enable_disable_test.go | 6 +++--- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/apis/resource/fuzzer/fuzzer.go b/pkg/apis/resource/fuzzer/fuzzer.go index 31b64886e00..f9fa97a102a 100644 --- a/pkg/apis/resource/fuzzer/fuzzer.go +++ b/pkg/apis/resource/fuzzer/fuzzer.go @@ -62,7 +62,7 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} { // // This is necessary because randomly generated content // might be valid JSON which changes during re-encoding. - r.Data = runtime.RawExtension{Raw: []byte(`{"apiVersion":"unknown.group/unknown","kind":"Something","someKey":"someValue"}`)} + r.Data = &runtime.RawExtension{Raw: []byte(`{"apiVersion":"unknown.group/unknown","kind":"Something","someKey":"someValue"}`)} }, } } diff --git a/pkg/apis/resource/types.go b/pkg/apis/resource/types.go index ab58317d914..c2c62f14132 100644 --- a/pkg/apis/resource/types.go +++ b/pkg/apis/resource/types.go @@ -1040,7 +1040,7 @@ type AllocatedDeviceStatus struct { // The length of the raw data must be smaller or equal to 10 Ki. // // +optional - Data runtime.RawExtension + Data *runtime.RawExtension // NetworkData contains network-related information specific to the device. // diff --git a/pkg/apis/resource/validation/validation.go b/pkg/apis/resource/validation/validation.go index 9a357c9bc07..deb00e5a742 100644 --- a/pkg/apis/resource/validation/validation.go +++ b/pkg/apis/resource/validation/validation.go @@ -752,8 +752,8 @@ func validateDeviceStatus(device resource.AllocatedDeviceStatus, fldPath *field. allErrs = append(allErrs, field.TooMany(fldPath.Child("conditions"), len(device.Conditions), resource.AllocatedDeviceStatusMaxConditions)) } allErrs = append(allErrs, metav1validation.ValidateConditions(device.Conditions, fldPath.Child("conditions"))...) - if len(device.Data.Raw) > 0 { // Data is an optional field. - allErrs = append(allErrs, validateRawExtension(device.Data, fldPath.Child("data"), false, resource.AllocatedDeviceStatusDataMaxLength)...) + if device.Data != nil && len(device.Data.Raw) > 0 { // Data is an optional field. + allErrs = append(allErrs, validateRawExtension(*device.Data, fldPath.Child("data"), false, resource.AllocatedDeviceStatusDataMaxLength)...) } allErrs = append(allErrs, validateNetworkDeviceData(device.NetworkData, fldPath.Child("networkData"))...) return allErrs diff --git a/pkg/apis/resource/validation/validation_resourceclaim_test.go b/pkg/apis/resource/validation/validation_resourceclaim_test.go index 78d30c5ac00..45a32a9d2d6 100644 --- a/pkg/apis/resource/validation/validation_resourceclaim_test.go +++ b/pkg/apis/resource/validation/validation_resourceclaim_test.go @@ -1003,7 +1003,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) { {Type: "test-6", Status: metav1.ConditionTrue, Reason: "test_reason", LastTransitionTime: metav1.Now(), ObservedGeneration: 0}, {Type: "test-7", Status: metav1.ConditionTrue, Reason: "test_reason", LastTransitionTime: metav1.Now(), ObservedGeneration: 0}, }, - Data: runtime.RawExtension{ + Data: &runtime.RawExtension{ Raw: []byte(`{"kind": "foo", "apiVersion": "dra.example.com/v1"}`), }, NetworkData: &resource.NetworkDeviceData{ @@ -1090,7 +1090,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) { Driver: goodName, Pool: goodName, Device: goodName, - Data: runtime.RawExtension{ + Data: &runtime.RawExtension{ Raw: []byte(`foo`), }, }, @@ -1112,7 +1112,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) { Driver: goodName, Pool: goodName, Device: goodName, - Data: runtime.RawExtension{Raw: []byte(`{"str": "` + strings.Repeat("x", resource.AllocatedDeviceStatusDataMaxLength-9-2+1 /* too large by one */) + `"}`)}, + Data: &runtime.RawExtension{Raw: []byte(`{"str": "` + strings.Repeat("x", resource.AllocatedDeviceStatusDataMaxLength-9-2+1 /* too large by one */) + `"}`)}, Conditions: []metav1.Condition{ {Type: "test-0", Status: metav1.ConditionTrue, Reason: "test_reason", LastTransitionTime: metav1.Now(), ObservedGeneration: 0}, {Type: "test-1", Status: metav1.ConditionTrue, Reason: "test_reason", LastTransitionTime: metav1.Now(), ObservedGeneration: 0}, @@ -1219,7 +1219,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) { Driver: goodName, Pool: goodName, Device: goodName, - Data: runtime.RawExtension{ + Data: &runtime.RawExtension{ Raw: []byte(`foo`), }, }, @@ -1241,7 +1241,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) { Driver: goodName, Pool: goodName, Device: goodName, - Data: runtime.RawExtension{Raw: []byte(`{"str": "` + strings.Repeat("x", resource.AllocatedDeviceStatusDataMaxLength-9-2+1 /* too large by one */) + `"}`)}, + Data: &runtime.RawExtension{Raw: []byte(`{"str": "` + strings.Repeat("x", resource.AllocatedDeviceStatusDataMaxLength-9-2+1 /* too large by one */) + `"}`)}, Conditions: []metav1.Condition{ {Type: "test-0", Status: metav1.ConditionTrue, Reason: "test_reason", LastTransitionTime: metav1.Now(), ObservedGeneration: 0}, {Type: "test-1", Status: metav1.ConditionTrue, Reason: "test_reason", LastTransitionTime: metav1.Now(), ObservedGeneration: 0}, diff --git a/staging/src/k8s.io/api/resource/v1alpha3/types.go b/staging/src/k8s.io/api/resource/v1alpha3/types.go index b023d792c1a..9e47bf061be 100644 --- a/staging/src/k8s.io/api/resource/v1alpha3/types.go +++ b/staging/src/k8s.io/api/resource/v1alpha3/types.go @@ -1051,7 +1051,7 @@ type AllocatedDeviceStatus struct { // The length of the raw data must be smaller or equal to 10 Ki. // // +optional - Data runtime.RawExtension `json:"data,omitempty" protobuf:"bytes,5,opt,name=data"` + Data *runtime.RawExtension `json:"data,omitempty" protobuf:"bytes,5,opt,name=data"` // NetworkData contains network-related information specific to the device. // diff --git a/staging/src/k8s.io/api/resource/v1beta1/types.go b/staging/src/k8s.io/api/resource/v1beta1/types.go index d5a238f90f1..71c0cb87adc 100644 --- a/staging/src/k8s.io/api/resource/v1beta1/types.go +++ b/staging/src/k8s.io/api/resource/v1beta1/types.go @@ -1054,7 +1054,7 @@ type AllocatedDeviceStatus struct { // The length of the raw data must be smaller or equal to 10 Ki. // // +optional - Data runtime.RawExtension `json:"data,omitempty" protobuf:"bytes,5,opt,name=data"` + Data *runtime.RawExtension `json:"data,omitempty" protobuf:"bytes,5,opt,name=data"` // NetworkData contains network-related information specific to the device. // diff --git a/test/e2e/dra/dra.go b/test/e2e/dra/dra.go index d8296d85113..7164936f80d 100644 --- a/test/e2e/dra/dra.go +++ b/test/e2e/dra/dra.go @@ -438,7 +438,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation, Pool: allocatedResourceClaim.Status.Allocation.Devices.Results[0].Pool, Device: allocatedResourceClaim.Status.Allocation.Devices.Results[0].Device, Conditions: []metav1.Condition{{Type: "a", Status: "True", Message: "c", Reason: "d", LastTransitionTime: metav1.NewTime(time.Now().Truncate(time.Second))}}, - Data: runtime.RawExtension{Raw: []byte(`{"foo":"bar"}`)}, + Data: &runtime.RawExtension{Raw: []byte(`{"foo":"bar"}`)}, NetworkData: &resourceapi.NetworkDeviceData{ InterfaceName: "inf1", IPs: []string{"10.9.8.0/24", "2001:db8::/64"}, @@ -457,7 +457,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation, Pool: allocatedResourceClaim.Status.Allocation.Devices.Results[0].Pool, Device: allocatedResourceClaim.Status.Allocation.Devices.Results[0].Device, Conditions: []metav1.Condition{{Type: "e", Status: "True", Message: "g", Reason: "h", LastTransitionTime: metav1.NewTime(time.Now().Truncate(time.Second))}}, - Data: runtime.RawExtension{Raw: []byte(`{"bar":"foo"}`)}, + Data: &runtime.RawExtension{Raw: []byte(`{"bar":"foo"}`)}, NetworkData: &resourceapi.NetworkDeviceData{ InterfaceName: "inf2", IPs: []string{"10.9.8.1/24", "2001:db8::1/64"}, diff --git a/test/integration/resourceclaim/feature_enable_disable_test.go b/test/integration/resourceclaim/feature_enable_disable_test.go index 7921190e604..67562dcbe6c 100644 --- a/test/integration/resourceclaim/feature_enable_disable_test.go +++ b/test/integration/resourceclaim/feature_enable_disable_test.go @@ -81,7 +81,7 @@ func TestEnableDisableDRAResourceClaimDeviceStatus(t *testing.T) { Driver: "foo", Pool: "foo", Device: "foo", - Data: runtime.RawExtension{ + Data: &runtime.RawExtension{ Raw: []byte(`{"kind": "foo", "apiVersion": "dra.example.com/v1"}`), }, NetworkData: &v1beta1.NetworkDeviceData{ @@ -153,7 +153,7 @@ func TestEnableDisableDRAResourceClaimDeviceStatus(t *testing.T) { Driver: "bar", Pool: "bar", Device: "bar", - Data: runtime.RawExtension{ + Data: &runtime.RawExtension{ Raw: []byte(`{"kind": "foo", "apiVersion": "dra.example.com/v1"}`), }, NetworkData: &v1beta1.NetworkDeviceData{ @@ -189,7 +189,7 @@ func TestEnableDisableDRAResourceClaimDeviceStatus(t *testing.T) { Driver: "bar", Pool: "bar", Device: "bar", - Data: runtime.RawExtension{ + Data: &runtime.RawExtension{ Raw: []byte(`{"kind": "foo", "apiVersion": "dra.example.com/v1"}`), }, NetworkData: &v1beta1.NetworkDeviceData{