From cdfda0321a3cda7fd4d4d25da24e5b36d20c91e6 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Fri, 15 Mar 2024 07:26:04 +0000 Subject: [PATCH] Fix balancer type validation Signed-off-by: Gabriel Adrian Samfira --- params/params.go | 7 +++++-- params/requests.go | 6 +++--- runner/enterprises.go | 2 +- runner/organizations.go | 2 +- runner/pool/util.go | 2 +- runner/repositories.go | 2 +- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/params/params.go b/params/params.go index 3bca739e..b4157206 100644 --- a/params/params.go +++ b/params/params.go @@ -49,9 +49,12 @@ const ( // balancer, the pool manager will attempt to create instances in each pool in turn // for each job that needs to be serviced. So job1 in pool1, job2 in pool2 and so on. PoolBalancerTypeRoundRobin PoolBalancerType = "roundrobin" - // PoolBalancerTypeStack will try to create instances in the first pool that matches + // PoolBalancerTypePack will try to create instances in the first pool that matches // the required labels. If the pool is full, it will move on to the next pool and so on. - PoolBalancerTypeStack PoolBalancerType = "stack" + PoolBalancerTypePack PoolBalancerType = "pack" + // PoolBalancerTypeNone denotes to the default behavior of the pool manager, which is + // to use the round robin balancer. + PoolBalancerTypeNone PoolBalancerType = "" ) const ( diff --git a/params/requests.go b/params/requests.go index 8551d249..81108493 100644 --- a/params/requests.go +++ b/params/requests.go @@ -55,7 +55,7 @@ func (c *CreateRepoParams) Validate() error { } switch c.PoolBalancerType { - case PoolBalancerTypeRoundRobin, PoolBalancerTypeStack: + case PoolBalancerTypeRoundRobin, PoolBalancerTypePack: default: return errors.NewBadRequestError("invalid pool balancer type") } @@ -83,7 +83,7 @@ func (c *CreateOrgParams) Validate() error { } switch c.PoolBalancerType { - case PoolBalancerTypeRoundRobin, PoolBalancerTypeStack: + case PoolBalancerTypeRoundRobin, PoolBalancerTypePack: default: return errors.NewBadRequestError("invalid pool balancer type") } @@ -109,7 +109,7 @@ func (c *CreateEnterpriseParams) Validate() error { } switch c.PoolBalancerType { - case PoolBalancerTypeRoundRobin, PoolBalancerTypeStack: + case PoolBalancerTypeRoundRobin, PoolBalancerTypePack: default: return errors.NewBadRequestError("invalid pool balancer type") } diff --git a/runner/enterprises.go b/runner/enterprises.go index 3f7f9f72..01c5a8d0 100644 --- a/runner/enterprises.go +++ b/runner/enterprises.go @@ -173,7 +173,7 @@ func (r *Runner) UpdateEnterprise(ctx context.Context, enterpriseID string, para } switch param.PoolBalancerType { - case params.PoolBalancerTypeRoundRobin, params.PoolBalancerTypeStack, param.PoolBalancerType: + case params.PoolBalancerTypeRoundRobin, params.PoolBalancerTypePack, params.PoolBalancerTypeNone: default: return params.Enterprise{}, runnerErrors.NewBadRequestError("invalid pool balancer type: %s", param.PoolBalancerType) } diff --git a/runner/organizations.go b/runner/organizations.go index abd53f35..2d837fd0 100644 --- a/runner/organizations.go +++ b/runner/organizations.go @@ -202,7 +202,7 @@ func (r *Runner) UpdateOrganization(ctx context.Context, orgID string, param par } switch param.PoolBalancerType { - case params.PoolBalancerTypeRoundRobin, params.PoolBalancerTypeStack, param.PoolBalancerType: + case params.PoolBalancerTypeRoundRobin, params.PoolBalancerTypePack, params.PoolBalancerTypeNone: default: return params.Organization{}, runnerErrors.NewBadRequestError("invalid pool balancer type: %s", param.PoolBalancerType) } diff --git a/runner/pool/util.go b/runner/pool/util.go index e9fbdf1a..8769fe0b 100644 --- a/runner/pool/util.go +++ b/runner/pool/util.go @@ -52,7 +52,7 @@ func (p *poolsForTags) Get(tags []string) (poolCacheStore, bool) { return nil, false } poolCache := v.(*poolRoundRobin) - if p.poolCacheType == params.PoolBalancerTypeStack { + if p.poolCacheType == params.PoolBalancerTypePack { // When we service a list of jobs, we want to try each pool in turn // for each job. Pools are sorted by priority so we always start from the // highest priority pool and move on to the next if the first one is full. diff --git a/runner/repositories.go b/runner/repositories.go index 669fb323..d5b4db77 100644 --- a/runner/repositories.go +++ b/runner/repositories.go @@ -201,7 +201,7 @@ func (r *Runner) UpdateRepository(ctx context.Context, repoID string, param para } switch param.PoolBalancerType { - case params.PoolBalancerTypeRoundRobin, params.PoolBalancerTypeStack, param.PoolBalancerType: + case params.PoolBalancerTypeRoundRobin, params.PoolBalancerTypePack, params.PoolBalancerTypeNone: default: return params.Repository{}, runnerErrors.NewBadRequestError("invalid pool balancer type: %s", param.PoolBalancerType) }