lib, gapi, cli: Add a wait flag to empty and a new default

Change the default "wait" state for if you run the empty frontend when
there's already an available deploy waiting. You almost certainly want
to start running it right away.

Example:

mgmt etcd

mgmt run --hostname h1 --no-server --tmp-prefix --seeds=http://127.0.0.1:2379 empty
mgmt run --hostname h2 --no-server --tmp-prefix --seeds=http://127.0.0.1:2379 empty

mgmt deploy --no-git --seeds=http://127.0.0.1:2379 lang examples/lang/hello0.mcl

mgmt run --hostname h3 --no-server --tmp-prefix --seeds=http://127.0.0.1:2379 empty

In fact, you don't even need to start up etcd first for this to all
work.
This commit is contained in:
James Shubin
2025-03-10 14:56:42 -04:00
parent 37e5a37045
commit 50bd6f5811
3 changed files with 31 additions and 3 deletions

View File

@@ -70,7 +70,9 @@ func LookupSubcommand(obj interface{}, st interface{}) string {
}
// EmptyArgs is the empty CLI parsing structure and type of the parsed result.
type EmptyArgs struct{}
type EmptyArgs struct {
Wait bool `arg:"--wait" help:"don't use any existing (stale) deploys"`
}
// LangArgs is the lang CLI parsing structure and type of the parsed result.
type LangArgs struct {

View File

@@ -33,6 +33,7 @@ import (
"fmt"
"sync"
cliUtil "github.com/purpleidea/mgmt/cli/util"
"github.com/purpleidea/mgmt/gapi"
"github.com/purpleidea/mgmt/pgraph"
)
@@ -48,6 +49,17 @@ func init() {
// GAPI implements the main lang GAPI interface.
type GAPI struct {
// Wait should be true if we don't use any existing (stale) deploys.
// This means that if you start an empty GAPI, then it will immediately
// try to look for and run any existing deploys that have been stored in
// the cluster that it has connected to. If this is true, then it will
// only start on the next deploy. To be honest, we should probably never
// wait, but this was accidentally how it was initially implemented, so
// we'll change the default and add this in as a flag for now. We may
// remove this in the future unless someone has a good reason for
// needing it.
Wait bool
data *gapi.Data
initialized bool
closeChan chan struct{}
@@ -57,11 +69,19 @@ type GAPI struct {
// Cli takes an *Info struct, and returns our deploy if activated, and if there
// are any validation problems, you should return an error. If there is no
// deploy, then you should return a nil deploy and a nil error.
func (obj *GAPI) Cli(*gapi.Info) (*gapi.Deploy, error) {
func (obj *GAPI) Cli(info *gapi.Info) (*gapi.Deploy, error) {
args, ok := info.Args.(*cliUtil.EmptyArgs)
if !ok {
// programming error
return nil, fmt.Errorf("could not convert to our struct")
}
return &gapi.Deploy{
Name: Name,
//Noop: false,
GAPI: &GAPI{},
GAPI: &GAPI{
Wait: args.Wait,
},
}, nil
}

View File

@@ -1024,6 +1024,12 @@ func (obj *Main) Run() error {
defer wg.Done()
defer close(deployChan) // no more are coming ever!
// if "empty" and we don't want to wait for a fresh deploy...
if obj.Deploy != nil && max != 0 {
if emptyGAPI, ok := obj.Deploy.GAPI.(*empty.GAPI); ok && !emptyGAPI.Wait {
obj.Deploy = nil // erase the empty deploy
}
}
// we've been asked to deploy, so do that first...
if obj.Deploy != nil {
deploy := obj.Deploy