mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	[KEP-4817] Use structured.MakeDeviceID
Signed-off-by: Lionel Jouin <lionel.jouin@est.tech>
This commit is contained in:
		@@ -130,7 +130,7 @@ func gatherRequestNames(deviceClaim *resource.DeviceClaim) sets.Set[string] {
 | 
				
			|||||||
func gatherAllocatedDevices(allocationResult *resource.DeviceAllocationResult) sets.Set[structured.DeviceID] {
 | 
					func gatherAllocatedDevices(allocationResult *resource.DeviceAllocationResult) sets.Set[structured.DeviceID] {
 | 
				
			||||||
	allocatedDevices := sets.New[structured.DeviceID]()
 | 
						allocatedDevices := sets.New[structured.DeviceID]()
 | 
				
			||||||
	for _, result := range allocationResult.Results {
 | 
						for _, result := range allocationResult.Results {
 | 
				
			||||||
		deviceID := structured.DeviceID{Driver: result.Driver, Pool: result.Pool, Device: result.Device}
 | 
							deviceID := structured.MakeDeviceID(result.Driver, result.Pool, result.Device)
 | 
				
			||||||
		allocatedDevices.Insert(deviceID)
 | 
							allocatedDevices.Insert(deviceID)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return allocatedDevices
 | 
						return allocatedDevices
 | 
				
			||||||
@@ -276,7 +276,7 @@ func validateResourceClaimStatusUpdate(status, oldStatus *resource.ResourceClaim
 | 
				
			|||||||
			return validateDeviceStatus(device, fldPath, allocatedDevices)
 | 
								return validateDeviceStatus(device, fldPath, allocatedDevices)
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		func(device resource.AllocatedDeviceStatus) (structured.DeviceID, string) {
 | 
							func(device resource.AllocatedDeviceStatus) (structured.DeviceID, string) {
 | 
				
			||||||
			return structured.DeviceID{Driver: device.Driver, Pool: device.Pool, Device: device.Device}, "deviceID"
 | 
								return structured.MakeDeviceID(device.Driver, device.Pool, device.Device), "deviceID"
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		fldPath.Child("devices"))...)
 | 
							fldPath.Child("devices"))...)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -744,7 +744,7 @@ func validateDeviceStatus(device resource.AllocatedDeviceStatus, fldPath *field.
 | 
				
			|||||||
	allErrs = append(allErrs, validateDriverName(device.Driver, fldPath.Child("driver"))...)
 | 
						allErrs = append(allErrs, validateDriverName(device.Driver, fldPath.Child("driver"))...)
 | 
				
			||||||
	allErrs = append(allErrs, validatePoolName(device.Pool, fldPath.Child("pool"))...)
 | 
						allErrs = append(allErrs, validatePoolName(device.Pool, fldPath.Child("pool"))...)
 | 
				
			||||||
	allErrs = append(allErrs, validateDeviceName(device.Device, fldPath.Child("device"))...)
 | 
						allErrs = append(allErrs, validateDeviceName(device.Device, fldPath.Child("device"))...)
 | 
				
			||||||
	deviceID := structured.DeviceID{Driver: device.Driver, Pool: device.Pool, Device: device.Device}
 | 
						deviceID := structured.MakeDeviceID(device.Driver, device.Pool, device.Device)
 | 
				
			||||||
	if !allocatedDevices.Has(deviceID) {
 | 
						if !allocatedDevices.Has(deviceID) {
 | 
				
			||||||
		allErrs = append(allErrs, field.Invalid(fldPath, deviceID, "must be an allocated device in the claim"))
 | 
							allErrs = append(allErrs, field.Invalid(fldPath, deviceID, "must be an allocated device in the claim"))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1024,7 +1024,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
 | 
				
			|||||||
		"invalid-device-status-duplicate": {
 | 
							"invalid-device-status-duplicate": {
 | 
				
			||||||
			wantFailures: field.ErrorList{
 | 
								wantFailures: field.ErrorList{
 | 
				
			||||||
				field.Duplicate(field.NewPath("status", "devices").Index(0).Child("networkData", "addresses").Index(1), "2001:db8::1/64"),
 | 
									field.Duplicate(field.NewPath("status", "devices").Index(0).Child("networkData", "addresses").Index(1), "2001:db8::1/64"),
 | 
				
			||||||
				field.Duplicate(field.NewPath("status", "devices").Index(1).Child("deviceID"), structured.DeviceID{Driver: goodName, Pool: goodName, Device: goodName}),
 | 
									field.Duplicate(field.NewPath("status", "devices").Index(1).Child("deviceID"), structured.MakeDeviceID(goodName, goodName, goodName)),
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			oldClaim: func() *resource.ResourceClaim { return validAllocatedClaim }(),
 | 
								oldClaim: func() *resource.ResourceClaim { return validAllocatedClaim }(),
 | 
				
			||||||
			update: func(claim *resource.ResourceClaim) *resource.ResourceClaim {
 | 
								update: func(claim *resource.ResourceClaim) *resource.ResourceClaim {
 | 
				
			||||||
@@ -1098,7 +1098,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		"invalid-device-status-no-device": {
 | 
							"invalid-device-status-no-device": {
 | 
				
			||||||
			wantFailures: field.ErrorList{
 | 
								wantFailures: field.ErrorList{
 | 
				
			||||||
				field.Invalid(field.NewPath("status", "devices").Index(0), structured.DeviceID{Driver: "b", Pool: "a", Device: "r"}, "must be an allocated device in the claim"),
 | 
									field.Invalid(field.NewPath("status", "devices").Index(0), structured.MakeDeviceID("b", "a", "r"), "must be an allocated device in the claim"),
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			oldClaim: func() *resource.ResourceClaim { return validAllocatedClaim }(),
 | 
								oldClaim: func() *resource.ResourceClaim { return validAllocatedClaim }(),
 | 
				
			||||||
			update: func(claim *resource.ResourceClaim) *resource.ResourceClaim {
 | 
								update: func(claim *resource.ResourceClaim) *resource.ResourceClaim {
 | 
				
			||||||
@@ -1116,7 +1116,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
 | 
				
			|||||||
		"invalid-device-status-duplicate-disabled-feature-gate": {
 | 
							"invalid-device-status-duplicate-disabled-feature-gate": {
 | 
				
			||||||
			wantFailures: field.ErrorList{
 | 
								wantFailures: field.ErrorList{
 | 
				
			||||||
				field.Duplicate(field.NewPath("status", "devices").Index(0).Child("networkData", "addresses").Index(1), "2001:db8::1/64"),
 | 
									field.Duplicate(field.NewPath("status", "devices").Index(0).Child("networkData", "addresses").Index(1), "2001:db8::1/64"),
 | 
				
			||||||
				field.Duplicate(field.NewPath("status", "devices").Index(1).Child("deviceID"), structured.DeviceID{Driver: goodName, Pool: goodName, Device: goodName}),
 | 
									field.Duplicate(field.NewPath("status", "devices").Index(1).Child("deviceID"), structured.MakeDeviceID(goodName, goodName, goodName)),
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			oldClaim: func() *resource.ResourceClaim { return validAllocatedClaim }(),
 | 
								oldClaim: func() *resource.ResourceClaim { return validAllocatedClaim }(),
 | 
				
			||||||
			update: func(claim *resource.ResourceClaim) *resource.ResourceClaim {
 | 
								update: func(claim *resource.ResourceClaim) *resource.ResourceClaim {
 | 
				
			||||||
@@ -1190,7 +1190,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		"invalid-device-status-no-device-disabled-feature-gate": {
 | 
							"invalid-device-status-no-device-disabled-feature-gate": {
 | 
				
			||||||
			wantFailures: field.ErrorList{
 | 
								wantFailures: field.ErrorList{
 | 
				
			||||||
				field.Invalid(field.NewPath("status", "devices").Index(0), structured.DeviceID{Driver: "b", Pool: "a", Device: "r"}, "must be an allocated device in the claim"),
 | 
									field.Invalid(field.NewPath("status", "devices").Index(0), structured.MakeDeviceID("b", "a", "r"), "must be an allocated device in the claim"),
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			oldClaim: func() *resource.ResourceClaim { return validAllocatedClaim }(),
 | 
								oldClaim: func() *resource.ResourceClaim { return validAllocatedClaim }(),
 | 
				
			||||||
			update: func(claim *resource.ResourceClaim) *resource.ResourceClaim {
 | 
								update: func(claim *resource.ResourceClaim) *resource.ResourceClaim {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -257,7 +257,7 @@ func dropDeallocatedStatusDevices(newClaim, oldClaim *resource.ResourceClaim) {
 | 
				
			|||||||
	if oldClaim.Status.Allocation != nil {
 | 
						if oldClaim.Status.Allocation != nil {
 | 
				
			||||||
		// Get all devices in the oldClaim.
 | 
							// Get all devices in the oldClaim.
 | 
				
			||||||
		for _, result := range oldClaim.Status.Allocation.Devices.Results {
 | 
							for _, result := range oldClaim.Status.Allocation.Devices.Results {
 | 
				
			||||||
			deviceID := structured.DeviceID{Driver: result.Driver, Pool: result.Pool, Device: result.Device}
 | 
								deviceID := structured.MakeDeviceID(result.Driver, result.Pool, result.Device)
 | 
				
			||||||
			deallocatedDevices.Insert(deviceID)
 | 
								deallocatedDevices.Insert(deviceID)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -265,7 +265,7 @@ func dropDeallocatedStatusDevices(newClaim, oldClaim *resource.ResourceClaim) {
 | 
				
			|||||||
	// Remove devices from deallocatedDevices that are still in newClaim.
 | 
						// Remove devices from deallocatedDevices that are still in newClaim.
 | 
				
			||||||
	if newClaim.Status.Allocation != nil {
 | 
						if newClaim.Status.Allocation != nil {
 | 
				
			||||||
		for _, result := range newClaim.Status.Allocation.Devices.Results {
 | 
							for _, result := range newClaim.Status.Allocation.Devices.Results {
 | 
				
			||||||
			deviceID := structured.DeviceID{Driver: result.Driver, Pool: result.Pool, Device: result.Device}
 | 
								deviceID := structured.MakeDeviceID(result.Driver, result.Pool, result.Device)
 | 
				
			||||||
			deallocatedDevices.Delete(deviceID)
 | 
								deallocatedDevices.Delete(deviceID)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -273,11 +273,7 @@ func dropDeallocatedStatusDevices(newClaim, oldClaim *resource.ResourceClaim) {
 | 
				
			|||||||
	// Remove from newClaim.Status.Devices.
 | 
						// Remove from newClaim.Status.Devices.
 | 
				
			||||||
	n := 0
 | 
						n := 0
 | 
				
			||||||
	for _, device := range newClaim.Status.Devices {
 | 
						for _, device := range newClaim.Status.Devices {
 | 
				
			||||||
		deviceID := structured.DeviceID{
 | 
							deviceID := structured.MakeDeviceID(device.Driver, device.Pool, device.Device)
 | 
				
			||||||
			Driver: device.Driver,
 | 
					 | 
				
			||||||
			Pool:   device.Pool,
 | 
					 | 
				
			||||||
			Device: device.Device,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if !deallocatedDevices.Has(deviceID) {
 | 
							if !deallocatedDevices.Has(deviceID) {
 | 
				
			||||||
			newClaim.Status.Devices[n] = device
 | 
								newClaim.Status.Devices[n] = device
 | 
				
			||||||
			n++
 | 
								n++
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user