Add a common RunnerPrefix type
There are several fields that are common among some of the data structures in garm. The RunnerPrefix is just one of them. Perhaps we should move some of the rest in a common type and embed that into the types that share those fields. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
4f2808eb23
commit
abcc9569bd
10 changed files with 50 additions and 33 deletions
|
|
@ -61,9 +61,11 @@ var orgPoolAddCmd = &cobra.Command{
|
|||
|
||||
tags := strings.Split(poolTags, ",")
|
||||
newPoolParams := params.CreatePoolParams{
|
||||
ProviderName: poolProvider,
|
||||
MaxRunners: poolMaxRunners,
|
||||
RunnerPrefix: poolRunnerPrefix,
|
||||
ProviderName: poolProvider,
|
||||
MaxRunners: poolMaxRunners,
|
||||
RunnerPrefix: params.RunnerPrefix{
|
||||
Prefix: poolRunnerPrefix,
|
||||
},
|
||||
MinIdleRunners: poolMinIdleRunners,
|
||||
Image: poolImage,
|
||||
Flavor: poolFlavor,
|
||||
|
|
@ -198,7 +200,9 @@ explicitly remove them using the runner delete command.
|
|||
}
|
||||
|
||||
if cmd.Flags().Changed("runner-prefix") {
|
||||
poolUpdateParams.RunnerPrefix = poolRunnerPrefix
|
||||
poolUpdateParams.RunnerPrefix = params.RunnerPrefix{
|
||||
Prefix: poolRunnerPrefix,
|
||||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("max-runners") {
|
||||
|
|
|
|||
|
|
@ -167,7 +167,9 @@ var poolAddCmd = &cobra.Command{
|
|||
|
||||
tags := strings.Split(poolTags, ",")
|
||||
newPoolParams := params.CreatePoolParams{
|
||||
RunnerPrefix: poolRunnerPrefix,
|
||||
RunnerPrefix: params.RunnerPrefix{
|
||||
Prefix: poolRunnerPrefix,
|
||||
},
|
||||
ProviderName: poolProvider,
|
||||
MaxRunners: poolMaxRunners,
|
||||
MinIdleRunners: poolMinIdleRunners,
|
||||
|
|
@ -259,7 +261,9 @@ explicitly remove them using the runner delete command.
|
|||
}
|
||||
|
||||
if cmd.Flags().Changed("runner-prefix") {
|
||||
poolUpdateParams.RunnerPrefix = poolRunnerPrefix
|
||||
poolUpdateParams.RunnerPrefix = params.RunnerPrefix{
|
||||
Prefix: poolRunnerPrefix,
|
||||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("enabled") {
|
||||
|
|
|
|||
|
|
@ -76,9 +76,11 @@ var repoPoolAddCmd = &cobra.Command{
|
|||
|
||||
tags := strings.Split(poolTags, ",")
|
||||
newPoolParams := params.CreatePoolParams{
|
||||
ProviderName: poolProvider,
|
||||
MaxRunners: poolMaxRunners,
|
||||
RunnerPrefix: poolRunnerPrefix,
|
||||
ProviderName: poolProvider,
|
||||
MaxRunners: poolMaxRunners,
|
||||
RunnerPrefix: params.RunnerPrefix{
|
||||
Prefix: poolRunnerPrefix,
|
||||
},
|
||||
MinIdleRunners: poolMinIdleRunners,
|
||||
Image: poolImage,
|
||||
Flavor: poolFlavor,
|
||||
|
|
@ -185,7 +187,9 @@ explicitly remove them using the runner delete command.
|
|||
}
|
||||
|
||||
if cmd.Flags().Changed("runner-prefix") {
|
||||
poolUpdateParams.RunnerPrefix = poolRunnerPrefix
|
||||
poolUpdateParams.RunnerPrefix = params.RunnerPrefix{
|
||||
Prefix: poolRunnerPrefix,
|
||||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("max-runners") {
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ func (s *sqlDatabase) CreateEnterprisePool(ctx context.Context, enterpriseID str
|
|||
ProviderName: param.ProviderName,
|
||||
MaxRunners: param.MaxRunners,
|
||||
MinIdleRunners: param.MinIdleRunners,
|
||||
RunnerPrefix: param.RunnerPrefix,
|
||||
RunnerPrefix: param.GetRunnerPrefix(),
|
||||
Image: param.Image,
|
||||
Flavor: param.Flavor,
|
||||
OSType: param.OSType,
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ func (s *sqlDatabase) CreateOrganizationPool(ctx context.Context, orgId string,
|
|||
ProviderName: param.ProviderName,
|
||||
MaxRunners: param.MaxRunners,
|
||||
MinIdleRunners: param.MinIdleRunners,
|
||||
RunnerPrefix: param.RunnerPrefix,
|
||||
RunnerPrefix: param.GetRunnerPrefix(),
|
||||
Image: param.Image,
|
||||
Flavor: param.Flavor,
|
||||
OSType: param.OSType,
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ func (s *sqlDatabase) CreateRepositoryPool(ctx context.Context, repoId string, p
|
|||
ProviderName: param.ProviderName,
|
||||
MaxRunners: param.MaxRunners,
|
||||
MinIdleRunners: param.MinIdleRunners,
|
||||
RunnerPrefix: param.RunnerPrefix,
|
||||
RunnerPrefix: param.GetRunnerPrefix(),
|
||||
Image: param.Image,
|
||||
Flavor: param.Flavor,
|
||||
OSType: param.OSType,
|
||||
|
|
|
|||
|
|
@ -106,11 +106,13 @@ func (s *sqlDatabase) sqlToCommonEnterprise(enterprise Enterprise) params.Enterp
|
|||
|
||||
func (s *sqlDatabase) sqlToCommonPool(pool Pool) params.Pool {
|
||||
ret := params.Pool{
|
||||
ID: pool.ID.String(),
|
||||
ProviderName: pool.ProviderName,
|
||||
MaxRunners: pool.MaxRunners,
|
||||
MinIdleRunners: pool.MinIdleRunners,
|
||||
RunnerPrefix: pool.RunnerPrefix,
|
||||
ID: pool.ID.String(),
|
||||
ProviderName: pool.ProviderName,
|
||||
MaxRunners: pool.MaxRunners,
|
||||
MinIdleRunners: pool.MinIdleRunners,
|
||||
RunnerPrefix: params.RunnerPrefix{
|
||||
Prefix: pool.RunnerPrefix,
|
||||
},
|
||||
Image: pool.Image,
|
||||
Flavor: pool.Flavor,
|
||||
OSArch: pool.OSArch,
|
||||
|
|
|
|||
|
|
@ -137,8 +137,9 @@ type Tag struct {
|
|||
}
|
||||
|
||||
type Pool struct {
|
||||
RunnerPrefix
|
||||
|
||||
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"`
|
||||
|
|
@ -286,3 +287,14 @@ type RunnerInfo struct {
|
|||
Name string
|
||||
Labels []string
|
||||
}
|
||||
|
||||
type RunnerPrefix struct {
|
||||
Prefix string `json:"runner_prefix"`
|
||||
}
|
||||
|
||||
func (p RunnerPrefix) GetRunnerPrefix() string {
|
||||
if p.Prefix == "" {
|
||||
return DefaultRunnerPrefix
|
||||
}
|
||||
return p.Prefix
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,6 +97,8 @@ type NewUserParams struct {
|
|||
}
|
||||
|
||||
type UpdatePoolParams struct {
|
||||
RunnerPrefix
|
||||
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Enabled *bool `json:"enabled,omitempty"`
|
||||
MaxRunners *uint `json:"max_runners,omitempty"`
|
||||
|
|
@ -104,18 +106,10 @@ 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"`
|
||||
}
|
||||
|
||||
func (p *UpdatePoolParams) GetRunnerPrefix() string {
|
||||
if p.RunnerPrefix == "" {
|
||||
p.RunnerPrefix = DefaultRunnerPrefix
|
||||
}
|
||||
return p.RunnerPrefix
|
||||
}
|
||||
|
||||
type CreateInstanceParams struct {
|
||||
Name string
|
||||
OSType config.OSType
|
||||
|
|
@ -128,8 +122,9 @@ type CreateInstanceParams struct {
|
|||
}
|
||||
|
||||
type CreatePoolParams struct {
|
||||
RunnerPrefix
|
||||
|
||||
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"`
|
||||
|
|
|
|||
|
|
@ -395,15 +395,11 @@ func (r *basePoolManager) AddRunner(ctx context.Context, poolID string) error {
|
|||
return errors.Wrap(err, "fetching pool")
|
||||
}
|
||||
|
||||
prefix := pool.RunnerPrefix
|
||||
if prefix == "" {
|
||||
prefix = params.DefaultRunnerPrefix
|
||||
}
|
||||
suffix, err := shortid.Generate()
|
||||
if err != nil {
|
||||
suffix = uuid.New().String()
|
||||
}
|
||||
name := fmt.Sprintf("%s-%s", prefix, suffix)
|
||||
name := fmt.Sprintf("%s-%s", pool.GetRunnerPrefix(), suffix)
|
||||
|
||||
createParams := params.CreateInstanceParams{
|
||||
Name: name,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue