From b993c208bf5a5fcca9b0ae601d4403bde88fab53 Mon Sep 17 00:00:00 2001 From: Eric Weber Date: Mon, 23 Oct 2023 16:10:21 -0500 Subject: [PATCH] Use string field for replica.evictionRequested Signed-off-by: Eric Weber --- controller/instance_manager_controller.go | 4 ++-- controller/node_controller.go | 8 ++++++-- k8s/pkg/apis/longhorn/v1beta2/replica.go | 7 ++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/controller/instance_manager_controller.go b/controller/instance_manager_controller.go index 0e38c9f233..d5a96f4895 100644 --- a/controller/instance_manager_controller.go +++ b/controller/instance_manager_controller.go @@ -775,10 +775,10 @@ func (imc *InstanceManagerController) canDeleteInstanceManagerPDB(im *longhorn.I if node.Status.AutoEvicting { // With this drain policy, we should try to evict unprotected replicas. for _, replica := range unprotectedReplicas { - if !replica.Spec.EvictionRequested { + if replica.Spec.EvictionRequested == "" { replicaLog := log.WithField("replica", replica.Name) replicaLog.Infof("Requesting replica eviction") - replica.Spec.EvictionRequested = true + replica.Spec.EvictionRequested = longhorn.ReplicaEvictionRequestedAuto if _, err = imc.ds.UpdateReplica(replica); err != nil { replicaLog.Errorf("Failed to request replica eviction, will requeue then resync instance manager: %v", err) } diff --git a/controller/node_controller.go b/controller/node_controller.go index c85263d51d..1af9978d63 100644 --- a/controller/node_controller.go +++ b/controller/node_controller.go @@ -1487,8 +1487,12 @@ func (nc *NodeController) syncReplicaEvictionRequested(node *longhorn.Node) erro return err } shouldEvictReplica := nc.shouldEvictReplica(node, &diskSpec, replica) - if replica.Spec.EvictionRequested != shouldEvictReplica { - replica.Spec.EvictionRequested = shouldEvictReplica + if shouldEvictReplica && replica.Spec.EvictionRequested != longhorn.ReplicaEvictionRequestedManual { + replica.Spec.EvictionRequested = longhorn.ReplicaEvictionRequestedManual + replicasToSync = append(replicasToSync, replica) + } + if !shouldEvictReplica && replica.Spec.EvictionRequested == longhorn.ReplicaEvictionRequestedManual { + replica.Spec.EvictionRequested = "" replicasToSync = append(replicasToSync, replica) } } diff --git a/k8s/pkg/apis/longhorn/v1beta2/replica.go b/k8s/pkg/apis/longhorn/v1beta2/replica.go index e8ed37533b..fa99ac2ff4 100644 --- a/k8s/pkg/apis/longhorn/v1beta2/replica.go +++ b/k8s/pkg/apis/longhorn/v1beta2/replica.go @@ -9,6 +9,8 @@ const ( ReplicaRebuildFailedUnavailableErrorMSG = "rpc error: code = Unavailable" ) +type ReplicaEvictionRequested string + const ( ReplicaConditionTypeRebuildFailed = "RebuildFailed" ReplicaConditionTypeWaitForBackingImage = "WaitForBackingImage" @@ -17,6 +19,9 @@ const ( ReplicaConditionReasonRebuildFailedDisconnection = "Disconnection" ReplicaConditionReasonRebuildFailedGeneral = "General" + + ReplicaEvictionRequestedManual = ReplicaEvictionRequested("manual") + ReplicaEvictionRequestedAuto = ReplicaEvictionRequested("auto") ) // ReplicaSpec defines the desired state of the Longhorn replica @@ -47,7 +52,7 @@ type ReplicaSpec struct { // +optional RebuildRetryCount int `json:"rebuildRetryCount"` // +optional - EvictionRequested bool `json:"evictionRequested"` + EvictionRequested ReplicaEvictionRequested `json:"evictionRequested"` } // ReplicaStatus defines the observed state of the Longhorn replica