Skip to content

Commit

Permalink
fix: parse the process name to get the process type instead of using …
Browse files Browse the repository at this point in the history
…port count

ref: longhorn/longhorn 7393

Signed-off-by: Jack Lin <jack.lin@suse.com>
  • Loading branch information
ChanYiLin committed Feb 22, 2024
1 parent 43013ae commit cbdd046
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions engineapi/instance_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"path/filepath"
"strconv"
"strings"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -267,7 +268,7 @@ func parseInstance(p *imapi.Instance) *longhorn.InstanceProcess {
DataEngine: getDataEngineFromInstanceProcess(p),
},
Status: longhorn.InstanceProcessStatus{
Type: getTypeForInstance(longhorn.InstanceType(p.Type), p.PortCount),
Type: getTypeForInstance(longhorn.InstanceType(p.Type), p.Name),
State: longhorn.InstanceState(p.InstanceStatus.State),
ErrorMsg: p.InstanceStatus.ErrorMsg,
Conditions: p.InstanceStatus.Conditions,
Expand All @@ -292,7 +293,7 @@ func parseProcess(p *imapi.Process) *longhorn.InstanceProcess {
DataEngine: longhorn.DataEngineTypeV1,
},
Status: longhorn.InstanceProcessStatus{
Type: getTypeForProcess(p.PortCount),
Type: getTypeForProcess(p.Name),
State: longhorn.InstanceState(p.ProcessStatus.State),
ErrorMsg: p.ProcessStatus.ErrorMsg,
Conditions: p.ProcessStatus.Conditions,
Expand All @@ -315,19 +316,27 @@ func getDataEngineFromInstanceProcess(p *imapi.Instance) longhorn.DataEngineType
return longhorn.DataEngineType(p.BackendStoreDriver)
}

func getTypeForInstance(instanceType longhorn.InstanceType, portCount int32) longhorn.InstanceType {
func getTypeForInstance(instanceType longhorn.InstanceType, name string) longhorn.InstanceType {
if instanceType != longhorn.InstanceType("") {
return instanceType
}

if portCount == DefaultEnginePortCount {
// engine process name example: pvc-5a8ee916-5989-46c6-bafc-ddbf7c802499-e-0
nameSlices := strings.Split(name, "-")
processType := nameSlices[len(nameSlices)-2]

if processType == "e" {
return longhorn.InstanceTypeEngine
}
return longhorn.InstanceTypeReplica
}

func getTypeForProcess(portCount int32) longhorn.InstanceType {
if portCount == DefaultEnginePortCount {
func getTypeForProcess(name string) longhorn.InstanceType {
// engine process name example: pvc-5a8ee916-5989-46c6-bafc-ddbf7c802499-e-0
nameSlices := strings.Split(name, "-")
processType := nameSlices[len(nameSlices)-2]

if processType == "e" {
return longhorn.InstanceTypeEngine
}
return longhorn.InstanceTypeReplica
Expand Down

0 comments on commit cbdd046

Please sign in to comment.