Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI lameduck Subcommand #394

Draft
wants to merge 1 commit into
base: control-client
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"encoding/json"
"errors"
"time"

"github.com/nats-io/nats.go"
Expand Down Expand Up @@ -168,8 +169,16 @@ func (c *ControlAPIClient) GetInfo(nodeId string) (*models.InfoResponse, error)
return resp, nil
}

func (c *ControlAPIClient) SetLameDuck(nodeId string) (*models.LameduckResponse, error) {
req := models.LameduckRequest{}
func (c *ControlAPIClient) SetLameDuck(nodeId string, tag map[string]string) (*models.LameduckResponse, error) {
if nodeId == "" && len(tag) != 1 {
return nil, errors.New("invalid inputs to lameduck request")
}

req := models.LameduckRequest{
NodeId: nodeId,
Tag: tag,
}

req_b, err := json.Marshal(req)
if err != nil {
return nil, err
Expand Down
33 changes: 22 additions & 11 deletions cmd/nex/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/nats-io/nkeys"

control "github.com/synadia-io/nex/api"
options "github.com/synadia-io/nex/models"
"github.com/synadia-io/nex/node"
)
Expand Down Expand Up @@ -113,24 +114,34 @@ func (l LameDuck) Validate() error {
if len(l.Label) > 1 {
return errors.New("only one label allowed")
}

switch {
case l.NodeID != "":
fmt.Println("Putting node in lameduck")
case len(l.Label) == 1:
fmt.Println("Putting all nodes with label in lameduck")
default:
return errors.New("used must provide valid Node ID or one label")
}

return nil
}

func (l LameDuck) Run(ctx context.Context, globals *Globals) error {
if globals.Check {
return printTable("Node Lameduck Configuration", append(globals.Table(), l.Table()...)...)
}
fmt.Println("run lameduck")

nc, err := configureNatsConnection(globals)
if err != nil {
return err
}

controller, err := control.NewControlApiClient(nc)
if err != nil {
return err
}

resp, err := controller.SetLameDuck(l.NodeID, l.Label)
if err != nil {
return err
}

if !resp.Success {
return fmt.Errorf("failed to put node in lameduck mode: %s", resp.Msg)
}

fmt.Printf("Node %s is now in lameduck mode. Workloads will begin stopping gracefully.\n", l.NodeID)
return nil
}

Expand Down
10 changes: 8 additions & 2 deletions models/controlapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ type UndeployRequest struct{}
type UndeployResponse struct{}
type InfoRequest struct{}
type InfoResponse struct{}
type LameduckRequest struct{}
type LameduckResponse struct{}
type LameduckRequest struct {
NodeId string
Tag map[string]string
}
type LameduckResponse struct {
Success bool
Msg string
}
Loading