validator: reject update request before syncing disk spec and status
The disk spec and status should be one-to-one matching.
Longhorn 685
@@ -72,7 +72,7 @@ func (n *nodeValidator) Update(request *admission.Request, oldObj runtime.Object
}
// Ensure the node controller already syncs the disk spec and status.
- if len(oldNode.Spec.Disks) != len(oldNode.Status.DiskStatus) {
+ if !isNodeDiskSpecAndStatusSynced(oldNode) {
return werror.NewConflict(fmt.Sprintf("spec and status of disks on node %v are being syncing and please retry later.", oldNode.Name))
}
@@ -142,3 +142,17 @@ func (n *nodeValidator) Update(request *admission.Request, oldObj runtime.Object
return nil
}
+
+func isNodeDiskSpecAndStatusSynced(node *longhorn.Node) bool {
+ if len(node.Spec.Disks) != len(node.Status.DiskStatus) {
+ return false
+ }
+
+ for diskName := range node.Spec.Disks {
+ if _, ok := node.Status.DiskStatus[diskName]; !ok {
+ return false
+ }
+ }
+
+ return true
+}
