diff options
| author | KubeEdge Bot <48982446+kubeedge-bot@users.noreply.github.com> | 2024-04-22 10:16:00 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-22 10:16:00 +0800 |
| commit | d794090270ae1c47f2b7c72a4383591eb99002c2 (patch) | |
| tree | af06187b96bcd27921b9df353dfe351675dbf33e /cloud/pkg/devicecontroller/controller/downstream.go | |
| parent | Merge pull request #5548 from Shelley-BaoYue/automated-cherry-pick-of-#5530-u... (diff) | |
| parent | Fix the status reporting of device to avoid issues defined by twin. (diff) | |
| download | kubeedge-1.16.2.tar.gz | |
Merge pull request #5545 from luomengY/automated-cherry-pick-of-#5467-upstream-release-1.16v1.16.2
Automated cherry pick of #5467: Fix the status reporting of device to avoid issues defined by twin.
Diffstat (limited to 'cloud/pkg/devicecontroller/controller/downstream.go')
| -rw-r--r-- | cloud/pkg/devicecontroller/controller/downstream.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/cloud/pkg/devicecontroller/controller/downstream.go b/cloud/pkg/devicecontroller/controller/downstream.go index 20bc84ad1..adc3c3ac1 100644 --- a/cloud/pkg/devicecontroller/controller/downstream.go +++ b/cloud/pkg/devicecontroller/controller/downstream.go @@ -208,6 +208,9 @@ func isExistModel(deviceMap *sync.Map, device *v1beta1.Device) bool { // If NodeName is updated, call add device for newNode, deleteDevice for old Node. // If Spec is updated, send update message to edge func (dc *DownstreamController) deviceUpdated(device *v1beta1.Device) { + if len(device.Status.Twins) > 0 { + removeTwinWithNameChanged(device) + } deviceID := util.GetResourceID(device.Namespace, device.Name) value, ok := dc.deviceManager.Device.Load(deviceID) dc.deviceManager.Device.Store(deviceID, device) @@ -417,3 +420,20 @@ func NewDownstreamController(crdInformerFactory crdinformers.SharedInformerFacto } return dc, nil } + +// Remove twin with changed attribute names. +func removeTwinWithNameChanged(device *v1beta1.Device) { + properties := device.Spec.Properties + twins := device.Status.Twins + newTwins := make([]v1beta1.Twin, 0, len(properties)) + for _, twin := range twins { + twinName := twin.PropertyName + for _, property := range properties { + if property.Name == twinName { + newTwins = append(newTwins, twin) + break + } + } + } + device.Status.Twins = newTwins +} |
