Skip to content

Commit

Permalink
Merge pull request openyurtio#1883 from crazytaxii/fix
Browse files Browse the repository at this point in the history
Fix: yurt-iot-dock crashes when setting the device properties (openyurtio#1872)
  • Loading branch information
LavenderQAQ authored Jan 3, 2024
2 parents 67e1485 + 9e358e0 commit a8a8532
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 a8a8532

Please sign in to comment.