Skip to content

Commit 7dc26e5

Browse files
authored
refactor(gateway/client): move use client from akash-api (#289)
refs akash-network/support#320 Signed-off-by: Artur Troian <[email protected]> Co-authored-by: Artur Troian <[email protected]>
1 parent bd89bac commit 7dc26e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1860
-1883
lines changed

bidengine/service.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66

7+
apclient "github.com/akash-network/akash-api/go/provider/client"
78
"github.com/boz/go-lifecycle"
89
sdkquery "github.com/cosmos/cosmos-sdk/types/query"
910
"github.com/prometheus/client_golang/prometheus"
@@ -34,7 +35,7 @@ var ErrNotRunning = errors.New("not running")
3435

3536
// StatusClient interface predefined with Status method
3637
type StatusClient interface {
37-
Status(context.Context) (*Status, error)
38+
Status(context.Context) (*apclient.BidEngineStatus, error)
3839
StatusV1(ctx context.Context) (*provider.BidEngineStatus, error)
3940
}
4041

@@ -81,7 +82,7 @@ func NewService(
8182
cluster: cluster,
8283
bus: bus,
8384
sub: sub,
84-
statusch: make(chan chan<- *Status),
85+
statusch: make(chan chan<- *apclient.BidEngineStatus),
8586
orders: make(map[string]*order),
8687
drainch: make(chan *order),
8788
ordersch: make(chan []mtypes.OrderID, 1000),
@@ -111,7 +112,7 @@ type service struct {
111112
bus pubsub.Bus
112113
sub pubsub.Subscriber
113114

114-
statusch chan chan<- *Status
115+
statusch chan chan<- *apclient.BidEngineStatus
115116
orders map[string]*order
116117
drainch chan *order
117118
ordersch chan []mtypes.OrderID
@@ -133,8 +134,8 @@ func (s *service) Done() <-chan struct{} {
133134
return s.lc.Done()
134135
}
135136

136-
func (s *service) Status(ctx context.Context) (*Status, error) {
137-
ch := make(chan *Status, 1)
137+
func (s *service) Status(ctx context.Context) (*apclient.BidEngineStatus, error) {
138+
ch := make(chan *apclient.BidEngineStatus, 1)
138139

139140
select {
140141
case <-s.lc.Done():
@@ -286,7 +287,7 @@ loop:
286287
trySignal()
287288
}
288289
case ch := <-s.statusch:
289-
ch <- &Status{
290+
ch <- &apclient.BidEngineStatus{
290291
Orders: uint32(len(s.orders)), // nolint: gosec
291292
}
292293
case order := <-s.drainch:

bidengine/types.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
11
package bidengine
2-
3-
// Status stores orders
4-
type Status struct {
5-
Orders uint32 `json:"orders"`
6-
}

cluster/client.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"sync"
1010
"time"
1111

12+
apclient "github.com/akash-network/akash-api/go/provider/client"
1213
"github.com/pkg/errors"
1314
eventsv1 "k8s.io/api/events/v1"
1415
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -43,11 +44,11 @@ var _ Client = (*nullClient)(nil)
4344

4445
//go:generate mockery --name ReadClient
4546
type ReadClient interface {
46-
LeaseStatus(context.Context, mtypes.LeaseID) (map[string]*ctypes.ServiceStatus, error)
47-
ForwardedPortStatus(context.Context, mtypes.LeaseID) (map[string][]ctypes.ForwardedPortStatus, error)
47+
LeaseStatus(context.Context, mtypes.LeaseID) (map[string]*apclient.ServiceStatus, error)
48+
ForwardedPortStatus(context.Context, mtypes.LeaseID) (map[string][]apclient.ForwardedPortStatus, error)
4849
LeaseEvents(context.Context, mtypes.LeaseID, string, bool) (ctypes.EventsWatcher, error)
4950
LeaseLogs(context.Context, mtypes.LeaseID, string, bool, *int64) ([]*ctypes.ServiceLog, error)
50-
ServiceStatus(context.Context, mtypes.LeaseID, string) (*ctypes.ServiceStatus, error)
51+
ServiceStatus(context.Context, mtypes.LeaseID, string) (*apclient.ServiceStatus, error)
5152

5253
AllHostnames(context.Context) ([]chostname.ActiveHostname, error)
5354
GetManifestGroup(context.Context, mtypes.LeaseID) (bool, crd.ManifestGroup, error)
@@ -178,11 +179,11 @@ func (c *nullClient) Deploy(ctx context.Context, deployment ctypes.IDeployment)
178179
return nil
179180
}
180181

181-
func (*nullClient) ForwardedPortStatus(context.Context, mtypes.LeaseID) (map[string][]ctypes.ForwardedPortStatus, error) {
182+
func (*nullClient) ForwardedPortStatus(_ context.Context, _ mtypes.LeaseID) (map[string][]apclient.ForwardedPortStatus, error) {
182183
return nil, errNotImplemented
183184
}
184185

185-
func (c *nullClient) LeaseStatus(_ context.Context, lid mtypes.LeaseID) (map[string]*ctypes.ServiceStatus, error) {
186+
func (c *nullClient) LeaseStatus(_ context.Context, lid mtypes.LeaseID) (map[string]*apclient.ServiceStatus, error) {
186187
c.mtx.Lock()
187188
defer c.mtx.Unlock()
188189

@@ -191,9 +192,9 @@ func (c *nullClient) LeaseStatus(_ context.Context, lid mtypes.LeaseID) (map[str
191192
return nil, nil
192193
}
193194

194-
resp := make(map[string]*ctypes.ServiceStatus)
195+
resp := make(map[string]*apclient.ServiceStatus)
195196
for _, svc := range lease.group.Services {
196-
resp[svc.Name] = &ctypes.ServiceStatus{
197+
resp[svc.Name] = &apclient.ServiceStatus{
197198
Name: svc.Name,
198199
Available: int32(svc.Count), // nolint: gosec
199200
Total: int32(svc.Count), // nolint: gosec
@@ -264,7 +265,7 @@ func (c *nullClient) LeaseEvents(ctx context.Context, lid mtypes.LeaseID, _ stri
264265
return feed, nil
265266
}
266267

267-
func (c *nullClient) ServiceStatus(_ context.Context, _ mtypes.LeaseID, _ string) (*ctypes.ServiceStatus, error) {
268+
func (c *nullClient) ServiceStatus(_ context.Context, _ mtypes.LeaseID, _ string) (*apclient.ServiceStatus, error) {
268269
return nil, nil
269270
}
270271

cluster/inventory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"sync/atomic"
99
"time"
1010

11-
inventoryV1 "github.com/akash-network/akash-api/go/inventory/v1"
12-
provider "github.com/akash-network/akash-api/go/provider/v1"
1311
"github.com/boz/go-lifecycle"
1412
sdk "github.com/cosmos/cosmos-sdk/types"
1513
"github.com/desertbit/timer"
@@ -18,9 +16,11 @@ import (
1816
"github.com/tendermint/tendermint/libs/log"
1917
tpubsub "github.com/troian/pubsub"
2018

19+
inventoryV1 "github.com/akash-network/akash-api/go/inventory/v1"
2120
dtypes "github.com/akash-network/akash-api/go/node/deployment/v1beta3"
2221
mtypes "github.com/akash-network/akash-api/go/node/market/v1beta4"
2322
atypes "github.com/akash-network/akash-api/go/node/types/v1beta3"
23+
provider "github.com/akash-network/akash-api/go/provider/v1"
2424

2525
"github.com/akash-network/node/pubsub"
2626
sdlutil "github.com/akash-network/node/sdl/util"

cluster/kube/client.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
mapi "github.com/akash-network/akash-api/go/manifest/v2beta2"
1414
dtypes "github.com/akash-network/akash-api/go/node/deployment/v1beta3"
1515
mtypes "github.com/akash-network/akash-api/go/node/market/v1beta4"
16+
apclient "github.com/akash-network/akash-api/go/provider/client"
1617
"github.com/prometheus/client_golang/prometheus"
1718
"github.com/prometheus/client_golang/prometheus/promauto"
1819
"github.com/tendermint/tendermint/libs/log"
@@ -801,7 +802,7 @@ func (c *client) LeaseLogs(ctx context.Context, lid mtypes.LeaseID,
801802
return streams, nil
802803
}
803804

804-
func (c *client) ForwardedPortStatus(ctx context.Context, leaseID mtypes.LeaseID) (map[string][]ctypes.ForwardedPortStatus, error) {
805+
func (c *client) ForwardedPortStatus(ctx context.Context, leaseID mtypes.LeaseID) (map[string][]apclient.ForwardedPortStatus, error) {
805806
settingsI := ctx.Value(builder.SettingsKey)
806807
if nil == settingsI {
807808
return nil, kubeclienterrors.ErrNotConfiguredWithSettings
@@ -819,7 +820,7 @@ func (c *client) ForwardedPortStatus(ctx context.Context, leaseID mtypes.LeaseID
819820
return nil, fmt.Errorf("%s: %w", kubeclienterrors.ErrInternalError.Error(), err)
820821
}
821822

822-
forwardedPorts := make(map[string][]ctypes.ForwardedPortStatus)
823+
forwardedPorts := make(map[string][]apclient.ForwardedPortStatus)
823824

824825
// Search for a Kubernetes service declared as nodeport
825826
for _, service := range services.Items {
@@ -828,14 +829,14 @@ func (c *client) ForwardedPortStatus(ctx context.Context, leaseID mtypes.LeaseID
828829
deploymentName := serviceName[0 : len(serviceName)-len(builder.SuffixForNodePortServiceName)]
829830

830831
if 0 != len(service.Spec.Ports) {
831-
portsForDeployment := make([]ctypes.ForwardedPortStatus, 0, len(service.Spec.Ports))
832+
portsForDeployment := make([]apclient.ForwardedPortStatus, 0, len(service.Spec.Ports))
832833
for _, port := range service.Spec.Ports {
833834
// Check if the service is exposed via NodePort mechanism in the cluster
834835
// This is a random port chosen by the cluster when the deployment is created
835836
nodePort := port.NodePort
836837
if nodePort > 0 {
837838
// Record the actual port inside the container that is exposed
838-
v := ctypes.ForwardedPortStatus{
839+
v := apclient.ForwardedPortStatus{
839840
Host: settings.ClusterPublicHostname,
840841
Port: uint16(port.TargetPort.IntVal), // nolint: gosec
841842
ExternalPort: uint16(nodePort), // nolint: gosec
@@ -865,7 +866,7 @@ func (c *client) ForwardedPortStatus(ctx context.Context, leaseID mtypes.LeaseID
865866
}
866867

867868
// LeaseStatus todo: limit number of results and do pagination / streaming
868-
func (c *client) LeaseStatus(ctx context.Context, lid mtypes.LeaseID) (map[string]*ctypes.ServiceStatus, error) {
869+
func (c *client) LeaseStatus(ctx context.Context, lid mtypes.LeaseID) (map[string]*apclient.ServiceStatus, error) {
869870
settingsI := ctx.Value(builder.SettingsKey)
870871
if nil == settingsI {
871872
return nil, kubeclienterrors.ErrNotConfiguredWithSettings
@@ -904,7 +905,7 @@ func (c *client) LeaseStatus(ctx context.Context, lid mtypes.LeaseID) (map[strin
904905
return serviceStatus, nil
905906
}
906907

907-
func (c *client) ServiceStatus(ctx context.Context, lid mtypes.LeaseID, name string) (*ctypes.ServiceStatus, error) {
908+
func (c *client) ServiceStatus(ctx context.Context, lid mtypes.LeaseID, name string) (*apclient.ServiceStatus, error) {
908909
if err := c.leaseExists(ctx, lid); err != nil {
909910
return nil, err
910911
}
@@ -919,7 +920,7 @@ func (c *client) ServiceStatus(ctx context.Context, lid mtypes.LeaseID, name str
919920
return nil, kubeclienterrors.ErrNoManifestForLease
920921
}
921922

922-
var result *ctypes.ServiceStatus
923+
var result *apclient.ServiceStatus
923924

924925
var svc *crd.ManifestService
925926

@@ -959,7 +960,7 @@ func (c *client) ServiceStatus(ctx context.Context, lid mtypes.LeaseID, name str
959960
return nil, kubeclienterrors.ErrNoDeploymentForLease
960961
}
961962

962-
result = &ctypes.ServiceStatus{
963+
result = &apclient.ServiceStatus{
963964
Name: deployment.Name,
964965
Available: deployment.Status.AvailableReplicas,
965966
Total: deployment.Status.Replicas,
@@ -984,7 +985,7 @@ func (c *client) ServiceStatus(ctx context.Context, lid mtypes.LeaseID, name str
984985
return nil, kubeclienterrors.ErrNoDeploymentForLease
985986
}
986987

987-
result = &ctypes.ServiceStatus{
988+
result = &apclient.ServiceStatus{
988989
Name: statefulset.Name,
989990
Available: statefulset.Status.CurrentReplicas,
990991
Total: statefulset.Status.Replicas,
@@ -1073,7 +1074,7 @@ func (c *client) leaseExists(ctx context.Context, lid mtypes.LeaseID) error {
10731074
return nil
10741075
}
10751076

1076-
func (c *client) deploymentsForLease(ctx context.Context, lid mtypes.LeaseID) (map[string]*ctypes.ServiceStatus, error) {
1077+
func (c *client) deploymentsForLease(ctx context.Context, lid mtypes.LeaseID) (map[string]*apclient.ServiceStatus, error) {
10771078
if err := c.leaseExists(ctx, lid); err != nil {
10781079
return nil, err
10791080
}
@@ -1096,11 +1097,11 @@ func (c *client) deploymentsForLease(ctx context.Context, lid mtypes.LeaseID) (m
10961097
return nil, fmt.Errorf("%s: %w", kubeclienterrors.ErrInternalError.Error(), err)
10971098
}
10981099

1099-
serviceStatus := make(map[string]*ctypes.ServiceStatus)
1100+
serviceStatus := make(map[string]*apclient.ServiceStatus)
11001101

11011102
if deployments != nil {
11021103
for _, deployment := range deployments.Items {
1103-
serviceStatus[deployment.Name] = &ctypes.ServiceStatus{
1104+
serviceStatus[deployment.Name] = &apclient.ServiceStatus{
11041105
Name: deployment.Name,
11051106
Available: deployment.Status.AvailableReplicas,
11061107
Total: deployment.Status.Replicas,
@@ -1115,7 +1116,7 @@ func (c *client) deploymentsForLease(ctx context.Context, lid mtypes.LeaseID) (m
11151116

11161117
if statefulsets != nil {
11171118
for _, statefulset := range statefulsets.Items {
1118-
serviceStatus[statefulset.Name] = &ctypes.ServiceStatus{
1119+
serviceStatus[statefulset.Name] = &apclient.ServiceStatus{
11191120
Name: statefulset.Name,
11201121
Available: statefulset.Status.CurrentReplicas,
11211122
Total: statefulset.Status.Replicas,

cluster/kube/operators/clients/metallb/mocks/metallb_client.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)