From 514200543dd6cbc7518774b29a9044c61ab6bba6 Mon Sep 17 00:00:00 2001 From: Derek Su Date: Sun, 7 Jul 2024 14:23:55 +0000 Subject: [PATCH 1/3] feat(v2 upgrade/crd): add targetPortEnd and targetPortStart in instanceProcessStatus Longhorn 6001 Signed-off-by: Derek Su --- k8s/crds.yaml | 18 ++++++++++++++++++ .../apis/longhorn/v1beta2/instancemanager.go | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/k8s/crds.yaml b/k8s/crds.yaml index 1329b838b6..167997ca7d 100644 --- a/k8s/crds.yaml +++ b/k8s/crds.yaml @@ -2115,6 +2115,12 @@ spec: type: integer state: type: string + targetPortEnd: + format: int32 + type: integer + targetPortStart: + format: int32 + type: integer type: type: string type: object @@ -2158,6 +2164,12 @@ spec: type: integer state: type: string + targetPortEnd: + format: int32 + type: integer + targetPortStart: + format: int32 + type: integer type: type: string type: object @@ -2201,6 +2213,12 @@ spec: type: integer state: type: string + targetPortEnd: + format: int32 + type: integer + targetPortStart: + format: int32 + type: integer type: type: string type: object diff --git a/k8s/pkg/apis/longhorn/v1beta2/instancemanager.go b/k8s/pkg/apis/longhorn/v1beta2/instancemanager.go index 0413fad917..7b2689f35a 100644 --- a/k8s/pkg/apis/longhorn/v1beta2/instancemanager.go +++ b/k8s/pkg/apis/longhorn/v1beta2/instancemanager.go @@ -134,6 +134,10 @@ type InstanceProcessStatus struct { // +optional PortStart int32 `json:"portStart"` // +optional + TargetPortEnd int32 `json:"targetPortEnd"` + // +optional + TargetPortStart int32 `json:"targetPortStart"` + // +optional State InstanceState `json:"state"` // +optional Type InstanceType `json:"type"` From 36ee12364e3265d7a7bb09fe9e9c9abcc548d6a1 Mon Sep 17 00:00:00 2001 From: Derek Su Date: Tue, 9 Jul 2024 08:23:56 +0000 Subject: [PATCH 2/3] feat(v2 upgrade/chart): update for the changes in the data plane Longhorn 6001 Signed-off-by: Derek Su --- controller/engine_controller.go | 38 +++++++++++++++++++------------- controller/instance_handler.go | 11 +++++---- controller/replica_controller.go | 2 +- engineapi/instance_manager.go | 20 ++++++++++++----- 4 files changed, 45 insertions(+), 26 deletions(-) diff --git a/controller/engine_controller.go b/controller/engine_controller.go index 6dcd9c2ed5..fd210a5499 100644 --- a/controller/engine_controller.go +++ b/controller/engine_controller.go @@ -510,6 +510,9 @@ func (ec *EngineController) CreateInstance(obj interface{}) (*longhorn.InstanceP DataLocality: v.Spec.DataLocality, ImIP: im.Status.IP, EngineCLIAPIVersion: cliAPIVersion, + UpgradeRequired: false, + InitiatorAddress: im.Status.IP, + TargetAddress: im.Status.IP, }) } @@ -2119,25 +2122,30 @@ func (ec *EngineController) Upgrade(e *longhorn.Engine, log *logrus.Entry) (err err = errors.Wrapf(err, "failed to live upgrade image for %v", e.Name) }() - engineClientProxy, err := ec.getEngineClientProxy(e, e.Spec.Image) - if err != nil { - return err - } - defer engineClientProxy.Close() - - version, err := engineClientProxy.VersionGet(e, false) - if err != nil { - return err - } + if types.IsDataEngineV1(e.Spec.DataEngine) { + engineClientProxy, err := ec.getEngineClientProxy(e, e.Spec.Image) + if err != nil { + return err + } + defer engineClientProxy.Close() - // Don't use image with different image name but same commit here. It - // will cause live replica to be removed. Volume controller should filter those. - if version.ClientVersion.GitCommit != version.ServerVersion.GitCommit { - log.Infof("Upgrading engine from %v to %v", e.Status.CurrentImage, e.Spec.Image) - if err := ec.UpgradeEngineInstance(e, log); err != nil { + version, err := engineClientProxy.VersionGet(e, false) + if err != nil { return err } + + // Don't use image with different image name but same commit here. It + // will cause live replica to be removed. Volume controller should filter those. + if version.ClientVersion.GitCommit != version.ServerVersion.GitCommit { + log.Infof("Upgrading engine from %v to %v", e.Status.CurrentImage, e.Spec.Image) + if err := ec.UpgradeEngineInstance(e, log); err != nil { + return err + } + } + } else { + return errors.Wrapf(err, "upgrading engine %v with data engine %v is not supported", e.Name, e.Spec.DataEngine) } + log.Infof("Engine has been upgraded from %v to %v", e.Status.CurrentImage, e.Spec.Image) e.Status.CurrentImage = e.Spec.Image e.Status.CurrentReplicaAddressMap = e.Spec.UpgradedReplicaAddressMap diff --git a/controller/instance_handler.go b/controller/instance_handler.go index 56f5104eab..c42566d980 100644 --- a/controller/instance_handler.go +++ b/controller/instance_handler.go @@ -249,6 +249,8 @@ func (h *InstanceHandler) ReconcileInstanceState(obj interface{}, spec *longhorn return err } + log := logrus.WithField("instance", instanceName) + isCLIAPIVersionOne := false if types.IsDataEngineV1(spec.DataEngine) { if status.CurrentImage != "" { @@ -296,11 +298,11 @@ func (h *InstanceHandler) ReconcileInstanceState(obj interface{}, spec *longhorn if !status.LogFetched { // No need to get the log for instance manager if the data engine is not "longhorn" if types.IsDataEngineV1(spec.DataEngine) { - logrus.Warnf("Getting requested log for %v in instance manager %v", instanceName, status.InstanceManagerName) + log.Warnf("Getting requested log for %v in instance manager %v", instanceName, status.InstanceManagerName) if im == nil { - logrus.Warnf("Failed to get the log for %v due to Instance Manager is already gone", status.InstanceManagerName) + log.Warnf("Failed to get the log for %v due to Instance Manager is already gone", status.InstanceManagerName) } else if err := h.printInstanceLogs(instanceName, runtimeObj); err != nil { - logrus.WithError(err).Warnf("Failed to get requested log for instance %v on node %v", instanceName, im.Spec.NodeID) + log.WithError(err).Warnf("Failed to get requested log for instance %v on node %v", instanceName, im.Spec.NodeID) } } status.LogFetched = true @@ -384,10 +386,11 @@ func (h *InstanceHandler) ReconcileInstanceState(obj interface{}, spec *longhorn } status.Started = false default: - return fmt.Errorf("BUG: unknown instance desire state: desire %v", spec.DesireState) + return fmt.Errorf("unknown instance desire state: desire %v", spec.DesireState) } h.syncStatusWithInstanceManager(im, instanceName, spec, status, instances) + switch status.CurrentState { case longhorn.InstanceStateRunning: // If `spec.DesireState` is `longhorn.InstanceStateStopped`, `spec.NodeID` has been unset by volume controller. diff --git a/controller/replica_controller.go b/controller/replica_controller.go index 90d33c3fdf..0eb6c7b07b 100644 --- a/controller/replica_controller.go +++ b/controller/replica_controller.go @@ -565,7 +565,7 @@ func (rc *ReplicaController) DeleteInstance(obj interface{}) error { cleanupRequired = true } - log.Info("Deleting replica instance") + log.WithField("cleanupRequired", cleanupRequired).Infof("Deleting replica instance on disk %v", r.Spec.DiskPath) err = c.InstanceDelete(r.Spec.DataEngine, r.Name, string(longhorn.InstanceManagerTypeReplica), r.Spec.DiskID, cleanupRequired) if err != nil && !types.ErrorIsNotFound(err) { diff --git a/engineapi/instance_manager.go b/engineapi/instance_manager.go index 3cd7fe29ac..a2ce5278f8 100644 --- a/engineapi/instance_manager.go +++ b/engineapi/instance_manager.go @@ -268,12 +268,14 @@ func parseInstance(p *imapi.Instance) *longhorn.InstanceProcess { DataEngine: getDataEngineFromInstanceProcess(p), }, Status: longhorn.InstanceProcessStatus{ - Type: getTypeForInstance(longhorn.InstanceType(p.Type), p.Name), - State: longhorn.InstanceState(p.InstanceStatus.State), - ErrorMsg: p.InstanceStatus.ErrorMsg, - Conditions: p.InstanceStatus.Conditions, - PortStart: p.InstanceStatus.PortStart, - PortEnd: p.InstanceStatus.PortEnd, + Type: getTypeForInstance(longhorn.InstanceType(p.Type), p.Name), + State: longhorn.InstanceState(p.InstanceStatus.State), + ErrorMsg: p.InstanceStatus.ErrorMsg, + Conditions: p.InstanceStatus.Conditions, + PortStart: p.InstanceStatus.PortStart, + PortEnd: p.InstanceStatus.PortEnd, + TargetPortStart: p.InstanceStatus.TargetPortStart, + TargetPortEnd: p.InstanceStatus.TargetPortEnd, // FIXME: These fields are not used, maybe we can deprecate them later. Listen: "", @@ -440,6 +442,9 @@ type EngineInstanceCreateRequest struct { DataLocality longhorn.DataLocality ImIP string EngineCLIAPIVersion int + UpgradeRequired bool + InitiatorAddress string + TargetAddress string } // EngineInstanceCreate creates a new engine instance @@ -494,6 +499,9 @@ func (c *InstanceManagerClient) EngineInstanceCreate(req *EngineInstanceCreateRe Engine: imclient.EngineCreateRequest{ ReplicaAddressMap: replicaAddresses, Frontend: frontend, + UpgradeRequired: req.UpgradeRequired, + InitiatorAddress: req.InitiatorAddress, + TargetAddress: req.TargetAddress, }, }) From 778c920065ebca0c3097a64da76f6fd8026fba2a Mon Sep 17 00:00:00 2001 From: Derek Su Date: Tue, 9 Jul 2024 08:26:13 +0000 Subject: [PATCH 3/3] vendor: update dependencies Longhorn 6001 Signed-off-by: Derek Su --- go.mod | 4 +- go.sum | 8 +- .../pkg/api/instance.go | 24 ++-- .../pkg/client/instance.go | 131 ++++++++++++++++++ vendor/modules.txt | 4 +- 5 files changed, 153 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 3613a54739..350d44d378 100644 --- a/go.mod +++ b/go.mod @@ -59,12 +59,12 @@ require ( github.com/jinzhu/copier v0.3.5 github.com/kubernetes-csi/csi-lib-utils v0.6.1 github.com/longhorn/backing-image-manager v1.7.0-dev.0.20240707082104-dfbe0d008b9c - github.com/longhorn/backupstore v0.0.0-20240706152841-78e2c8892f4e + github.com/longhorn/backupstore v0.0.0-20240709004445-1cadf9073de3 github.com/longhorn/go-common-libs v0.0.0-20240707062002-b9354601827e github.com/longhorn/go-iscsi-helper v0.0.0-20240708025845-7cc78e60866a github.com/longhorn/go-spdk-helper v0.0.0-20240708060539-de887e9cc6db github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240707085442-0bfac42c4aff - github.com/longhorn/longhorn-instance-manager v1.7.0-dev.0.20240707105202-1a2fb0b7ea9e + github.com/longhorn/longhorn-instance-manager v1.7.0-dev.0.20240709072210-84ba8e974de0 github.com/longhorn/longhorn-share-manager v1.7.0-dev.0.20240707073010-6d6d282d334a github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.18.0 diff --git a/go.sum b/go.sum index 4fae43fcbd..77ac610b9d 100644 --- a/go.sum +++ b/go.sum @@ -1222,8 +1222,8 @@ github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhn github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE= github.com/longhorn/backing-image-manager v1.7.0-dev.0.20240707082104-dfbe0d008b9c h1:KkY6aqQB8j9VWxNHNYObsA0Plyg40ZrSp1YSfnFDIUQ= github.com/longhorn/backing-image-manager v1.7.0-dev.0.20240707082104-dfbe0d008b9c/go.mod h1:ZXD/+yKwMer/eZzwQ2ev/eAyLvih7WNq6NDgfUpvQ+8= -github.com/longhorn/backupstore v0.0.0-20240706152841-78e2c8892f4e h1:UtuNgcxi6YSdlY711WXEa5lHqET6p3QL+4ZkAJnVl9w= -github.com/longhorn/backupstore v0.0.0-20240706152841-78e2c8892f4e/go.mod h1:X9DZ+xqReDQfSsGCxRnNViBxoxSbHezjfejwTPp17NI= +github.com/longhorn/backupstore v0.0.0-20240709004445-1cadf9073de3 h1:DCNyiGtXlYKMdXBm7p3l86pXEaP0klFpes+BtLYleQc= +github.com/longhorn/backupstore v0.0.0-20240709004445-1cadf9073de3/go.mod h1:IJ7rVDB0l5J8YBFgvbYRM0dCF9pLhnIToia+4PDzNqY= github.com/longhorn/go-common-libs v0.0.0-20240707062002-b9354601827e h1:0SiyvTuovYc9kLJbjagTSxv3sOfCCU9FQJasRo7bgzU= github.com/longhorn/go-common-libs v0.0.0-20240707062002-b9354601827e/go.mod h1:vX53A9KF4RHC1UTbEGouZHsZO6bwT3zk63l1hvwF5T8= github.com/longhorn/go-iscsi-helper v0.0.0-20240708025845-7cc78e60866a h1:8FYqfmKkssHYiZqgpnodiyzjPkYmqSViEjXdCvij3rQ= @@ -1232,8 +1232,8 @@ github.com/longhorn/go-spdk-helper v0.0.0-20240708060539-de887e9cc6db h1:wQRJNpZ github.com/longhorn/go-spdk-helper v0.0.0-20240708060539-de887e9cc6db/go.mod h1:BMhlxcEnrn0/jyO+9cMV1gWz2jkmeGFZLnGIqsH3lv0= github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240707085442-0bfac42c4aff h1:w8z+IYOHtvWEW7jZniVDX1vJGcGr4DIt2UmHeSxzXKU= github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240707085442-0bfac42c4aff/go.mod h1:u0TZ1221YusDYA+ExdVLjLid1Ps6JuJXgh9185l5D9Y= -github.com/longhorn/longhorn-instance-manager v1.7.0-dev.0.20240707105202-1a2fb0b7ea9e h1:rRgImfGjiuRSA7nm0tbf6vK3j5hVbdHdiQDU5aFnDEo= -github.com/longhorn/longhorn-instance-manager v1.7.0-dev.0.20240707105202-1a2fb0b7ea9e/go.mod h1:EFuyWq4P+esJTCDjJSiTk0vVG5rE4/5Ahq5YWyqoF/c= +github.com/longhorn/longhorn-instance-manager v1.7.0-dev.0.20240709072210-84ba8e974de0 h1:zhLAX9ggz3egAGVLU45m7RAGD/BSxiAG+mJGcO8IH8k= +github.com/longhorn/longhorn-instance-manager v1.7.0-dev.0.20240709072210-84ba8e974de0/go.mod h1:u3rEJikFcEGOlzMcAZjvs0mecBYA5RQITQLVfimFSyE= github.com/longhorn/longhorn-share-manager v1.7.0-dev.0.20240707073010-6d6d282d334a h1:3CqA8oswld3wmPGS+nNA8IQIo8atzgQNbYSf8MzAe5k= github.com/longhorn/longhorn-share-manager v1.7.0-dev.0.20240707073010-6d6d282d334a/go.mod h1:R6+NscPU4lAV5ueO7//lBCAO3en0aDbZi5KkkOSUJvk= github.com/longhorn/types v0.0.0-20240706151541-33cb010c3544 h1:U08l+0SbxCsododsraBHB5PdXrQme3TEh9iaREhRLQs= diff --git a/vendor/github.com/longhorn/longhorn-instance-manager/pkg/api/instance.go b/vendor/github.com/longhorn/longhorn-instance-manager/pkg/api/instance.go index c151db5eba..74752823ac 100644 --- a/vendor/github.com/longhorn/longhorn-instance-manager/pkg/api/instance.go +++ b/vendor/github.com/longhorn/longhorn-instance-manager/pkg/api/instance.go @@ -64,20 +64,24 @@ func RPCToInstanceList(obj *rpc.InstanceListResponse) map[string]*Instance { } type InstanceStatus struct { - State string `json:"state"` - ErrorMsg string `json:"errorMsg"` - Conditions map[string]bool `json:"conditions"` - PortStart int32 `json:"portStart"` - PortEnd int32 `json:"portEnd"` + State string `json:"state"` + ErrorMsg string `json:"errorMsg"` + Conditions map[string]bool `json:"conditions"` + PortStart int32 `json:"portStart"` + PortEnd int32 `json:"portEnd"` + TargetPortStart int32 `json:"targetPortStart"` + TargetPortEnd int32 `json:"targetPortEnd"` } func RPCToInstanceStatus(obj *rpc.InstanceStatus) InstanceStatus { return InstanceStatus{ - State: obj.State, - ErrorMsg: obj.ErrorMsg, - Conditions: obj.Conditions, - PortStart: obj.PortStart, - PortEnd: obj.PortEnd, + State: obj.State, + ErrorMsg: obj.ErrorMsg, + Conditions: obj.Conditions, + PortStart: obj.PortStart, + PortEnd: obj.PortEnd, + TargetPortStart: obj.TargetPortStart, + TargetPortEnd: obj.TargetPortEnd, } } diff --git a/vendor/github.com/longhorn/longhorn-instance-manager/pkg/client/instance.go b/vendor/github.com/longhorn/longhorn-instance-manager/pkg/client/instance.go index 5367a566e7..6b4f67083f 100644 --- a/vendor/github.com/longhorn/longhorn-instance-manager/pkg/client/instance.go +++ b/vendor/github.com/longhorn/longhorn-instance-manager/pkg/client/instance.go @@ -88,6 +88,9 @@ func NewInstanceServiceClientWithTLS(ctx context.Context, ctxCancel context.Canc type EngineCreateRequest struct { ReplicaAddressMap map[string]string Frontend string + InitiatorAddress string + TargetAddress string + UpgradeRequired bool } type ReplicaCreateRequest struct { @@ -115,6 +118,7 @@ type InstanceCreateRequest struct { BackendStoreDriver string } +// InstanceCreate creates an instance. func (c *InstanceServiceClient) InstanceCreate(req *InstanceCreateRequest) (*api.Instance, error) { if req.Name == "" || req.InstanceType == "" { return nil, fmt.Errorf("failed to create instance: missing required parameter") @@ -169,6 +173,10 @@ func (c *InstanceServiceClient) InstanceCreate(req *InstanceCreateRequest) (*api ProcessInstanceSpec: processInstanceSpec, SpdkInstanceSpec: spdkInstanceSpec, + + UpgradeRequired: req.Engine.UpgradeRequired, + InitiatorAddress: req.Engine.InitiatorAddress, + TargetAddress: req.Engine.TargetAddress, }, }) if err != nil { @@ -178,6 +186,7 @@ func (c *InstanceServiceClient) InstanceCreate(req *InstanceCreateRequest) (*api return api.RPCToInstance(p), nil } +// InstanceDelete deletes the instance by name. func (c *InstanceServiceClient) InstanceDelete(dataEngine, name, instanceType, diskUUID string, cleanupRequired bool) (*api.Instance, error) { if name == "" { return nil, fmt.Errorf("failed to delete instance: missing required parameter name") @@ -207,6 +216,7 @@ func (c *InstanceServiceClient) InstanceDelete(dataEngine, name, instanceType, d return api.RPCToInstance(p), nil } +// InstanceGet returns the instance by name. func (c *InstanceServiceClient) InstanceGet(dataEngine, name, instanceType string) (*api.Instance, error) { if name == "" { return nil, fmt.Errorf("failed to get instance: missing required parameter name") @@ -246,6 +256,7 @@ func (c *InstanceServiceClient) InstanceList() (map[string]*api.Instance, error) return api.RPCToInstanceList(instances), nil } +// InstanceLog returns the log stream of an instance. func (c *InstanceServiceClient) InstanceLog(ctx context.Context, dataEngine, name, instanceType string) (*api.LogStream, error) { if name == "" { return nil, fmt.Errorf("failed to get instance: missing required parameter name") @@ -270,6 +281,7 @@ func (c *InstanceServiceClient) InstanceLog(ctx context.Context, dataEngine, nam return api.NewLogStream(stream), nil } +// InstanceWatch watches for instance updates. func (c *InstanceServiceClient) InstanceWatch(ctx context.Context) (*api.InstanceStream, error) { client := c.getControllerServiceClient() stream, err := client.InstanceWatch(ctx, &emptypb.Empty{}) @@ -280,6 +292,7 @@ func (c *InstanceServiceClient) InstanceWatch(ctx context.Context) (*api.Instanc return api.NewInstanceStream(stream), nil } +// InstanceReplace replaces an instance with a new one. func (c *InstanceServiceClient) InstanceReplace(dataEngine, name, instanceType, binary string, portCount int, args, portArgs []string, terminateSignal string) (*api.Instance, error) { if name == "" || binary == "" { return nil, fmt.Errorf("failed to replace instance: missing required parameter") @@ -320,6 +333,120 @@ func (c *InstanceServiceClient) InstanceReplace(dataEngine, name, instanceType, return api.RPCToInstance(p), nil } +// InstanceSuspend suspends an instance. +func (c *InstanceServiceClient) InstanceSuspend(dataEngine, name, instanceType string) error { + if name == "" { + return fmt.Errorf("failed to suspend instance: missing required parameter name") + } + + driver, ok := rpc.DataEngine_value[getDataEngine(dataEngine)] + if !ok { + return fmt.Errorf("failed to suspend instance: invalid data engine %v", dataEngine) + } + + client := c.getControllerServiceClient() + ctx, cancel := context.WithTimeout(context.Background(), types.GRPCServiceTimeout) + defer cancel() + + _, err := client.InstanceSuspend(ctx, &rpc.InstanceSuspendRequest{ + Name: name, + Type: instanceType, + DataEngine: rpc.DataEngine(driver), + }) + if err != nil { + return errors.Wrapf(err, "failed to suspend instance %v", name) + } + + return nil +} + +// InstanceResume suspends an instance. +func (c *InstanceServiceClient) InstanceResume(dataEngine, name, instanceType string) error { + if name == "" { + return fmt.Errorf("failed to resume instance: missing required parameter name") + } + + driver, ok := rpc.DataEngine_value[getDataEngine(dataEngine)] + if !ok { + return fmt.Errorf("failed to resume instance: invalid data engine %v", dataEngine) + } + + client := c.getControllerServiceClient() + ctx, cancel := context.WithTimeout(context.Background(), types.GRPCServiceTimeout) + defer cancel() + + _, err := client.InstanceResume(ctx, &rpc.InstanceResumeRequest{ + Name: name, + Type: instanceType, + DataEngine: rpc.DataEngine(driver), + }) + if err != nil { + return errors.Wrapf(err, "failed to resume instance %v", name) + } + + return nil +} + +// InstanceSwitchOverTarget switches over the target for an instance. +func (c *InstanceServiceClient) InstanceSwitchOverTarget(dataEngine, name, instanceType, targetAddress string) error { + if name == "" { + return fmt.Errorf("failed to switch over target for instance: missing required parameter name") + } + + if targetAddress == "" { + return fmt.Errorf("failed to switch over target for instance: missing required parameter target address") + } + + driver, ok := rpc.DataEngine_value[getDataEngine(dataEngine)] + if !ok { + return fmt.Errorf("failed to switch over target instance: invalid data engine %v", dataEngine) + } + + client := c.getControllerServiceClient() + ctx, cancel := context.WithTimeout(context.Background(), types.GRPCServiceTimeout) + defer cancel() + + _, err := client.InstanceSwitchOverTarget(ctx, &rpc.InstanceSwitchOverTargetRequest{ + Name: name, + Type: instanceType, + DataEngine: rpc.DataEngine(driver), + TargetAddress: targetAddress, + }) + if err != nil { + return errors.Wrapf(err, "failed to switch over target for instance %v", name) + } + + return nil +} + +// InstanceDeleteTarget delete target for an instance. +func (c *InstanceServiceClient) InstanceDeleteTarget(dataEngine, name, instanceType string) error { + if name == "" { + return fmt.Errorf("failed to delete target for instance: missing required parameter name") + } + + driver, ok := rpc.DataEngine_value[getDataEngine(dataEngine)] + if !ok { + return fmt.Errorf("failed to delete target instance: invalid data engine %v", dataEngine) + } + + client := c.getControllerServiceClient() + ctx, cancel := context.WithTimeout(context.Background(), types.GRPCServiceTimeout) + defer cancel() + + _, err := client.InstanceDeleteTarget(ctx, &rpc.InstanceDeleteTargetRequest{ + Name: name, + Type: instanceType, + DataEngine: rpc.DataEngine(driver), + }) + if err != nil { + return errors.Wrapf(err, "failed to delete target for instance %v", name) + } + + return nil +} + +// InstanceResume resumes an instance. func (c *InstanceServiceClient) VersionGet() (*meta.VersionOutput, error) { client := c.getControllerServiceClient() ctx, cancel := context.WithTimeout(context.Background(), types.GRPCServiceTimeout) @@ -343,6 +470,7 @@ func (c *InstanceServiceClient) VersionGet() (*meta.VersionOutput, error) { }, nil } +// LogSetLevel sets the log level of the service. func (c *InstanceServiceClient) LogSetLevel(dataEngine, service, level string) error { client := c.getControllerServiceClient() ctx, cancel := context.WithTimeout(context.Background(), types.GRPCServiceTimeout) @@ -360,6 +488,7 @@ func (c *InstanceServiceClient) LogSetLevel(dataEngine, service, level string) e return err } +// LogSetFlags sets the log flags of the service.x func (c *InstanceServiceClient) LogSetFlags(dataEngine, service, flags string) error { client := c.getControllerServiceClient() ctx, cancel := context.WithTimeout(context.Background(), types.GRPCServiceTimeout) @@ -377,6 +506,7 @@ func (c *InstanceServiceClient) LogSetFlags(dataEngine, service, flags string) e return err } +// LogGetLevel returns the log level of the service. func (c *InstanceServiceClient) LogGetLevel(dataEngine, service string) (string, error) { client := c.getControllerServiceClient() ctx, cancel := context.WithTimeout(context.Background(), types.GRPCServiceTimeout) @@ -396,6 +526,7 @@ func (c *InstanceServiceClient) LogGetLevel(dataEngine, service string) (string, return resp.Level, nil } +// LogGetFlags returns the log flags of the service. func (c *InstanceServiceClient) LogGetFlags(dataEngine, service string) (string, error) { client := c.getControllerServiceClient() ctx, cancel := context.WithTimeout(context.Background(), types.GRPCServiceTimeout) diff --git a/vendor/modules.txt b/vendor/modules.txt index 3d767fdd5d..3d3887cb82 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -230,7 +230,7 @@ github.com/longhorn/backing-image-manager/pkg/client github.com/longhorn/backing-image-manager/pkg/meta github.com/longhorn/backing-image-manager/pkg/types github.com/longhorn/backing-image-manager/pkg/util -# github.com/longhorn/backupstore v0.0.0-20240706152841-78e2c8892f4e +# github.com/longhorn/backupstore v0.0.0-20240709004445-1cadf9073de3 ## explicit; go 1.22.0 github.com/longhorn/backupstore github.com/longhorn/backupstore/backupbackingimage @@ -269,7 +269,7 @@ github.com/longhorn/longhorn-engine/pkg/meta github.com/longhorn/longhorn-engine/pkg/replica/client github.com/longhorn/longhorn-engine/pkg/types github.com/longhorn/longhorn-engine/pkg/util -# github.com/longhorn/longhorn-instance-manager v1.7.0-dev.0.20240707105202-1a2fb0b7ea9e +# github.com/longhorn/longhorn-instance-manager v1.7.0-dev.0.20240709072210-84ba8e974de0 ## explicit; go 1.22.2 github.com/longhorn/longhorn-instance-manager/pkg/api github.com/longhorn/longhorn-instance-manager/pkg/client