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>

fix: fix
  • Loading branch information
ChanYiLin committed Mar 25, 2024
1 parent 62c25ce commit f640a16
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 35 deletions.
20 changes: 0 additions & 20 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
Expand All @@ -71,22 +67,12 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/longhorn/backupstore v0.0.0-20240219094812-3a87ee02df77 h1:iJRq59kA22f9HIjFtY/lz5rKCorZJrrYXju70XoWdmE=
github.com/longhorn/backupstore v0.0.0-20240219094812-3a87ee02df77/go.mod h1:4cbJWtlrD2cGTQxQLtdlPTYopiJiusXH7CpOBrn/s3k=
github.com/longhorn/go-common-libs v0.0.0-20240307063052-6e77996eda29 h1:tyzIDCMjQGQzhqAtdJaeEMAaNUZJD/sHERXp+tYc+ms=
github.com/longhorn/go-common-libs v0.0.0-20240307063052-6e77996eda29/go.mod h1:ePLGb2r/PJBUIVoVhLOt4bLOeu0S72ZB+fWDWwC8H28=
github.com/longhorn/go-common-libs v0.0.0-20240315062830-5aa0ac1dac62 h1:ovotrq4HvaSRFgLozlNyUAvJp2eykdOwfpz4VIYZGIY=
github.com/longhorn/go-common-libs v0.0.0-20240315062830-5aa0ac1dac62/go.mod h1:ePLGb2r/PJBUIVoVhLOt4bLOeu0S72ZB+fWDWwC8H28=
github.com/longhorn/go-common-libs v0.0.0-20240319112414-b75404dc7fbc h1:Eh9Npc5yBcVD8E4zVQIGUtC62HcfqevrHjQ2kh7fJ/E=
github.com/longhorn/go-common-libs v0.0.0-20240319112414-b75404dc7fbc/go.mod h1:ESTw7LYBF+dB5VndQNKXKrD6B9s/hF94lotGKXLovlM=
github.com/longhorn/go-spdk-helper v0.0.0-20240308030201-9b252d6f7250 h1:bc9BtfvSuXvmztYiBCebvPWPxakbiCWBvydbeqat+Ek=
github.com/longhorn/go-spdk-helper v0.0.0-20240308030201-9b252d6f7250/go.mod h1:re2QHb6FUU9G/CL3AnXDbzFjLNPwmweBvnTfeVpkZ1E=
github.com/longhorn/go-spdk-helper v0.0.0-20240315133419-fd71aaab4a11 h1:qfr6EjGt5+jEsoAizQDNb9r4BGUVCBiSE8Y1EfKsfx4=
github.com/longhorn/go-spdk-helper v0.0.0-20240315133419-fd71aaab4a11/go.mod h1:ByXr0dR+YNz0H1+k8aBXjSzQ7R2Y2UI6f4+d90YTM/M=
github.com/longhorn/go-spdk-helper v0.0.0-20240319142717-116729b98b89 h1:NdWVJURZRFnyLDIpw/Ocx9bsQCdHpBkr0BOuQQCyPtg=
github.com/longhorn/go-spdk-helper v0.0.0-20240319142717-116729b98b89/go.mod h1:do6+0y096uk/gW1d5iOKMuebFcf/OiIhyOtIUVamReU=
github.com/longhorn/longhorn-engine v1.6.0-dev-20240105.0.20240126141003-067f67803ee8 h1:Oj5bAlKBzS+qPxA8lfpUcbllrVjnHVCuhPcQv/V98xw=
github.com/longhorn/longhorn-engine v1.6.0-dev-20240105.0.20240126141003-067f67803ee8/go.mod h1:Snkv3gy4AUOhZSYMI7g7lVX/OOB8DTo28eJwsEfbAwM=
github.com/longhorn/longhorn-spdk-engine v0.0.0-20240315010143-da2a02e86462 h1:eVMZH4r+v1NwBbsuxdTmiJD4odWQ0GmuYgS1KN93nss=
github.com/longhorn/longhorn-spdk-engine v0.0.0-20240315010143-da2a02e86462/go.mod h1:2gpXwMvzw/wZhsTSPRP453W5mO+TNDqEdPDJv7h8VWo=
github.com/longhorn/longhorn-spdk-engine v0.0.0-20240319114738-c9046e18cf8c h1:q1aK/uRlLDQZwDr3ADBsNvFjeb0OwbkppysHajQaogk=
github.com/longhorn/longhorn-spdk-engine v0.0.0-20240319114738-c9046e18cf8c/go.mod h1:14Br2xN1itgG0bmg/uHCgVFIb3ccBAa0RAzLn3MP1G0=
github.com/longhorn/nsfilelock v0.0.0-20200723175406-fa7c83ad0003 h1:Jw9uANsGcHTxp6HcC++/vN17LfeuDmozHI2j6DoZf5E=
Expand Down Expand Up @@ -222,8 +208,6 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 h1:
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s=
google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk=
google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand All @@ -237,14 +221,10 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/apimachinery v0.29.2 h1:EWGpfJ856oj11C52NRCHuU7rFDwxev48z+6DSlGNsV8=
k8s.io/apimachinery v0.29.2/go.mod h1:6HVkd1FwxIagpYrHSwJlQqZI3G9LfYWRPAkUvLnXTKU=
k8s.io/apimachinery v0.29.3 h1:2tbx+5L7RNvqJjn7RIuIKu9XTsIZ9Z5wX2G22XAa5EU=
k8s.io/apimachinery v0.29.3/go.mod h1:hx/S4V2PNW4OMg3WizRrHutyB5la0iCUbZym+W0EQIU=
k8s.io/klog/v2 v2.110.1 h1:U/Af64HJf7FcwMcXyKm2RPM22WZzyR7OSpYj5tg3cL0=
k8s.io/klog/v2 v2.110.1/go.mod h1:YGtd1984u+GgbuZ7e08/yBuAfKLSO0+uR1Fhi6ExXjo=
k8s.io/mount-utils v0.29.2 h1:FrUfgvOo63nqJRPXKoqN/DW1lMnR/y0pzpFErKh6p2o=
k8s.io/mount-utils v0.29.2/go.mod h1:9IWJTMe8tG0MYMLEp60xK9GYVeCdA3g4LowmnVi+t9Y=
k8s.io/mount-utils v0.29.3 h1:iEcqPP7Vv8UClH8nnMfovtmy/04fIloRW9JuSXykoZ0=
k8s.io/mount-utils v0.29.3/go.mod h1:9IWJTMe8tG0MYMLEp60xK9GYVeCdA3g4LowmnVi+t9Y=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
Expand Down
20 changes: 12 additions & 8 deletions pkg/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
spdkapi "github.com/longhorn/longhorn-spdk-engine/pkg/api"
spdkclient "github.com/longhorn/longhorn-spdk-engine/pkg/client"

