Skip to content

Commit

Permalink
Use client that accepts ProxyEngineRequest instead of address
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Weber <eric.weber@suse.com>
  • Loading branch information
ejweber committed May 11, 2023
1 parent a7dd20c commit 66d7f01
Show file tree
Hide file tree
Showing 17 changed files with 362 additions and 436 deletions.
15 changes: 14 additions & 1 deletion engineapi/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"golang.org/x/net/context"

imclient "github.com/longhorn/longhorn-instance-manager/pkg/client"
"github.com/longhorn/longhorn-instance-manager/pkg/imrpc"
imutil "github.com/longhorn/longhorn-instance-manager/pkg/util"

"github.com/longhorn/longhorn-manager/datastore"
Expand Down Expand Up @@ -132,6 +133,18 @@ func (p *Proxy) DirectToURL(e *longhorn.Engine) string {
return imutil.GetURL(e.Status.StorageIP, e.Status.Port)
}

func (p *Proxy) ToProxyEngineRequest(e *longhorn.Engine) imrpc.ProxyEngineRequest {
if e == nil {
p.logger.Debug("BUG: cannot get engine client proxy re-direct details with nil engine object")
}

return imrpc.ProxyEngineRequest{
Address: imutil.GetURL(e.Status.StorageIP, e.Status.Port),
VolumeName: e.Spec.VolumeName,
InstanceName: e.ObjectMeta.Name,
}
}

func (p *Proxy) VersionGet(e *longhorn.Engine, clientOnly bool) (version *EngineVersion, err error) {
recvClientVersion := p.grpcClient.ClientVersionGet()
clientVersion := (*longhorn.EngineVersionDetails)(&recvClientVersion)
Expand All @@ -142,7 +155,7 @@ func (p *Proxy) VersionGet(e *longhorn.Engine, clientOnly bool) (version *Engine
}, nil
}

recvServerVersion, err := p.grpcClient.ServerVersionGet(p.DirectToURL(e))
recvServerVersion, err := p.grpcClient.ServerVersionGet(p.ToProxyEngineRequest(e))
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions engineapi/proxy_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (p *Proxy) SnapshotBackup(e *longhorn.Engine, snapshotName, backupName, bac
return "", "", err
}

