Skip to content

Commit

Permalink
status api
Browse files Browse the repository at this point in the history
fixes: #254
  • Loading branch information
aastein authored Jun 27, 2018
1 parent ec20056 commit cb48a13
Show file tree
Hide file tree
Showing 14 changed files with 476 additions and 227 deletions.
24 changes: 13 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,19 @@ kubetypes:
--gogo_out=plugins=grpc:. $<

mocks:
mockery -case=underscore -dir query -output query/mocks -name Client
mockery -case=underscore -dir txutil -output txutil/mocks -name Client
mockery -case=underscore -dir app/market -output app/market/mocks -name Client
mockery -case=underscore -dir app/market -output app/market/mocks -name Engine
mockery -case=underscore -dir app/market -output app/market/mocks -name Facilitator
mockery -case=underscore -dir marketplace -output marketplace/mocks -name Handler
mockery -case=underscore -dir provider/cluster -output provider/cluster/mocks -name Client
mockery -case=underscore -dir provider/cluster -output provider/cluster/mocks -name Cluster
mockery -case=underscore -dir provider/cluster -output provider/cluster/mocks -name Deployment
mockery -case=underscore -dir provider/cluster -output provider/cluster/mocks -name Reservation
mockery -case=underscore -dir provider/manifest -output provider/manifest/mocks -name Handler
mockery -case=underscore -dir query -output query/mocks -name Client
mockery -case=underscore -dir txutil -output txutil/mocks -name Client
mockery -case=underscore -dir app/market -output app/market/mocks -name Client
mockery -case=underscore -dir app/market -output app/market/mocks -name Engine
mockery -case=underscore -dir app/market -output app/market/mocks -name Facilitator
mockery -case=underscore -dir marketplace -output marketplace/mocks -name Handler
mockery -case=underscore -dir provider/cluster -output provider/cluster/mocks -name Client
mockery -case=underscore -dir provider/cluster -output provider/cluster/mocks -name Cluster
mockery -case=underscore -dir provider/cluster -output provider/cluster/mocks -name Deployment
mockery -case=underscore -dir provider/cluster -output provider/cluster/mocks -name Reservation
mockery -case=underscore -dir provider/cluster/kube -output provider/cluster/kube/mocks -name Client
mockery -case=underscore -dir provider/manifest -output provider/manifest/mocks -name Handler


gofmt:
find . -not -path './vendor*' -name '*.go' -type f | \
Expand Down
116 changes: 59 additions & 57 deletions cmd/akash/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/ovrclk/akash/keys"
"github.com/ovrclk/akash/manifest"
"github.com/ovrclk/akash/marketplace"
mhttp "github.com/ovrclk/akash/provider/manifest/http"
http "github.com/ovrclk/akash/provider/http"
"github.com/ovrclk/akash/sdl"
"github.com/ovrclk/akash/types"
. "github.com/ovrclk/akash/util"
Expand All @@ -27,7 +27,8 @@ func deploymentCommand() *cobra.Command {

cmd.AddCommand(createDeploymentCommand())
cmd.AddCommand(closeDeploymentCommand())
cmd.AddCommand(sendManifestCommand())
// todo: this command is not working
// cmd.AddCommand(sendManifestCommand())

return cmd
}
Expand Down Expand Up @@ -121,7 +122,7 @@ func createDeployment(session session.Session, cmd *cobra.Command, args []string

// send manifest over http to provider uri
fmt.Printf("Sending manifest to %v...\n", prov.HostURI)
err = mhttp.Send(mani, txclient.Signer(), prov, tx.Deployment)
err = http.SendManifest(mani, txclient.Signer(), prov, tx.Deployment)
if err != nil {
fmt.Printf("ERROR: %v", err)
}
Expand Down Expand Up @@ -182,57 +183,58 @@ func closeDeployment(session session.Session, cmd *cobra.Command, args []string)
return nil
}

func sendManifestCommand() *cobra.Command {

cmd := &cobra.Command{
Use: "sendmani <manifest> <deployment>",
Short: "send manifest to all deployment providers",
Args: cobra.ExactArgs(2),
RunE: session.WithSession(
session.RequireKey(session.RequireNode(sendManifest))),
}

session.AddFlagNode(cmd, cmd.Flags())
session.AddFlagKey(cmd, cmd.Flags())

return cmd
}

func sendManifest(session session.Session, cmd *cobra.Command, args []string) error {
signer, _, err := session.Signer()
if err != nil {
return err
}

sdl, err := sdl.ReadFile(args[0])
if err != nil {
return err
}

mani, err := sdl.Manifest()
if err != nil {
return err
}

depAddr, err := keys.ParseDeploymentPath(args[1])
if err != nil {
return err
}

leases, err := session.QueryClient().DeploymentLeases(session.Ctx(), depAddr.ID())
if err != nil {
return err
}

for _, lease := range leases.Items {
provider, err := session.QueryClient().Provider(session.Ctx(), lease.Provider)
if err != nil {
return err
}
err = mhttp.Send(mani, signer, provider, lease.Deployment)
if err != nil {
return err
}
}
return nil
}
// todo: this command is not working
// func sendManifestCommand() *cobra.Command {

