From 6dea1c1937995d7b778b652904ca78cbe94f7538 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Mon, 21 Aug 2023 11:57:52 +0000 Subject: [PATCH] Add temporary replace to fork Signed-off-by: Gabriel Adrian Samfira --- go.mod | 2 +- runner/common/util.go | 6 +++++- runner/pool/pool.go | 24 +++++++++++++++++------- vendor/modules.txt | 2 +- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 064844bc..8c5abdf6 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( gorm.io/gorm v1.24.6 ) -replace github.com/google/go-github/v54 => github.com/gabriel-samfira/go-github/v54 v54.0.0-20230820134006-4b55d56a9b7f +replace github.com/google/go-github/v54 => github.com/gabriel-samfira/go-github/v54 v54.0.0-20230821112832-bbb536ee5a3a require ( github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect diff --git a/runner/common/util.go b/runner/common/util.go index c9989a9d..e9bc1fdc 100644 --- a/runner/common/util.go +++ b/runner/common/util.go @@ -55,6 +55,8 @@ type GithubClient interface { CreateOrganizationRegistrationToken(ctx context.Context, owner string) (*github.RegistrationToken, *github.Response, error) // GenerateOrgJITConfig generate a just-in-time configuration for an organization. GenerateOrgJITConfig(ctx context.Context, owner string, request *github.GenerateJITConfigRequest) (*github.JITRunnerConfig, *github.Response, error) + // ListOrganizationRunnerGroups lists all runner groups within an organization. + ListOrganizationRunnerGroups(ctx context.Context, org string, opts *github.ListOrgRunnerGroupOptions) (*github.RunnerGroups, *github.Response, error) } type GithubEnterpriseClient interface { @@ -67,6 +69,8 @@ type GithubEnterpriseClient interface { // ListRunnerApplicationDownloads returns a list of github runner application downloads for the // various supported operating systems and architectures. ListRunnerApplicationDownloads(ctx context.Context, enterprise string) ([]*github.RunnerApplicationDownload, *github.Response, error) - + // GenerateEnterpriseJITConfig generate a just-in-time configuration for an enterprise. GenerateEnterpriseJITConfig(ctx context.Context, enterprise string, request *github.GenerateJITConfigRequest) (*github.JITRunnerConfig, *github.Response, error) + // ListRunnerGroups lists all self-hosted runner groups configured in an enterprise. + ListRunnerGroups(ctx context.Context, enterprise string, opts *github.ListEnterpriseRunnerGroupOptions) (*github.EnterpriseRunnerGroups, *github.Response, error) } diff --git a/runner/pool/pool.go b/runner/pool/pool.go index 8e1e661a..fdfb6e8b 100644 --- a/runner/pool/pool.go +++ b/runner/pool/pool.go @@ -532,6 +532,8 @@ func (r *basePoolManager) cleanupOrphanedGithubRunners(runners []*github.Runner) r.log("instance %s is still being created, give it a chance to finish", dbInstance.Name) continue case commonParams.InstanceRunning: + // this check is not strictly needed, but can help avoid unnecessary strain on the provider. + // At worst, we will have a runner that is offline in github for 5 minutes before we reap it. if time.Since(dbInstance.UpdatedAt).Minutes() < 5 { // instance was updated recently. We give it a chance to register itself in github. r.log("instance %s was updated recently, skipping check", dbInstance.Name) @@ -716,6 +718,10 @@ func (r *basePoolManager) AddRunner(ctx context.Context, poolID string, aditiona return errors.Wrap(err, "creating instance") } + // labels := r.getLabelsForInstance(pool) + + // // Attempt to create JIT config + return nil } @@ -744,6 +750,16 @@ func (r *basePoolManager) setPoolRunningState(isRunning bool, failureReason stri r.mux.Unlock() } +func (r *basePoolManager) getLabelsForInstance(pool params.Pool) []string { + labels := []string{} + for _, tag := range pool.Tags { + labels = append(labels, tag.Name) + } + labels = append(labels, r.controllerLabel()) + labels = append(labels, r.poolLabel(pool.ID)) + return labels +} + func (r *basePoolManager) addInstanceToProvider(instance params.Instance) error { pool, err := r.helper.GetPoolByID(instance.PoolID) if err != nil { @@ -755,13 +771,7 @@ func (r *basePoolManager) addInstanceToProvider(instance params.Instance) error return fmt.Errorf("unknown provider %s for pool %s", pool.ProviderName, pool.ID) } - labels := []string{} - for _, tag := range pool.Tags { - labels = append(labels, tag.Name) - } - labels = append(labels, r.controllerLabel()) - labels = append(labels, r.poolLabel(pool.ID)) - + labels := r.getLabelsForInstance(pool) jwtValidity := pool.RunnerTimeout() entity := r.helper.String() diff --git a/vendor/modules.txt b/vendor/modules.txt index 2eae1345..24d7e7ab 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -439,4 +439,4 @@ gorm.io/gorm/logger gorm.io/gorm/migrator gorm.io/gorm/schema gorm.io/gorm/utils -# github.com/google/go-github/v54 => github.com/gabriel-samfira/go-github/v54 v54.0.0-20230820134006-4b55d56a9b7f +# github.com/google/go-github/v54 => github.com/gabriel-samfira/go-github/v54 v54.0.0-20230821112832-bbb536ee5a3a