ResourceClaim.Status.Devices.Data as pointer

Signed-off-by: Lionel Jouin <lionel.jouin@est.tech>
This commit is contained in:
Lionel Jouin 2024-12-14 18:59:59 +01:00
parent b7d6e78726
commit 11d68ecc4e
8 changed files with 16 additions and 16 deletions

View File

@ -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"}`)}
},
}
}

View File

@ -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.
//

View File

@ -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

View File

@ -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},

View File

@ -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.
//

View File

@ -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.
//

View File

@ -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"},

View File

@ -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{