Skip to content

Commit 11d68ec

Browse files
committed
ResourceClaim.Status.Devices.Data as pointer
Signed-off-by: Lionel Jouin <[email protected]>
1 parent b7d6e78 commit 11d68ec

File tree

8 files changed

+16
-16
lines changed

8 files changed

+16
-16
lines changed

pkg/apis/resource/fuzzer/fuzzer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
6262
//
6363
// This is necessary because randomly generated content
6464
// might be valid JSON which changes during re-encoding.
65-
r.Data = runtime.RawExtension{Raw: []byte(`{"apiVersion":"unknown.group/unknown","kind":"Something","someKey":"someValue"}`)}
65+
r.Data = &runtime.RawExtension{Raw: []byte(`{"apiVersion":"unknown.group/unknown","kind":"Something","someKey":"someValue"}`)}
6666
},
6767
}
6868
}

pkg/apis/resource/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ type AllocatedDeviceStatus struct {
10401040
// The length of the raw data must be smaller or equal to 10 Ki.
10411041
//
10421042
// +optional
1043-
Data runtime.RawExtension
1043+
Data *runtime.RawExtension
10441044

10451045
// NetworkData contains network-related information specific to the device.
10461046
//

pkg/apis/resource/validation/validation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,8 @@ func validateDeviceStatus(device resource.AllocatedDeviceStatus, fldPath *field.
752752
allErrs = append(allErrs, field.TooMany(fldPath.Child("conditions"), len(device.Conditions), resource.AllocatedDeviceStatusMaxConditions))
753753
}
754754
allErrs = append(allErrs, metav1validation.ValidateConditions(device.Conditions, fldPath.Child("conditions"))...)
755-
if len(device.Data.Raw) > 0 { // Data is an optional field.
756-
allErrs = append(allErrs, validateRawExtension(device.Data, fldPath.Child("data"), false, resource.AllocatedDeviceStatusDataMaxLength)...)
755+
if device.Data != nil && len(device.Data.Raw) > 0 { // Data is an optional field.
756+
allErrs = append(allErrs, validateRawExtension(*device.Data, fldPath.Child("data"), false, resource.AllocatedDeviceStatusDataMaxLength)...)
757757
}
758758
allErrs = append(allErrs, validateNetworkDeviceData(device.NetworkData, fldPath.Child("networkData"))...)
759759
return allErrs

pkg/apis/resource/validation/validation_resourceclaim_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
10031003
{Type: "test-6", Status: metav1.ConditionTrue, Reason: "test_reason", LastTransitionTime: metav1.Now(), ObservedGeneration: 0},
10041004
{Type: "test-7", Status: metav1.ConditionTrue, Reason: "test_reason", LastTransitionTime: metav1.Now(), ObservedGeneration: 0},
10051005
},
1006-
Data: runtime.RawExtension{
1006+
Data: &runtime.RawExtension{
10071007
Raw: []byte(`{"kind": "foo", "apiVersion": "dra.example.com/v1"}`),
10081008
},
10091009
NetworkData: &resource.NetworkDeviceData{
@@ -1090,7 +1090,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
10901090
Driver: goodName,
10911091
Pool: goodName,
10921092
Device: goodName,
1093-
Data: runtime.RawExtension{
1093+
Data: &runtime.RawExtension{
10941094
Raw: []byte(`foo`),
10951095
},
10961096
},
@@ -1112,7 +1112,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
11121112
Driver: goodName,
11131113
Pool: goodName,
11141114
Device: goodName,
1115-
Data: runtime.RawExtension{Raw: []byte(`{"str": "` + strings.Repeat("x", resource.AllocatedDeviceStatusDataMaxLength-9-2+1 /* too large by one */) + `"}`)},
1115+
Data: &runtime.RawExtension{Raw: []byte(`{"str": "` + strings.Repeat("x", resource.AllocatedDeviceStatusDataMaxLength-9-2+1 /* too large by one */) + `"}`)},
11161116
Conditions: []metav1.Condition{
11171117
{Type: "test-0", Status: metav1.ConditionTrue, Reason: "test_reason", LastTransitionTime: metav1.Now(), ObservedGeneration: 0},
11181118
{Type: "test-1", Status: metav1.ConditionTrue, Reason: "test_reason", LastTransitionTime: metav1.Now(), ObservedGeneration: 0},
@@ -1219,7 +1219,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
12191219
Driver: goodName,
12201220
Pool: goodName,
12211221
Device: goodName,
1222-
Data: runtime.RawExtension{
1222+
Data: &runtime.RawExtension{
12231223
Raw: []byte(`foo`),
12241224
},
12251225
},
@@ -1241,7 +1241,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
12411241
Driver: goodName,
12421242
Pool: goodName,
12431243
Device: goodName,
1244-
Data: runtime.RawExtension{Raw: []byte(`{"str": "` + strings.Repeat("x", resource.AllocatedDeviceStatusDataMaxLength-9-2+1 /* too large by one */) + `"}`)},
1244+
Data: &runtime.RawExtension{Raw: []byte(`{"str": "` + strings.Repeat("x", resource.AllocatedDeviceStatusDataMaxLength-9-2+1 /* too large by one */) + `"}`)},
12451245
Conditions: []metav1.Condition{
12461246
{Type: "test-0", Status: metav1.ConditionTrue, Reason: "test_reason", LastTransitionTime: metav1.Now(), ObservedGeneration: 0},
12471247
{Type: "test-1", Status: metav1.ConditionTrue, Reason: "test_reason", LastTransitionTime: metav1.Now(), ObservedGeneration: 0},

staging/src/k8s.io/api/resource/v1alpha3/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ type AllocatedDeviceStatus struct {
10511051
// The length of the raw data must be smaller or equal to 10 Ki.
10521052
//
10531053
// +optional
1054-
Data runtime.RawExtension `json:"data,omitempty" protobuf:"bytes,5,opt,name=data"`
1054+
Data *runtime.RawExtension `json:"data,omitempty" protobuf:"bytes,5,opt,name=data"`
10551055

10561056
// NetworkData contains network-related information specific to the device.
10571057
//

staging/src/k8s.io/api/resource/v1beta1/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ type AllocatedDeviceStatus struct {
10541054
// The length of the raw data must be smaller or equal to 10 Ki.
10551055
//
10561056
// +optional
1057-
Data runtime.RawExtension `json:"data,omitempty" protobuf:"bytes,5,opt,name=data"`
1057+
Data *runtime.RawExtension `json:"data,omitempty" protobuf:"bytes,5,opt,name=data"`
10581058

10591059
// NetworkData contains network-related information specific to the device.
10601060
//

test/e2e/dra/dra.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
438438
Pool: allocatedResourceClaim.Status.Allocation.Devices.Results[0].Pool,
439439
Device: allocatedResourceClaim.Status.Allocation.Devices.Results[0].Device,
440440
Conditions: []metav1.Condition{{Type: "a", Status: "True", Message: "c", Reason: "d", LastTransitionTime: metav1.NewTime(time.Now().Truncate(time.Second))}},
441-
Data: runtime.RawExtension{Raw: []byte(`{"foo":"bar"}`)},
441+
Data: &runtime.RawExtension{Raw: []byte(`{"foo":"bar"}`)},
442442
NetworkData: &resourceapi.NetworkDeviceData{
443443
InterfaceName: "inf1",
444444
IPs: []string{"10.9.8.0/24", "2001:db8::/64"},
@@ -457,7 +457,7 @@ var _ = framework.SIGDescribe("node")("DRA", feature.DynamicResourceAllocation,
457457
Pool: allocatedResourceClaim.Status.Allocation.Devices.Results[0].Pool,
458458
Device: allocatedResourceClaim.Status.Allocation.Devices.Results[0].Device,
459459
Conditions: []metav1.Condition{{Type: "e", Status: "True", Message: "g", Reason: "h", LastTransitionTime: metav1.NewTime(time.Now().Truncate(time.Second))}},
460-
Data: runtime.RawExtension{Raw: []byte(`{"bar":"foo"}`)},
460+
Data: &runtime.RawExtension{Raw: []byte(`{"bar":"foo"}`)},
461461
NetworkData: &resourceapi.NetworkDeviceData{
462462
InterfaceName: "inf2",
463463
IPs: []string{"10.9.8.1/24", "2001:db8::1/64"},

test/integration/resourceclaim/feature_enable_disable_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestEnableDisableDRAResourceClaimDeviceStatus(t *testing.T) {
8181
Driver: "foo",
8282
Pool: "foo",
8383
Device: "foo",
84-
Data: runtime.RawExtension{
84+
Data: &runtime.RawExtension{
8585
Raw: []byte(`{"kind": "foo", "apiVersion": "dra.example.com/v1"}`),
8686
},
8787
NetworkData: &v1beta1.NetworkDeviceData{
@@ -153,7 +153,7 @@ func TestEnableDisableDRAResourceClaimDeviceStatus(t *testing.T) {
153153
Driver: "bar",
154154
Pool: "bar",
155155
Device: "bar",
156-
Data: runtime.RawExtension{
156+
Data: &runtime.RawExtension{
157157
Raw: []byte(`{"kind": "foo", "apiVersion": "dra.example.com/v1"}`),
158158
},
159159
NetworkData: &v1beta1.NetworkDeviceData{
@@ -189,7 +189,7 @@ func TestEnableDisableDRAResourceClaimDeviceStatus(t *testing.T) {
189189
Driver: "bar",
190190
Pool: "bar",
191191
Device: "bar",
192-
Data: runtime.RawExtension{
192+
Data: &runtime.RawExtension{
193193
Raw: []byte(`{"kind": "foo", "apiVersion": "dra.example.com/v1"}`),
194194
},
195195
NetworkData: &v1beta1.NetworkDeviceData{

0 commit comments

Comments
 (0)