Skip to content

Commit

Permalink
Deprecate replica.status.AutoEvicting in favor of replica.spec.AutoEv…
Browse files Browse the repository at this point in the history
…icting

Signed-off-by: Eric Weber <[email protected]>
  • Loading branch information
ejweber committed Oct 23, 2023
1 parent 9ee898c commit 5a52300
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 20 deletions.
8 changes: 4 additions & 4 deletions controller/replica_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ func (rc *ReplicaController) UpdateReplicaEvictionStatus(replica *longhorn.Repli

// Check if eviction has been requested on this replica
if rc.isEvictionRequested(replica) &&
!replica.Status.EvictionRequested {
replica.Status.EvictionRequested = true
!replica.Spec.EvictionRequested {
replica.Spec.EvictionRequested = true
log.Info("Replica has requested eviction")
}

// Check if eviction has been cancelled on this replica
if !rc.isEvictionRequested(replica) &&
replica.Status.EvictionRequested {
replica.Status.EvictionRequested = false
replica.Spec.EvictionRequested {
replica.Spec.EvictionRequested = false
log.Info("Replica has cancelled eviction")
}

Expand Down
2 changes: 1 addition & 1 deletion controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func hasReplicaEvictionRequested(rs map[string]*longhorn.Replica) bool {
for _, r := range rs {
if r.Status.EvictionRequested {
if r.Spec.EvictionRequested {
return true
}
}
Expand Down
8 changes: 4 additions & 4 deletions controller/volume_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ func (c *VolumeController) EvictReplicas(v *longhorn.Volume,
hasNewReplica := false
healthyNonEvictingCount := healthyCount
for _, replica := range rs {
if replica.Status.EvictionRequested &&
if replica.Spec.EvictionRequested &&
e.Status.ReplicaModeMap[replica.Name] == longhorn.ReplicaModeRW {
healthyNonEvictingCount--
}
Expand Down Expand Up @@ -1030,15 +1030,15 @@ func (c *VolumeController) cleanupEvictionRequestedReplicas(v *longhorn.Volume,
if !datastore.IsAvailableHealthyReplica(r) {
continue
}
if !r.Status.EvictionRequested {
if !r.Spec.EvictionRequested {
hasNonEvictingHealthyReplica = true
break
}
evictingHealthyReplica = r.Name
}

for _, r := range rs {
if !r.Status.EvictionRequested {
if !r.Spec.EvictionRequested {
continue
}
if !hasNonEvictingHealthyReplica && r.Name == evictingHealthyReplica {
Expand Down Expand Up @@ -2474,7 +2474,7 @@ func (c *VolumeController) getReplenishReplicasCount(v *longhorn.Volume, rs map[
continue
}
// Skip the replica has been requested eviction.
if r.Spec.FailedAt == "" && (!r.Status.EvictionRequested) && r.Spec.Active {
if r.Spec.FailedAt == "" && (!r.Spec.EvictionRequested) && r.Spec.Active {
usableCount++
}
}
Expand Down
3 changes: 3 additions & 0 deletions k8s/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2436,6 +2436,8 @@ spec:
type: string
engineName:
type: string
evictionRequested:
type: boolean
failedAt:
type: string
hardNodeAffinity:
Expand Down Expand Up @@ -2494,6 +2496,7 @@ spec:
currentState:
type: string
evictionRequested:
description: 'Deprecated: Replaced by field `spec.evictionRequested`.'
type: boolean
instanceManagerName:
type: string
Expand Down
3 changes: 3 additions & 0 deletions k8s/pkg/apis/longhorn/v1beta2/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ type ReplicaSpec struct {
UnmapMarkDiskChainRemovedEnabled bool `json:"unmapMarkDiskChainRemovedEnabled"`
// +optional
RebuildRetryCount int `json:"rebuildRetryCount"`
// +optional
EvictionRequested bool `json:"evictionRequested"`
}

// ReplicaStatus defines the observed state of the Longhorn replica
type ReplicaStatus struct {
InstanceStatus `json:""`
// Deprecated: Replaced by field `spec.evictionRequested`.
// +optional
EvictionRequested bool `json:"evictionRequested"`
}
Expand Down
2 changes: 1 addition & 1 deletion manager/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ func (m *VolumeManager) DeleteReplica(volumeName, replicaName string) error {
if !datastore.IsAvailableHealthyReplica(r) {
continue
}
if r.Status.EvictionRequested {
if r.Spec.EvictionRequested {
continue
}
healthyReplica = r.Name
Expand Down
8 changes: 4 additions & 4 deletions scheduler/replica_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (rcs *ReplicaScheduler) getNodeCandidates(nodesInfo map[string]*longhorn.No
func getNodesWithEvictingReplicas(replicas map[string]*longhorn.Replica, nodeInfo map[string]*longhorn.Node) map[string]*longhorn.Node {
nodesWithEvictingReplicas := map[string]*longhorn.Node{}
for _, r := range replicas {
if r.Status.EvictionRequested {
if r.Spec.EvictionRequested {
if node, ok := nodeInfo[r.Spec.NodeID]; ok {
nodesWithEvictingReplicas[r.Spec.NodeID] = node
}
Expand Down Expand Up @@ -584,7 +584,7 @@ func (rcs *ReplicaScheduler) isFailedReplicaReusable(r *longhorn.Replica, v *lon
if r.Spec.RebuildRetryCount >= FailedReplicaMaxRetryCount {
return false, nil
}
if r.Status.EvictionRequested {
if r.Spec.EvictionRequested {
return false, nil
}
if hardNodeAffinity != "" && r.Spec.NodeID != hardNodeAffinity {
Expand Down Expand Up @@ -668,7 +668,7 @@ func IsPotentiallyReusableReplica(r *longhorn.Replica, hardNodeAffinity string)
if r.Spec.RebuildRetryCount >= FailedReplicaMaxRetryCount {
return false
}
if r.Status.EvictionRequested {
if r.Spec.EvictionRequested {
return false
}
if hardNodeAffinity != "" && r.Spec.NodeID != hardNodeAffinity {
Expand Down Expand Up @@ -802,7 +802,7 @@ func getCurrentNodesAndZones(replicas map[string]*longhorn.Replica, nodeInfo map
for _, r := range replicas {
if r.Spec.NodeID != "" && r.DeletionTimestamp == nil && r.Spec.FailedAt == "" {
if node, ok := nodeInfo[r.Spec.NodeID]; ok {
if r.Status.EvictionRequested {
if r.Spec.EvictionRequested {
if _, ok := usedNodes[r.Spec.NodeID]; !ok {
// This is an evicting replica on a thus far unused node. We won't change this again unless we
// find a non-evicting replica on this node.
Expand Down
10 changes: 4 additions & 6 deletions scheduler/replica_scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ func (s *TestSuite) TestReplicaScheduler(c *C) {
}
alreadyScheduledReplica := newReplicaForVolume(tc.volume)
alreadyScheduledReplica.Spec.NodeID = TestNode1
alreadyScheduledReplica.Status.EvictionRequested = true
alreadyScheduledReplica.Spec.EvictionRequested = true
tc.allReplicas[alreadyScheduledReplica.Name] = alreadyScheduledReplica
node1.Status.DiskStatus = map[string]*longhorn.DiskStatus{
getDiskID(TestNode1, "1"): {
Expand Down Expand Up @@ -1025,7 +1025,7 @@ func (s *TestSuite) TestReplicaScheduler(c *C) {
}
alreadyScheduledReplica = newReplicaForVolume(tc.volume)
alreadyScheduledReplica.Spec.NodeID = TestNode1
alreadyScheduledReplica.Status.EvictionRequested = true
alreadyScheduledReplica.Spec.EvictionRequested = true
tc.allReplicas[alreadyScheduledReplica.Name] = alreadyScheduledReplica
node1.Status.DiskStatus = map[string]*longhorn.DiskStatus{
getDiskID(TestNode1, "1"): {
Expand All @@ -1048,7 +1048,7 @@ func (s *TestSuite) TestReplicaScheduler(c *C) {
}
alreadyScheduledReplica = newReplicaForVolume(tc.volume)
alreadyScheduledReplica.Spec.NodeID = TestNode2
alreadyScheduledReplica.Status.EvictionRequested = false
alreadyScheduledReplica.Spec.EvictionRequested = false
tc.allReplicas[alreadyScheduledReplica.Name] = alreadyScheduledReplica
node2.Status.DiskStatus = map[string]*longhorn.DiskStatus{
getDiskID(TestNode2, "1"): {
Expand All @@ -1071,7 +1071,7 @@ func (s *TestSuite) TestReplicaScheduler(c *C) {
}
alreadyScheduledReplica = newReplicaForVolume(tc.volume)
alreadyScheduledReplica.Spec.NodeID = TestNode3
alreadyScheduledReplica.Status.EvictionRequested = false
alreadyScheduledReplica.Spec.EvictionRequested = false
tc.allReplicas[alreadyScheduledReplica.Name] = alreadyScheduledReplica
node3.Status.DiskStatus = map[string]*longhorn.DiskStatus{
getDiskID(TestNode3, "1"): {
Expand Down Expand Up @@ -1363,8 +1363,6 @@ func (s *TestSuite) TestGetCurrentNodesAndZones(c *C) {
InstanceSpec: longhorn.InstanceSpec{
NodeID: nodeName,
},
},
Status: longhorn.ReplicaStatus{
EvictionRequested: evictionRequested,
},
}
Expand Down

0 comments on commit 5a52300

Please sign in to comment.