// cmd := &cobra.Command{
// Use: "sendmani <manifest> <deployment>",
// Short: "send manifest to all deployment providers",
// Args: cobra.ExactArgs(2),
// RunE: session.WithSession(
// session.RequireKey(session.RequireNode(sendManifest))),
// }

// session.AddFlagNode(cmd, cmd.Flags())
// session.AddFlagKey(cmd, cmd.Flags())

// return cmd
// }

// func sendManifest(session session.Session, cmd *cobra.Command, args []string) error {
// signer, _, err := session.Signer()
// if err != nil {
// return err
// }

// sdl, err := sdl.ReadFile(args[0])
// if err != nil {
// return err
// }

// mani, err := sdl.Manifest()
// if err != nil {
// return err
// }

// depAddr, err := keys.ParseDeploymentPath(args[1])
// if err != nil {
// return err
// }

// leases, err := session.QueryClient().DeploymentLeases(session.Ctx(), depAddr.ID())
// if err != nil {
// return err
// }

// for _, lease := range leases.Items {
// provider, err := session.QueryClient().Provider(session.Ctx(), lease.Provider)
// if err != nil {
// return err
// }
// err = http.SendManifest(mani, signer, provider, lease.Deployment)
// if err != nil {
// return err
// }
// }
// return nil
// }
4 changes: 2 additions & 2 deletions cmd/akash/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/ovrclk/akash/provider/cluster"
"github.com/ovrclk/akash/provider/cluster/kube"
"github.com/ovrclk/akash/provider/event"
"github.com/ovrclk/akash/provider/manifest/http"
"github.com/ovrclk/akash/provider/http"
psession "github.com/ovrclk/akash/provider/session"
"github.com/ovrclk/akash/types"
ptype "github.com/ovrclk/akash/types/provider"
Expand Down Expand Up @@ -198,7 +198,7 @@ func doProviderRunCommand(session session.Session, cmd *cobra.Command, args []st

go func() {
defer cancel()
errch <- http.RunServer(ctx, session.Log(), "3001", service.ManifestHandler())
errch <- http.RunServer(ctx, session.Log(), "3001", service.ManifestHandler(), cclient)
}()

var reterr error
Expand Down
15 changes: 14 additions & 1 deletion provider/cluster/client.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package cluster

import "github.com/ovrclk/akash/types"
import (
"github.com/ovrclk/akash/types"
"k8s.io/api/apps/v1"
)

type Client interface {
Deploy(types.LeaseID, *types.ManifestGroup) error
Teardown(types.LeaseID) error

Deployments() ([]Deployment, error)
KubeDeployments(types.LeaseID) (*v1.DeploymentList, error)
KubeDeployment(types.LeaseID, string) (*v1.Deployment, error)
}

type Deployment interface {
Expand All @@ -24,6 +29,14 @@ func (nullClient) Deploy(_ types.LeaseID, _ *types.ManifestGroup) error {
return nil
}

func (nullClient) KubeDeployments(_ types.LeaseID) (*v1.DeploymentList, error) {
return nil, nil
}

func (nullClient) KubeDeployment(_ types.LeaseID, _ string) (*v1.Deployment, error) {
return nil, nil
}

func (nullClient) Teardown(_ types.LeaseID) error {
return nil
}
Expand Down
19 changes: 18 additions & 1 deletion provider/cluster/kube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ovrclk/akash/provider/cluster"
"github.com/ovrclk/akash/types"
"github.com/tendermint/tmlibs/log"
"k8s.io/api/apps/v1"
apiextcs "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -103,8 +104,24 @@ func (c *client) Deployments() ([]cluster.Deployment, error) {
return deployments, nil
}

func (c *client) Deploy(lid types.LeaseID, group *types.ManifestGroup) error {
// todo: limit number of results and do pagination / streaming
func (c *client) KubeDeployments(lid types.LeaseID) (*v1.DeploymentList, error) {
deployments, err := c.kc.AppsV1().Deployments(lidNS(lid)).List(metav1.ListOptions{})
if err != nil {
return nil, err
}
return deployments, nil
}

func (c *client) KubeDeployment(lid types.LeaseID, name string) (*v1.Deployment, error) {
deployment, err := c.kc.AppsV1().Deployments(lidNS(lid)).Get(name, metav1.GetOptions{})
if err != nil {
return nil, err
}
return deployment, nil
}

func (c *client) Deploy(lid types.LeaseID, group *types.ManifestGroup) error {
if err := applyNS(c.kc, newNSBuilder(lid, group)); err != nil {
c.log.Error("applying namespace", "err", err, "lease", lid)
return err
Expand Down
110 changes: 110 additions & 0 deletions provider/cluster/kube/mocks/client.go

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

Loading

0 comments on commit cb48a13

Please sign in to comment.