diff --git a/controller/share_manager_controller.go b/controller/share_manager_controller.go index 13d50913a0..c1927778bc 100644 --- a/controller/share_manager_controller.go +++ b/controller/share_manager_controller.go @@ -432,6 +432,31 @@ func (c *ShareManagerController) unmountShareManagerVolume(sm *longhorn.ShareMan } } +// mountShareManagerVolume checks, exports and mounts the volume in the share manager pod. +func (c *ShareManagerController) mountShareManagerVolume(sm *longhorn.ShareManager) error { + podName := types.GetShareManagerPodNameFromShareManagerName(sm.Name) + pod, err := c.ds.GetPod(podName) + if err != nil && !apierrors.IsNotFound(err) { + return errors.Wrapf(err, "failed to retrieve pod %v for share manager from datastore", podName) + } + + if pod == nil { + return fmt.Errorf("pod %v for share manager not found", podName) + } + + client, err := engineapi.NewShareManagerClient(sm, pod) + if err != nil { + return errors.Wrapf(err, "failed to create share manager client for pod %v", podName) + } + defer client.Close() + + if err := client.Mount(); err != nil { + return errors.Wrapf(err, "failed to mount share manager pod %v", podName) + } + + return nil +} + func hasActiveWorkload(vol *longhorn.Volume) bool { if vol == nil { return false @@ -500,7 +525,7 @@ func (c *ShareManagerController) syncShareManagerVolume(sm *longhorn.ShareManage } return nil } else if sm.Status.State == longhorn.ShareManagerStateRunning { - return nil + return c.mountShareManagerVolume(sm) } // in a single node cluster, there is no other manager that can claim ownership so we are prevented from creation diff --git a/engineapi/share_manager.go b/engineapi/share_manager.go index bc8644d4bf..4fbecb95ac 100644 --- a/engineapi/share_manager.go +++ b/engineapi/share_manager.go @@ -42,3 +42,7 @@ func (c *ShareManagerClient) FilesystemTrim(encryptedDevice bool) error { func (c *ShareManagerClient) Unmount() error { return c.grpcClient.Unmount() } + +func (c *ShareManagerClient) Mount() error { + return c.grpcClient.Mount() +}