From 6be0c73888c5026df5abc5bfa341d54e0ca54a1f Mon Sep 17 00:00:00 2001 From: Eric Weber Date: Tue, 5 Sep 2023 16:48:02 -0500 Subject: [PATCH] Experiment with status field instead Signed-off-by: Eric Weber --- controller/node_controller.go | 25 +++++++++++++++++++++++++ controller/replica_controller.go | 5 +++++ k8s/pkg/apis/longhorn/v1beta2/node.go | 2 ++ 3 files changed, 32 insertions(+) diff --git a/controller/node_controller.go b/controller/node_controller.go index c6baca6e90..c4f496ecbb 100644 --- a/controller/node_controller.go +++ b/controller/node_controller.go @@ -491,7 +491,11 @@ func (nc *NodeController) syncNode(key string) (err error) { node.Status.Region, node.Status.Zone = types.GetRegionAndZone(kubeNode.Labels) } +<<<<<<< Updated upstream if err = nc.syncEvictingCondition(node, kubeNode); err != nil { +======= + if err = nc.syncAutoEvictingStatus(node, kubeNode); err != nil { +>>>>>>> Stashed changes return err } @@ -1436,11 +1440,18 @@ func (nc *NodeController) createSnapshotMonitor() (mon monitor.Monitor, err erro return mon, nil } +<<<<<<< Updated upstream func (nc *NodeController) syncEvictingCondition(node *longhorn.Node, kubeNode *corev1.Node) error { +======= +func (nc *NodeController) syncAutoEvictingStatus(node *longhorn.Node, kubeNode *corev1.Node) error { + oldAutoEvicting := node.Status.AutoEvicting + +>>>>>>> Stashed changes nodeDrainPolicy, err := nc.ds.GetSettingValueExisted(types.SettingNameNodeDrainPolicy) if err != nil { return err } +<<<<<<< Updated upstream if nodeDrainPolicy != string(types.NodeDrainPolicyBlockForEviction) { return nil @@ -1455,5 +1466,19 @@ func (nc *NodeController) syncEvictingCondition(node *longhorn.Node, kubeNode *c node.Status.Conditions = types.SetConditionAndRecord(node.Status.Conditions, longhorn.NodeConditionTypeEvicting, longhorn.ConditionStatusFalse, "", fmt.Sprintf("Node %v is not cordoned and %s is %s", node.Name, types.SettingNameNodeDrainPolicy, types.NodeDrainPolicyBlockForEviction), nc.eventRecorder, node, corev1.EventTypeNormal) } +======= + if nodeDrainPolicy != string(types.NodeDrainPolicyBlockForEviction) { + node.Status.AutoEvicting = false // We only auto evict in response to the associated policy. + } else if kubeNode.Spec.Unschedulable { + node.Status.AutoEvicting = true + } else { + node.Status.AutoEvicting = false + } + + if oldAutoEvicting != node.Status.AutoEvicting { + nc.logger.Infof("Changed auto eviction status to %t", node.Status.AutoEvicting, "nodeDrainPolicy", + nodeDrainPolicy, "kubernetesNodeUnschedulable", kubeNode.Spec.Unschedulable) + } +>>>>>>> Stashed changes return nil } diff --git a/controller/replica_controller.go b/controller/replica_controller.go index 4320516c0a..b9af10bd24 100644 --- a/controller/replica_controller.go +++ b/controller/replica_controller.go @@ -217,8 +217,13 @@ func (rc *ReplicaController) isEvictionRequested(replica *longhorn.Replica) bool return false } +<<<<<<< Updated upstream // Check if node has been request eviction. if types.GetCondition(node.Status.Conditions, longhorn.NodeConditionTypeEvicting).Status == longhorn.ConditionStatusTrue { +======= + // Check if node has requested eviction or is attempting to auto-evict replicas. + if node.Spec.EvictionRequested || node.status.autoEvicting { +>>>>>>> Stashed changes return true } diff --git a/k8s/pkg/apis/longhorn/v1beta2/node.go b/k8s/pkg/apis/longhorn/v1beta2/node.go index 41743572c0..26eeb154bc 100644 --- a/k8s/pkg/apis/longhorn/v1beta2/node.go +++ b/k8s/pkg/apis/longhorn/v1beta2/node.go @@ -123,6 +123,8 @@ type NodeStatus struct { Zone string `json:"zone"` // +optional SnapshotCheckStatus SnapshotCheckStatus `json:"snapshotCheckStatus"` + // +optional + AutoEvicting bool `json:"autoEvicting"` } // +genclient