Skip to content

Commit

Permalink
feat: allow to configure the runner name
Browse files Browse the repository at this point in the history
  • Loading branch information
maigl committed Jan 12, 2023
1 parent b2a22e1 commit 9e43e33
Show file tree
Hide file tree
Showing 19 changed files with 554 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmd/garm-cli/cmd/org_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ explicitly remove them using the runner delete command.
poolUpdateParams.OSArch = config.OSArch(poolOSArch)
}

if cmd.Flags().Changed("runner-prefix") {
poolUpdateParams.RunnerPrefix = poolRunnerPrefix
}

if cmd.Flags().Changed("max-runners") {
poolUpdateParams.MaxRunners = &poolMaxRunners
}
Expand Down Expand Up @@ -225,6 +229,7 @@ func init() {
orgPoolAddCmd.Flags().StringVar(&poolTags, "tags", "", "A comma separated list of tags to assign to this runner.")
orgPoolAddCmd.Flags().StringVar(&poolOSType, "os-type", "linux", "Operating system type (windows, linux, etc).")
orgPoolAddCmd.Flags().StringVar(&poolOSArch, "os-arch", "amd64", "Operating system architecture (amd64, arm, etc).")
orgPoolAddCmd.Flags().StringVar(&poolRunnerPrefix, "runner-prefix", "", "The name prefix to use for runners in this pool.")
orgPoolAddCmd.Flags().UintVar(&poolMaxRunners, "max-runners", 5, "The maximum number of runner this pool will create.")
orgPoolAddCmd.Flags().UintVar(&poolMinIdleRunners, "min-idle-runners", 1, "Attempt to maintain a minimum of idle self-hosted runners of this type.")
orgPoolAddCmd.Flags().BoolVar(&poolEnabled, "enabled", false, "Enable this pool.")
Expand All @@ -238,6 +243,7 @@ func init() {
orgPoolUpdateCmd.Flags().StringVar(&poolTags, "tags", "", "A comma separated list of tags to assign to this runner.")
orgPoolUpdateCmd.Flags().StringVar(&poolOSType, "os-type", "linux", "Operating system type (windows, linux, etc).")
orgPoolUpdateCmd.Flags().StringVar(&poolOSArch, "os-arch", "amd64", "Operating system architecture (amd64, arm, etc).")
orgPoolUpdateCmd.Flags().StringVar(&poolRunnerPrefix, "runner-prefix", "", "The name prefix to use for runners in this pool.")
orgPoolUpdateCmd.Flags().UintVar(&poolMaxRunners, "max-runners", 5, "The maximum number of runner this pool will create.")
orgPoolUpdateCmd.Flags().UintVar(&poolMinIdleRunners, "min-idle-runners", 1, "Attempt to maintain a minimum of idle self-hosted runners of this type.")
orgPoolUpdateCmd.Flags().BoolVar(&poolEnabled, "enabled", false, "Enable this pool.")
Expand Down
8 changes: 7 additions & 1 deletion cmd/garm-cli/cmd/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var poolListCmd = &cobra.Command{
Aliases: []string{"ls"},
Short: "List pools",
Long: `List pools of repositories, orgs or all of the above.
This command will list pools from one repo, one org or all pools
on the system. The list flags are mutually exclusive. You must however
specify one of them.
Expand Down Expand Up @@ -257,6 +257,10 @@ explicitly remove them using the runner delete command.
poolUpdateParams.MinIdleRunners = &poolMinIdleRunners
}

if cmd.Flags().Changed("runner-prefix") {
poolUpdateParams.RunnerPrefix = poolRunnerPrefix
}

if cmd.Flags().Changed("enabled") {
poolUpdateParams.Enabled = &poolEnabled
}
Expand Down Expand Up @@ -287,6 +291,7 @@ func init() {
poolUpdateCmd.Flags().StringVar(&poolTags, "tags", "", "A comma separated list of tags to assign to this runner.")
poolUpdateCmd.Flags().StringVar(&poolOSType, "os-type", "linux", "Operating system type (windows, linux, etc).")
poolUpdateCmd.Flags().StringVar(&poolOSArch, "os-arch", "amd64", "Operating system architecture (amd64, arm, etc).")
poolUpdateCmd.Flags().StringVar(&poolRunnerPrefix, "runner-prefix", "", "The name prefix to use for runners in this pool.")
poolUpdateCmd.Flags().UintVar(&poolMaxRunners, "max-runners", 5, "The maximum number of runner this pool will create.")
poolUpdateCmd.Flags().UintVar(&poolMinIdleRunners, "min-idle-runners", 1, "Attempt to maintain a minimum of idle self-hosted runners of this type.")
poolUpdateCmd.Flags().BoolVar(&poolEnabled, "enabled", false, "Enable this pool.")
Expand All @@ -295,6 +300,7 @@ func init() {
poolAddCmd.Flags().StringVar(&poolProvider, "provider-name", "", "The name of the provider where runners will be created.")
poolAddCmd.Flags().StringVar(&poolImage, "image", "", "The provider-specific image name to use for runners in this pool.")
poolAddCmd.Flags().StringVar(&poolFlavor, "flavor", "", "The flavor to use for this runner.")
poolAddCmd.Flags().StringVar(&poolRunnerPrefix, "runner-prefix", "", "The name prefix to use for runners in this pool.")
poolAddCmd.Flags().StringVar(&poolTags, "tags", "", "A comma separated list of tags to assign to this runner.")
poolAddCmd.Flags().StringVar(&poolOSType, "os-type", "linux", "Operating system type (windows, linux, etc).")
poolAddCmd.Flags().StringVar(&poolOSArch, "os-arch", "amd64", "Operating system architecture (amd64, arm, etc).")
Expand Down
7 changes: 7 additions & 0 deletions cmd/garm-cli/cmd/repo_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
poolProvider string
poolMaxRunners uint
poolMinIdleRunners uint
poolRunnerPrefix string
poolImage string
poolFlavor string
poolOSType string
Expand Down Expand Up @@ -182,6 +183,10 @@ explicitly remove them using the runner delete command.
poolUpdateParams.OSArch = config.OSArch(poolOSArch)
}

if cmd.Flags().Changed("runner-prefix") {
poolUpdateParams.RunnerPrefix = poolRunnerPrefix
}

if cmd.Flags().Changed("max-runners") {
poolUpdateParams.MaxRunners = &poolMaxRunners
}
Expand Down Expand Up @@ -211,6 +216,7 @@ func init() {
repoPoolAddCmd.Flags().StringVar(&poolTags, "tags", "", "A comma separated list of tags to assign to this runner.")
repoPoolAddCmd.Flags().StringVar(&poolOSType, "os-type", "linux", "Operating system type (windows, linux, etc).")
repoPoolAddCmd.Flags().StringVar(&poolOSArch, "os-arch", "amd64", "Operating system architecture (amd64, arm, etc).")
repoPoolAddCmd.Flags().StringVar(&poolRunnerPrefix, "runner-prefix", "", "The name prefix to use for runners in this pool.")
repoPoolAddCmd.Flags().UintVar(&poolMaxRunners, "max-runners", 5, "The maximum number of runner this pool will create.")
repoPoolAddCmd.Flags().UintVar(&poolMinIdleRunners, "min-idle-runners", 1, "Attempt to maintain a minimum of idle self-hosted runners of this type.")
repoPoolAddCmd.Flags().BoolVar(&poolEnabled, "enabled", false, "Enable this pool.")
Expand All @@ -224,6 +230,7 @@ func init() {
repoPoolUpdateCmd.Flags().StringVar(&poolTags, "tags", "", "A comma separated list of tags to assign to this runner.")
repoPoolUpdateCmd.Flags().StringVar(&poolOSType, "os-type", "linux", "Operating system type (windows, linux, etc).")
repoPoolUpdateCmd.Flags().StringVar(&poolOSArch, "os-arch", "amd64", "Operating system architecture (amd64, arm, etc).")
repoPoolUpdateCmd.Flags().StringVar(&poolRunnerPrefix, "runner-prefix", "", "The name prefix to use for runners in this pool.")
repoPoolUpdateCmd.Flags().UintVar(&poolMaxRunners, "max-runners", 5, "The maximum number of runner this pool will create.")
repoPoolUpdateCmd.Flags().UintVar(&poolMinIdleRunners, "min-idle-runners", 1, "Attempt to maintain a minimum of idle self-hosted runners of this type.")
repoPoolUpdateCmd.Flags().BoolVar(&poolEnabled, "enabled", false, "Enable this pool.")
Expand Down
1 change: 1 addition & 0 deletions database/sql/enterprise.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func (s *sqlDatabase) CreateEnterprisePool(ctx context.Context, enterpriseID str
ProviderName: param.ProviderName,
MaxRunners: param.MaxRunners,
MinIdleRunners: param.MinIdleRunners,
RunnerPrefix: param.RunnerPrefix,
Image: param.Image,
Flavor: param.Flavor,
OSType: param.OSType,
Expand Down
1 change: 1 addition & 0 deletions database/sql/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Pool struct {
Base

ProviderName string `gorm:"index:idx_pool_type"`
RunnerPrefix string
MaxRunners uint
MinIdleRunners uint
RunnerBootstrapTimeout uint
Expand Down
1 change: 1 addition & 0 deletions database/sql/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func (s *sqlDatabase) CreateOrganizationPool(ctx context.Context, orgId string,
ProviderName: param.ProviderName,
MaxRunners: param.MaxRunners,
MinIdleRunners: param.MinIdleRunners,
RunnerPrefix: param.RunnerPrefix,
Image: param.Image,
Flavor: param.Flavor,
OSType: param.OSType,
Expand Down
1 change: 1 addition & 0 deletions database/sql/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func (s *sqlDatabase) CreateRepositoryPool(ctx context.Context, repoId string, p
ProviderName: param.ProviderName,
MaxRunners: param.MaxRunners,
MinIdleRunners: param.MinIdleRunners,
RunnerPrefix: param.RunnerPrefix,
Image: param.Image,
Flavor: param.Flavor,
OSType: param.OSType,
Expand Down
4 changes: 4 additions & 0 deletions database/sql/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func (s *sqlDatabase) sqlToCommonPool(pool Pool) params.Pool {
ProviderName: pool.ProviderName,
MaxRunners: pool.MaxRunners,
MinIdleRunners: pool.MinIdleRunners,
RunnerPrefix: pool.RunnerPrefix,
Image: pool.Image,
Flavor: pool.Flavor,
OSArch: pool.OSArch,
Expand Down Expand Up @@ -218,6 +219,9 @@ func (s *sqlDatabase) updatePool(pool Pool, param params.UpdatePoolParams) (para
pool.Image = param.Image
}

// no check necessary, we have sane defaults
pool.RunnerPrefix = param.RunnerPrefix

if param.MaxRunners != nil {
pool.MaxRunners = *param.MaxRunners
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ require (
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
golang.org/x/net v0.0.0-20220325170049-de3da57026de // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569 h1:xzABM9let0HLLqFypcxvLmlvEciCHL7+Lv+4vwZqecI=
github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569/go.mod h1:2Ly+NIftZN4de9zRmENdYbvPQeaVIYKWpLFStLFEBgI=
github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs=
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
1 change: 1 addition & 0 deletions params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ type Tag struct {

type Pool struct {
ID string `json:"id"`
RunnerPrefix string `json:"runner_prefix"`
ProviderName string `json:"provider_name"`
MaxRunners uint `json:"max_runners"`
MinIdleRunners uint `json:"min_idle_runners"`
Expand Down
2 changes: 2 additions & 0 deletions params/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type UpdatePoolParams struct {
RunnerBootstrapTimeout *uint `json:"runner_bootstrap_timeout,omitempty"`
Image string `json:"image"`
Flavor string `json:"flavor"`
RunnerPrefix string `json:"runner_prefix"`
OSType config.OSType `json:"os_type"`
OSArch config.OSArch `json:"os_arch"`
}
Expand All @@ -119,6 +120,7 @@ type CreateInstanceParams struct {

type CreatePoolParams struct {
ProviderName string `json:"provider_name"`
RunnerPrefix string `json:"runner_prefix"`
MaxRunners uint `json:"max_runners"`
MinIdleRunners uint `json:"min_idle_runners"`
Image string `json:"image"`
Expand Down
8 changes: 6 additions & 2 deletions runner/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (
providerCommon "garm/runner/providers/common"

"github.com/google/go-github/v48/github"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/teris-io/shortid"
)

var (
Expand Down Expand Up @@ -394,7 +394,11 @@ func (r *basePoolManager) AddRunner(ctx context.Context, poolID string) error {
return errors.Wrap(err, "fetching pool")
}

name := fmt.Sprintf("garm-%s", uuid.New())
prefix := pool.RunnerPrefix
if prefix == "" {
prefix = "garm"
}
name := fmt.Sprintf("%s-%s", prefix, shortid.MustGenerate())

createParams := params.CreateInstanceParams{
Name: name,
Expand Down
3 changes: 3 additions & 0 deletions vendor/github.com/teris-io/shortid/.gitignore

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

19 changes: 19 additions & 0 deletions vendor/github.com/teris-io/shortid/.travis.yml

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

18 changes: 18 additions & 0 deletions vendor/github.com/teris-io/shortid/LICENSE

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

109 changes: 109 additions & 0 deletions vendor/github.com/teris-io/shortid/README.md

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

Loading

0 comments on commit 9e43e33

Please sign in to comment.