Merge pull request #64 from cloudbase/move-pool-type

Move pool type in params
This commit is contained in:
Gabriel 2023-01-20 17:14:38 +02:00 committed by GitHub
commit 4ff7df8f6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 12 deletions

View file

@ -38,13 +38,13 @@ type InstanceJWTClaims struct {
Name string `json:"name"`
PoolID string `json:"provider_id"`
// Scope is either repository or organization
Scope common.PoolType `json:"scope"`
Scope params.PoolType `json:"scope"`
// Entity is the repo or org name
Entity string `json:"entity"`
jwt.StandardClaims
}
func NewInstanceJWTToken(instance params.Instance, secret, entity string, poolType common.PoolType, ttlMinutes uint) (string, error) {
func NewInstanceJWTToken(instance params.Instance, secret, entity string, poolType params.PoolType, ttlMinutes uint) (string, error) {
// Token expiration is equal to the bootstrap timeout set on the pool plus the polling
// interval garm uses to check for timed out runners. Runners that have not sent their info
// by the end of this interval are most likely failed and will be reaped by garm anyway.

View file

@ -23,10 +23,17 @@ import (
uuid "github.com/satori/go.uuid"
)
type PoolType string
type AddressType string
type EventType string
type EventLevel string
const (
RepositoryPool PoolType = "repository"
OrganizationPool PoolType = "organization"
EnterprisePool PoolType = "enterprise"
)
const (
PublicAddress AddressType = "public"
PrivateAddress AddressType = "private"
@ -170,6 +177,17 @@ func (p *Pool) RunnerTimeout() uint {
return p.RunnerBootstrapTimeout
}
func (p *Pool) PoolType() PoolType {
if p.RepoID != "" {
return RepositoryPool
} else if p.OrgID != "" {
return OrganizationPool
} else if p.EnterpriseID != "" {
return EnterprisePool
}
return ""
}
type Internal struct {
OAuth2Token string `json:"oauth2"`
ControllerID string `json:"controller_id"`

View file

@ -19,12 +19,7 @@ import (
"time"
)
type PoolType string
const (
RepositoryPool PoolType = "repository"
OrganizationPool PoolType = "organization"
PoolScaleDownInterval = 1 * time.Minute
PoolConsilitationInterval = 5 * time.Second
PoolReapTimeoutInterval = 5 * time.Minute

View file

@ -580,13 +580,9 @@ func (r *basePoolManager) addInstanceToProvider(instance params.Instance) error
labels = append(labels, r.poolLabel(pool.ID))
jwtValidity := pool.RunnerTimeout()
var poolType common.PoolType = common.RepositoryPool
if pool.OrgID != "" {
poolType = common.OrganizationPool
}
entity := r.helper.String()
jwtToken, err := auth.NewInstanceJWTToken(instance, r.helper.JwtToken(), entity, poolType, jwtValidity)
jwtToken, err := auth.NewInstanceJWTToken(instance, r.helper.JwtToken(), entity, pool.PoolType(), jwtValidity)
if err != nil {
return errors.Wrap(err, "fetching instance jwt token")
}