From cc5834d9ebb9169ab47b288667655f09c447dbe2 Mon Sep 17 00:00:00 2001 From: Vistaar Juneja Date: Fri, 12 Aug 2022 11:32:16 +0100 Subject: [PATCH] start publishing tags based on supported os/arch --- command/harness/delegate/delegate.go | 2 +- command/harness/dlite/dlite.go | 16 +++++++++++++--- command/harness/pool.go | 14 +++++++------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/command/harness/delegate/delegate.go b/command/harness/delegate/delegate.go index a3258aae..85c2ffd3 100644 --- a/command/harness/delegate/delegate.go +++ b/command/harness/delegate/delegate.go @@ -114,7 +114,7 @@ func (c *delegateCommand) run(*kingpin.ParseContext) error { c.stageOwnerStore = database.NewStageOwnerStore(db) c.poolManager = drivers.New(ctx, instanceStore, c.env.Settings.LiteEnginePath, c.env.Runner.Name) - err = harness.SetupPool(ctx, &c.env, c.poolManager, c.poolFile) + _, err = harness.SetupPool(ctx, &c.env, c.poolManager, c.poolFile) if err != nil { return err } diff --git a/command/harness/dlite/dlite.go b/command/harness/dlite/dlite.go index 87fce210..c143d1c1 100644 --- a/command/harness/dlite/dlite.go +++ b/command/harness/dlite/dlite.go @@ -48,6 +48,16 @@ func RegisterDlite(app *kingpin.Application) { StringVar(&c.poolFile) } +// Iterate over the list of pools and register the tags for the pools it supports +func parseTags(pf *config.PoolFile) []string { + tags := []string{} + for i := range pf.Instances { + t := pf.Instances[i].Platform.OS + "-" + pf.Instances[i].Platform.Arch + tags = append(tags, t) + } + return tags +} + func (c *dliteCommand) startPoller(ctx context.Context, tags []string) error { r := router.NewRouter(routeMap(c)) // Client to interact with the harness server @@ -97,18 +107,18 @@ func (c *dliteCommand) run(*kingpin.ParseContext) error { c.stageOwnerStore = database.NewStageOwnerStore(db) c.poolManager = drivers.New(ctx, instanceStore, c.env.Settings.LiteEnginePath, c.env.Runner.Name) - err = harness.SetupPool(ctx, &c.env, c.poolManager, c.poolFile) + poolConfig, err := harness.SetupPool(ctx, &c.env, c.poolManager, c.poolFile) if err != nil { return err } + tags := parseTags(poolConfig) hook := loghistory.New() logrus.AddHook(hook) var g errgroup.Group g.Go(func() error { - // TODO (Vistaar): Add support for tags based on available pools - err = c.startPoller(ctx, []string{}) + err = c.startPoller(ctx, tags) if err != nil { logrus.WithError(err).Error("could not start poller") return err diff --git a/command/harness/pool.go b/command/harness/pool.go index 7c20ff4c..43604a16 100644 --- a/command/harness/pool.go +++ b/command/harness/pool.go @@ -10,7 +10,7 @@ import ( "github.com/sirupsen/logrus" ) -func SetupPool(ctx context.Context, env *config.EnvConfig, poolManager *drivers.Manager, poolFile string) error { +func SetupPool(ctx context.Context, env *config.EnvConfig, poolManager *drivers.Manager, poolFile string) (*config.PoolFile, error) { configPool, confErr := poolfile.ConfigPoolFile(poolFile, env) if confErr != nil { logrus.WithError(confErr).Fatalln("Unable to load pool file, or use an in memory pool") @@ -19,20 +19,20 @@ func SetupPool(ctx context.Context, env *config.EnvConfig, poolManager *drivers. pools, err := poolfile.ProcessPool(configPool, env.Runner.Name) if err != nil { logrus.WithError(err).Errorln("unable to process pool file") - return err + return configPool, err } err = poolManager.Add(pools...) if err != nil { logrus.WithError(err).Errorln("unable to add pools") - return err + return configPool, err } err = poolManager.PingDriver(ctx) if err != nil { logrus.WithError(err). Errorln("unable to ping driver") - return err + return configPool, err } // setup lifetimes of instances @@ -42,7 +42,7 @@ func SetupPool(ctx context.Context, env *config.EnvConfig, poolManager *drivers. if err != nil { logrus.WithError(err). Errorln("failed to start instance purger") - return err + return configPool, err } // lets remove any old instances. @@ -60,10 +60,10 @@ func SetupPool(ctx context.Context, env *config.EnvConfig, poolManager *drivers. if buildPoolErr != nil { logrus.WithError(buildPoolErr). Errorln("unable to build pool") - return buildPoolErr + return configPool, buildPoolErr } logrus.Infoln("pool created") - return nil + return configPool, nil } func Cleanup(ctx context.Context, env *config.EnvConfig, poolManager *drivers.Manager) error {