Skip to content

Commit

Permalink
Experiment with status field instead
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Weber <[email protected]>
  • Loading branch information
ejweber committed Sep 5, 2023
1 parent 4de0583 commit 6be0c73
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
25 changes: 25 additions & 0 deletions controller/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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
}
5 changes: 5 additions & 0 deletions controller/replica_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions k8s/pkg/apis/longhorn/v1beta2/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ type NodeStatus struct {
Zone string `json:"zone"`
// +optional
SnapshotCheckStatus SnapshotCheckStatus `json:"snapshotCheckStatus"`
// +optional
AutoEvicting bool `json:"autoEvicting"`
}

// +genclient
Expand Down

0 comments on commit 6be0c73

Please sign in to comment.