diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go index d11e359c9..b8a2b253a 100644 --- a/pkg/instance/instance.go +++ b/pkg/instance/instance.go @@ -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" @@ -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) { @@ -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) { @@ -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) { @@ -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 } @@ -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) { @@ -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, diff --git a/pkg/process/process_manager.go b/pkg/process/process_manager.go index fd4c7ed93..884313442 100644 --- a/pkg/process/process_manager.go +++ b/pkg/process/process_manager.go @@ -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" @@ -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) } } @@ -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) {