Skip to content

Commit

Permalink
Use string field for replica.evictionRequested
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Weber <[email protected]>
  • Loading branch information
ejweber committed Oct 23, 2023
1 parent d9814f6 commit b993c20
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions controller/instance_manager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 6 additions & 2 deletions controller/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
7 changes: 6 additions & 1 deletion k8s/pkg/apis/longhorn/v1beta2/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const (
ReplicaRebuildFailedUnavailableErrorMSG = "rpc error: code = Unavailable"
)

type ReplicaEvictionRequested string

const (
ReplicaConditionTypeRebuildFailed = "RebuildFailed"
ReplicaConditionTypeWaitForBackingImage = "WaitForBackingImage"
Expand All @@ -17,6 +19,9 @@ const (

ReplicaConditionReasonRebuildFailedDisconnection = "Disconnection"
ReplicaConditionReasonRebuildFailedGeneral = "General"

ReplicaEvictionRequestedManual = ReplicaEvictionRequested("manual")
ReplicaEvictionRequestedAuto = ReplicaEvictionRequested("auto")
)

// ReplicaSpec defines the desired state of the Longhorn replica
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b993c20

Please sign in to comment.