backupID, replicaAddress, err := p.grpcClient.SnapshotBackup(p.DirectToURL(e),
backupID, replicaAddress, err := p.grpcClient.SnapshotBackup(p.ToProxyEngineRequest(e),
backupName, snapshotName, backupTarget, backingImageName, backingImageChecksum,
compressionMethod, concurrentLimit, labels, credentialEnv,
)
Expand All @@ -49,7 +49,7 @@ func (p *Proxy) SnapshotBackup(e *longhorn.Engine, snapshotName, backupName, bac
}

func (p *Proxy) SnapshotBackupStatus(e *longhorn.Engine, backupName, replicaAddress string) (status *longhorn.EngineBackupStatus, err error) {
recv, err := p.grpcClient.SnapshotBackupStatus(p.DirectToURL(e), backupName, replicaAddress)
recv, err := p.grpcClient.SnapshotBackupStatus(p.ToProxyEngineRequest(e), backupName, replicaAddress)
if err != nil {
return nil, err
}
Expand All @@ -67,11 +67,11 @@ func (p *Proxy) BackupRestore(e *longhorn.Engine, backupTarget, backupName, back
return err
}

return p.grpcClient.BackupRestore(p.DirectToURL(e), backupURL, backupTarget, backupVolumeName, envs, concurrentLimit)
return p.grpcClient.BackupRestore(p.ToProxyEngineRequest(e), backupURL, backupTarget, backupVolumeName, envs, concurrentLimit)
}

func (p *Proxy) BackupRestoreStatus(e *longhorn.Engine) (status map[string]*longhorn.RestoreStatus, err error) {
recv, err := p.grpcClient.BackupRestoreStatus(p.DirectToURL(e))
recv, err := p.grpcClient.BackupRestoreStatus(p.ToProxyEngineRequest(e))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion engineapi/proxy_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func (p *Proxy) MetricsGet(e *longhorn.Engine) (*Metrics, error) {
metrics, err := p.grpcClient.MetricsGet(p.DirectToURL(e))
metrics, err := p.grpcClient.MetricsGet(p.ToProxyEngineRequest(e))
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions engineapi/proxy_replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (
)

func (p *Proxy) ReplicaAdd(e *longhorn.Engine, address string, restore, fastSync bool, replicaFileSyncHTTPClientTimeout int64) (err error) {
return p.grpcClient.ReplicaAdd(p.DirectToURL(e), address, restore, e.Spec.VolumeSize, e.Status.CurrentSize, int(replicaFileSyncHTTPClientTimeout), fastSync)
return p.grpcClient.ReplicaAdd(p.ToProxyEngineRequest(e), address, restore, e.Spec.VolumeSize, e.Status.CurrentSize, int(replicaFileSyncHTTPClientTimeout), fastSync)
}

func (p *Proxy) ReplicaRemove(e *longhorn.Engine, address string) (err error) {
return p.grpcClient.ReplicaRemove(p.DirectToURL(e), address)
return p.grpcClient.ReplicaRemove(p.ToProxyEngineRequest(e), address)
}

func (p *Proxy) ReplicaList(e *longhorn.Engine) (replicas map[string]*Replica, err error) {
resp, err := p.grpcClient.ReplicaList(p.DirectToURL(e))
resp, err := p.grpcClient.ReplicaList(p.ToProxyEngineRequest(e))
if err != nil {
return nil, err
}
Expand All @@ -33,7 +33,7 @@ func (p *Proxy) ReplicaList(e *longhorn.Engine) (replicas map[string]*Replica, e
}

func (p *Proxy) ReplicaRebuildStatus(e *longhorn.Engine) (status map[string]*longhorn.RebuildStatus, err error) {
recv, err := p.grpcClient.ReplicaRebuildingStatus(p.DirectToURL(e))
recv, err := p.grpcClient.ReplicaRebuildingStatus(p.ToProxyEngineRequest(e))
if err != nil {
return nil, err
}
Expand All @@ -50,13 +50,13 @@ func (p *Proxy) ReplicaRebuildVerify(e *longhorn.Engine, url string) (err error)
return err
}

return p.grpcClient.ReplicaVerifyRebuild(p.DirectToURL(e), url)
return p.grpcClient.ReplicaVerifyRebuild(p.ToProxyEngineRequest(e), url)
}

func (p *Proxy) ReplicaModeUpdate(e *longhorn.Engine, url, mode string) (err error) {
if err := ValidateReplicaURL(url); err != nil {
return err
}

return p.grpcClient.ReplicaModeUpdate(p.DirectToURL(e), url, mode)
return p.grpcClient.ReplicaModeUpdate(p.ToProxyEngineRequest(e), url, mode)
}
20 changes: 10 additions & 10 deletions engineapi/proxy_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
)

func (p *Proxy) SnapshotCreate(e *longhorn.Engine, name string, labels map[string]string) (string, error) {
return p.grpcClient.VolumeSnapshot(p.DirectToURL(e), name, labels)
return p.grpcClient.VolumeSnapshot(p.ToProxyEngineRequest(e), name, labels)
}

func (p *Proxy) SnapshotList(e *longhorn.Engine) (snapshots map[string]*longhorn.SnapshotInfo, err error) {
recv, err := p.grpcClient.SnapshotList(p.DirectToURL(e))
recv, err := p.grpcClient.SnapshotList(p.ToProxyEngineRequest(e))
if err != nil {
return nil, err
}
Expand All @@ -31,11 +31,11 @@ func (p *Proxy) SnapshotGet(e *longhorn.Engine, name string) (snapshot *longhorn
}

func (p *Proxy) SnapshotClone(e *longhorn.Engine, name, fromController string, fileSyncHTTPClientTimeout int64) (err error) {
return p.grpcClient.SnapshotClone(p.DirectToURL(e), name, fromController, int(fileSyncHTTPClientTimeout))
return p.grpcClient.SnapshotClone(p.ToProxyEngineRequest(e), name, fromController, int(fileSyncHTTPClientTimeout))
}

func (p *Proxy) SnapshotCloneStatus(e *longhorn.Engine) (status map[string]*longhorn.SnapshotCloneStatus, err error) {
recv, err := p.grpcClient.SnapshotCloneStatus(p.DirectToURL(e))
recv, err := p.grpcClient.SnapshotCloneStatus(p.ToProxyEngineRequest(e))
if err != nil {
return nil, err
}
Expand All @@ -48,15 +48,15 @@ func (p *Proxy) SnapshotCloneStatus(e *longhorn.Engine) (status map[string]*long
}

func (p *Proxy) SnapshotRevert(e *longhorn.Engine, name string) (err error) {
return p.grpcClient.SnapshotRevert(p.DirectToURL(e), name)
return p.grpcClient.SnapshotRevert(p.ToProxyEngineRequest(e), name)
}

func (p *Proxy) SnapshotPurge(e *longhorn.Engine) (err error) {
return p.grpcClient.SnapshotPurge(p.DirectToURL(e), true)
return p.grpcClient.SnapshotPurge(p.ToProxyEngineRequest(e), true)
}

func (p *Proxy) SnapshotPurgeStatus(e *longhorn.Engine) (status map[string]*longhorn.PurgeStatus, err error) {
recv, err := p.grpcClient.SnapshotPurgeStatus(p.DirectToURL(e))
recv, err := p.grpcClient.SnapshotPurgeStatus(p.ToProxyEngineRequest(e))
if err != nil {
return nil, err
}
Expand All @@ -69,15 +69,15 @@ func (p *Proxy) SnapshotPurgeStatus(e *longhorn.Engine) (status map[string]*long
}

func (p *Proxy) SnapshotDelete(e *longhorn.Engine, name string) (err error) {
return p.grpcClient.SnapshotRemove(p.DirectToURL(e), []string{name})
return p.grpcClient.SnapshotRemove(p.ToProxyEngineRequest(e), []string{name})
}

func (p *Proxy) SnapshotHash(e *longhorn.Engine, snapshotName string, rehash bool) error {
return p.grpcClient.SnapshotHash(p.DirectToURL(e), snapshotName, rehash)
return p.grpcClient.SnapshotHash(p.ToProxyEngineRequest(e), snapshotName, rehash)
}

func (p *Proxy) SnapshotHashStatus(e *longhorn.Engine, snapshotName string) (status map[string]*longhorn.HashStatus, err error) {
recv, err := p.grpcClient.SnapshotHashStatus(p.DirectToURL(e), snapshotName)
recv, err := p.grpcClient.SnapshotHashStatus(p.ToProxyEngineRequest(e), snapshotName)
if err != nil {
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions engineapi/proxy_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func (p *Proxy) VolumeGet(e *longhorn.Engine) (volume *Volume, err error) {
recv, err := p.grpcClient.VolumeGet(p.DirectToURL(e))
recv, err := p.grpcClient.VolumeGet(p.ToProxyEngineRequest(e))
if err != nil {
return nil, err
}
Expand All @@ -16,7 +16,7 @@ func (p *Proxy) VolumeGet(e *longhorn.Engine) (volume *Volume, err error) {
}

func (p *Proxy) VolumeExpand(e *longhorn.Engine) (err error) {
return p.grpcClient.VolumeExpand(p.DirectToURL(e), e.Spec.VolumeSize)
return p.grpcClient.VolumeExpand(p.ToProxyEngineRequest(e), e.Spec.VolumeSize)
}

func (p *Proxy) VolumeFrontendStart(e *longhorn.Engine) (err error) {
Expand All @@ -29,13 +29,13 @@ func (p *Proxy) VolumeFrontendStart(e *longhorn.Engine) (err error) {
return fmt.Errorf("cannot start empty frontend")
}

return p.grpcClient.VolumeFrontendStart(p.DirectToURL(e), frontendName)
return p.grpcClient.VolumeFrontendStart(p.ToProxyEngineRequest(e), frontendName)
}

func (p *Proxy) VolumeFrontendShutdown(e *longhorn.Engine) (err error) {
return p.grpcClient.VolumeFrontendShutdown(p.DirectToURL(e))
return p.grpcClient.VolumeFrontendShutdown(p.ToProxyEngineRequest(e))
}

func (p *Proxy) VolumeUnmapMarkSnapChainRemovedSet(e *longhorn.Engine) error {
return p.grpcClient.VolumeUnmapMarkSnapChainRemovedSet(p.DirectToURL(e), e.Spec.UnmapMarkSnapChainRemovedEnabled)
return p.grpcClient.VolumeUnmapMarkSnapChainRemovedSet(p.ToProxyEngineRequest(e), e.Spec.UnmapMarkSnapChainRemovedEnabled)
}
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ require (
github.com/longhorn/backing-image-manager v0.0.0-20220609065820-a08f7f47442f
github.com/longhorn/backupstore v0.0.0-20230505042557-0f585f513869
github.com/longhorn/go-iscsi-helper v0.0.0-20230425064248-72f136f48524
github.com/longhorn/longhorn-engine v1.4.0-rc1.0.20230505031224-c02fde759c53
github.com/longhorn/longhorn-engine v1.4.0-rc1.0.20230505045918-1f57dd9a235c
github.com/longhorn/longhorn-instance-manager v1.4.0-rc1.0.20230505033346-9228ec0ee161
github.com/longhorn/longhorn-share-manager v1.4.0-rc1.0.20230406134224-54b3892cf95a
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -149,3 +149,5 @@ require (
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
)

replace github.com/longhorn/longhorn-instance-manager => /home/eweber/longhorn-instance-manager
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,8 @@ github.com/longhorn/go-iscsi-helper v0.0.0-20210330030558-49a327fb024e/go.mod h1
github.com/longhorn/go-iscsi-helper v0.0.0-20230425064248-72f136f48524 h1:bqcufS0wAuXF0VGesCaGpim8wz0dNlTuKvgim0b9QFc=
github.com/longhorn/go-iscsi-helper v0.0.0-20230425064248-72f136f48524/go.mod h1:gjjEN5+gUyO1ooUaF7bVM0K+ZQ8vA9DiujVvoKWdT0k=
github.com/longhorn/longhorn-engine v1.2.0-preview1.0.20210818142058-32cb7dfd0630/go.mod h1:mtvBHZBmXJIHBcLL828FY5mGq4hoh7bV2EFK6LFLmhE=
github.com/longhorn/longhorn-engine v1.4.0-rc1.0.20230505031224-c02fde759c53 h1:vh0JO492cjwgOLmjePhEN8sf6qKATm0vW7ei29fvcFg=
github.com/longhorn/longhorn-engine v1.4.0-rc1.0.20230505031224-c02fde759c53/go.mod h1:CWCJm/D5gFOAUCOju0k8gm6B4gzMdQObrtMVuS5Y2Jg=
github.com/longhorn/longhorn-instance-manager v1.4.0-rc1.0.20230505033346-9228ec0ee161 h1:2LnKglHI07BnA74CpLafvmg8OpiznB+1cvF4kXjgqbk=
github.com/longhorn/longhorn-instance-manager v1.4.0-rc1.0.20230505033346-9228ec0ee161/go.mod h1:UwYEONhsNS8IK6WFknlpExs+EiqohVqgcIHycRFa9Z4=
github.com/longhorn/longhorn-engine v1.4.0-rc1.0.20230505045918-1f57dd9a235c h1:Qv63ScMU5vJITN3+DQ4aQsZ12/PQsAgnG+h2f+Idm1w=
github.com/longhorn/longhorn-engine v1.4.0-rc1.0.20230505045918-1f57dd9a235c/go.mod h1:JAA889pNTP/q5T0o6oEIcv+rYYlmsxSbLq0sQI/2UKU=
github.com/longhorn/longhorn-share-manager v1.4.0-rc1.0.20230406134224-54b3892cf95a h1:X0L/E7pTKg6r6nRrAbHVEk2rdyWW/TC+8Z/BAuzi7ns=
github.com/longhorn/longhorn-share-manager v1.4.0-rc1.0.20230406134224-54b3892cf95a/go.mod h1:15jIjFqyOr95VPRtZVJ7up6wseYpI/9mZByQIANc9Ts=
github.com/longhorn/nsfilelock v0.0.0-20200723175406-fa7c83ad0003/go.mod h1:0CLeXlf59Lg6C0kjLSDf47ft73Dh37CwymYRKWwAn04=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 66d7f01

Please sign in to comment.