Skip to content

Commit

Permalink
Fix: yurt-iot-dock crashes when setting the device properties (openyu…
Browse files Browse the repository at this point in the history
…rtio#1872)

Signed-off-by: HF <[email protected]>
  • Loading branch information
crazytaxii committed Dec 27, 2023
1 parent df8974f commit 9e358e0
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions pkg/yurtiotdock/controllers/device_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,23 +278,30 @@ func (r *DeviceReconciler) reconcileDeviceProperties(d *iotv1alpha1.Device, devi
}

// 1.2. set the device attribute in the edge platform to the expected value
if actualProperty == nil || desiredProperty.DesiredValue != actualProperty.ActualValue {
klog.V(4).Infof("DeviceName: %s, the desired value and the actual value are different, desired: %s, actual: %s",
d.GetName(), desiredProperty.DesiredValue, actualProperty.ActualValue)
if err := r.deviceCli.UpdatePropertyState(context.TODO(), propertyName, d, clients.UpdateOptions{}); err != nil {
klog.ErrorS(err, "could not update property", "DeviceName", d.GetName(), "propertyName", propertyName)
failedPropertyNames = append(failedPropertyNames, propertyName)
var actualValue string
if actualProperty != nil {
if actualValue = actualProperty.ActualValue; desiredProperty.DesiredValue == actualValue {
// The actual value is same as the desired one.
continue
}
}

klog.V(4).Infof("DeviceName: %s, successfully set the property %s to desired value", d.GetName(), propertyName)
newActualProperty := iotv1alpha1.ActualPropertyState{
Name: propertyName,
GetURL: actualProperty.GetURL,
ActualValue: desiredProperty.DesiredValue,
}
newDeviceStatus.DeviceProperties[propertyName] = newActualProperty
klog.V(4).Infof("DeviceName: %s, the desired value and the actual value are different, desired: %s, actual: %s",
d.GetName(), desiredProperty.DesiredValue, actualValue)

if err := r.deviceCli.UpdatePropertyState(context.TODO(), propertyName, d, clients.UpdateOptions{}); err != nil {
klog.ErrorS(err, "could not update property", "DeviceName", d.GetName(), "propertyName", propertyName)
failedPropertyNames = append(failedPropertyNames, propertyName)
continue
}

klog.V(4).Infof("DeviceName: %s, successfully set the property %s to desired value", d.GetName(), propertyName)
newActualProperty := iotv1alpha1.ActualPropertyState{
Name: propertyName,
GetURL: desiredProperty.PutURL,
ActualValue: desiredProperty.DesiredValue,
}
newDeviceStatus.DeviceProperties[propertyName] = newActualProperty
}
return newDeviceStatus, failedPropertyNames
}
Expand Down

0 comments on commit 9e358e0

Please sign in to comment.