Skip to content

Commit

Permalink
Merge pull request #153 from drone-runners/add-tags-support
Browse files Browse the repository at this point in the history
start publishing tags based on supported os/arch
  • Loading branch information
vistaarjuneja authored Aug 12, 2022
2 parents 122b9ec + cc5834d commit c289caa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion command/harness/delegate/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 13 additions & 3 deletions command/harness/dlite/dlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions command/harness/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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 {
Expand Down

0 comments on commit c289caa

Please sign in to comment.