lhutils "github.com/longhorn/go-common-libs/utils"
"github.com/longhorn/longhorn-instance-manager/pkg/client"
"github.com/longhorn/longhorn-instance-manager/pkg/meta"
"github.com/longhorn/longhorn-instance-manager/pkg/types"
Expand Down Expand Up @@ -141,7 +142,7 @@ func (ops V1DataEngineInstanceOps) InstanceCreate(req *rpc.InstanceCreateRequest
if err != nil {
return nil, err
}
return processResponseToInstanceResponse(process), nil
return processResponseToInstanceResponse(process, req.Spec.Type), nil
}

func (ops V2DataEngineInstanceOps) InstanceCreate(req *rpc.InstanceCreateRequest) (*rpc.InstanceResponse, error) {
Expand Down Expand Up @@ -198,7 +199,7 @@ func (ops V1DataEngineInstanceOps) InstanceDelete(req *rpc.InstanceDeleteRequest
if err != nil {
return nil, err
}
return processResponseToInstanceResponse(process), nil
return processResponseToInstanceResponse(process, req.Type), nil
}

func (ops V2DataEngineInstanceOps) InstanceDelete(req *rpc.InstanceDeleteRequest) (*rpc.InstanceResponse, error) {
Expand Down Expand Up @@ -260,7 +261,7 @@ func (ops V1DataEngineInstanceOps) InstanceGet(req *rpc.InstanceGetRequest) (*rp
if err != nil {
return nil, err
}
return processResponseToInstanceResponse(process), nil
return processResponseToInstanceResponse(process, req.Type), nil
}

func (ops V2DataEngineInstanceOps) InstanceGet(req *rpc.InstanceGetRequest) (*rpc.InstanceResponse, error) {
Expand Down Expand Up @@ -324,7 +325,11 @@ func (ops V1DataEngineInstanceOps) InstanceList(instances map[string]*rpc.Instan
return err
}
for _, process := range processes {
instances[process.Spec.Name] = processResponseToInstanceResponse(process)
processType := types.InstanceTypeReplica
if lhutils.IsEngineProcess(process.Spec.Name) {
processType = types.InstanceTypeEngine
}
instances[process.Spec.Name] = processResponseToInstanceResponse(process, processType)
}
return nil
}
Expand Down Expand Up @@ -387,7 +392,7 @@ func (ops V1DataEngineInstanceOps) InstanceReplace(req *rpc.InstanceReplaceReque
return nil, err
}

return processResponseToInstanceResponse(process), nil
return processResponseToInstanceResponse(process, req.Spec.Type), nil
}

func (ops V2DataEngineInstanceOps) InstanceReplace(req *rpc.InstanceReplaceRequest) (*rpc.InstanceResponse, error) {
Expand Down Expand Up @@ -648,12 +653,11 @@ func (s *Server) watchProcess(ctx context.Context, req *emptypb.Empty, client *c
}
}

func processResponseToInstanceResponse(p *rpc.ProcessResponse) *rpc.InstanceResponse {
func processResponseToInstanceResponse(p *rpc.ProcessResponse, processType string) *rpc.InstanceResponse {
return &rpc.InstanceResponse{
Spec: &rpc.InstanceSpec{
Name: p.Spec.Name,
// Leave Type empty. It will be determined in longhorn manager.
Type: "",
Type: processType,
// Deprecated
BackendStoreDriver: rpc.BackendStoreDriver_v1,
DataEngine: rpc.DataEngine_DATA_ENGINE_V1,
Expand Down
10 changes: 3 additions & 7 deletions pkg/process/process_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"google.golang.org/protobuf/types/known/emptypb"
"k8s.io/mount-utils"

commonUtils "github.com/longhorn/go-common-libs/utils"
lhUtils "github.com/longhorn/go-common-libs/utils"
rpc "github.com/longhorn/longhorn-instance-manager/pkg/imrpc"
"github.com/longhorn/longhorn-instance-manager/pkg/types"
"github.com/longhorn/longhorn-instance-manager/pkg/util"
Expand Down Expand Up @@ -155,13 +155,13 @@ func (pm *Manager) getProcessesToUpdateConditions(volumeMountPointMap map[string

for _, p := range pm.processes {
p.lock.Lock()
if isEngineProcess(p) && p.State == StateRunning {
if lhUtils.IsEngineProcess(p.Name) && p.State == StateRunning {
volumeName := util.ProcessNameToVolumeName(p.Name)
volumeNameSHA := sha256.Sum256([]byte(volumeName))
volumeNameSHAStr := hex.EncodeToString(volumeNameSHA[:])

if mp, exists := volumeMountPointMap[volumeNameSHAStr]; exists {
p.Conditions[types.EngineConditionFilesystemReadOnly] = commonUtils.IsMountPointReadOnly(mp)
p.Conditions[types.EngineConditionFilesystemReadOnly] = lhUtils.IsMountPointReadOnly(mp)
processesToUpdate = append(processesToUpdate, p)
}
}
Expand All @@ -170,10 +170,6 @@ func (pm *Manager) getProcessesToUpdateConditions(volumeMountPointMap map[string
return processesToUpdate
}

func isEngineProcess(p *Process) bool {
return p.PortCount == DefaultEnginePortCount
}

// ProcessCreate will create a process according to the request.
// If the specified process name exists already, the creation will fail.
func (pm *Manager) ProcessCreate(ctx context.Context, req *rpc.ProcessCreateRequest) (ret *rpc.ProcessResponse, err error) {
Expand Down

0 comments on commit f640a16

Please sign in to comment.