Fix lint errors
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
d7d6d1e31a
commit
e51f19acc8
15 changed files with 109 additions and 68 deletions
2
Makefile
2
Makefile
|
|
@ -106,7 +106,7 @@ $(LOCALBIN):
|
|||
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
|
||||
|
||||
## Tool Versions
|
||||
GOLANGCI_LINT_VERSION ?= v1.61.0
|
||||
GOLANGCI_LINT_VERSION ?= v1.64.8
|
||||
|
||||
.PHONY: golangci-lint
|
||||
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. If wrong version is installed, it will be overwritten.
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"math"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -63,7 +64,13 @@ func (i *instanceToken) NewInstanceJWTToken(instance params.Instance, entity str
|
|||
// 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.
|
||||
expireToken := time.Now().Add(time.Duration(ttlMinutes)*time.Minute + common.PoolReapTimeoutInterval)
|
||||
var ttl int
|
||||
if ttlMinutes > math.MaxInt {
|
||||
ttl = math.MaxInt
|
||||
} else {
|
||||
ttl = int(ttlMinutes)
|
||||
}
|
||||
expireToken := time.Now().Add(time.Duration(ttl)*time.Minute + common.PoolReapTimeoutInterval)
|
||||
expires := &jwt.NumericDate{
|
||||
Time: expireToken,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -238,16 +238,16 @@ type RunnerScaleSetStatistic struct {
|
|||
}
|
||||
|
||||
type RunnerScaleSet struct {
|
||||
Id int `json:"id,omitempty"`
|
||||
ID int `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
RunnerGroupId int `json:"runnerGroupId,omitempty"`
|
||||
RunnerGroupID int `json:"runnerGroupId,omitempty"`
|
||||
RunnerGroupName string `json:"runnerGroupName,omitempty"`
|
||||
Labels []Label `json:"labels,omitempty"`
|
||||
RunnerSetting RunnerSetting `json:"RunnerSetting,omitempty"`
|
||||
CreatedOn time.Time `json:"createdOn,omitempty"`
|
||||
RunnerJitConfigUrl string `json:"runnerJitConfigUrl,omitempty"`
|
||||
GetAcquirableJobsUrl string `json:"getAcquirableJobsUrl,omitempty"`
|
||||
AcquireJobsUrl string `json:"acquireJobsUrl,omitempty"`
|
||||
RunnerJitConfigURL string `json:"runnerJitConfigUrl,omitempty"`
|
||||
GetAcquirableJobsURL string `json:"getAcquirableJobsUrl,omitempty"`
|
||||
AcquireJobsURL string `json:"acquireJobsUrl,omitempty"`
|
||||
Statistics *RunnerScaleSetStatistic `json:"statistics,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Enabled *bool `json:"enabled,omitempty"`
|
||||
|
|
@ -327,19 +327,19 @@ type ActionsServiceAdminInfoRequest struct {
|
|||
}
|
||||
|
||||
type RunnerScaleSetSession struct {
|
||||
SessionId *uuid.UUID `json:"sessionId,omitempty"`
|
||||
SessionID *uuid.UUID `json:"sessionId,omitempty"`
|
||||
OwnerName string `json:"ownerName,omitempty"`
|
||||
RunnerScaleSet *RunnerScaleSet `json:"runnerScaleSet,omitempty"`
|
||||
MessageQueueUrl string `json:"messageQueueUrl,omitempty"`
|
||||
MessageQueueURL string `json:"messageQueueUrl,omitempty"`
|
||||
MessageQueueAccessToken string `json:"messageQueueAccessToken,omitempty"`
|
||||
Statistics *RunnerScaleSetStatistic `json:"statistics,omitempty"`
|
||||
}
|
||||
|
||||
func (a RunnerScaleSetSession) GetURL() (*url.URL, error) {
|
||||
if a.MessageQueueUrl == "" {
|
||||
if a.MessageQueueURL == "" {
|
||||
return nil, fmt.Errorf("no url specified")
|
||||
}
|
||||
u, err := url.ParseRequestURI(a.MessageQueueUrl)
|
||||
u, err := url.ParseRequestURI(a.MessageQueueURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse URL: %w", err)
|
||||
}
|
||||
|
|
@ -394,16 +394,16 @@ func (a RunnerScaleSetSession) ExpiresIn(t time.Duration) bool {
|
|||
}
|
||||
|
||||
type RunnerScaleSetMessage struct {
|
||||
MessageId int64 `json:"messageId"`
|
||||
MessageID int64 `json:"messageId"`
|
||||
MessageType string `json:"messageType"`
|
||||
Body string `json:"body"`
|
||||
Statistics *RunnerScaleSetStatistic `json:"statistics"`
|
||||
}
|
||||
|
||||
type RunnerReference struct {
|
||||
Id int `json:"id"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
RunnerScaleSetId int `json:"runnerScaleSetId"`
|
||||
RunnerScaleSetID int `json:"runnerScaleSetId"`
|
||||
CreatedOn time.Time `json:"createdOn"`
|
||||
RunnerGroupID uint64 `json:"runnerGroupId"`
|
||||
RunnerGroupName string `json:"runnerGroupName"`
|
||||
|
|
@ -431,9 +431,9 @@ type AcquirableJobList struct {
|
|||
}
|
||||
|
||||
type AcquirableJob struct {
|
||||
AcquireJobUrl string `json:"acquireJobUrl"`
|
||||
AcquireJobURL string `json:"acquireJobUrl"`
|
||||
MessageType string `json:"messageType"`
|
||||
RunnerRequestId int64 `json:"run0ne00rRequestId"`
|
||||
RunnerRequestID int64 `json:"run0ne00rRequestId"`
|
||||
RepositoryName string `json:"repositoryName"`
|
||||
OwnerName string `json:"ownerName"`
|
||||
JobWorkflowRef string `json:"jobWorkflowRef"`
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import (
|
|||
"encoding/json"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
|
|
@ -326,6 +327,21 @@ type Pool struct {
|
|||
Priority uint `json:"priority,omitempty"`
|
||||
}
|
||||
|
||||
func (p Pool) MinIdleRunnersAsInt() int {
|
||||
if p.MinIdleRunners > math.MaxInt {
|
||||
return math.MaxInt
|
||||
}
|
||||
|
||||
return int(p.MinIdleRunners)
|
||||
}
|
||||
|
||||
func (p Pool) MaxRunnersAsInt() int {
|
||||
if p.MaxRunners > math.MaxInt {
|
||||
return math.MaxInt
|
||||
}
|
||||
return int(p.MaxRunners)
|
||||
}
|
||||
|
||||
func (p Pool) GithubEntity() (GithubEntity, error) {
|
||||
switch p.PoolType() {
|
||||
case GithubEntityTypeRepository:
|
||||
|
|
@ -611,6 +627,14 @@ type ControllerInfo struct {
|
|||
Version string `json:"version,omitempty"`
|
||||
}
|
||||
|
||||
func (c *ControllerInfo) JobBackoff() time.Duration {
|
||||
if math.MaxInt64 > c.MinimumJobAgeBackoff {
|
||||
return time.Duration(math.MaxInt64)
|
||||
}
|
||||
|
||||
return time.Duration(int64(c.MinimumJobAgeBackoff))
|
||||
}
|
||||
|
||||
type GithubCredentials struct {
|
||||
ID uint `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ const (
|
|||
|
||||
func NewEntityPoolManager(ctx context.Context, entity params.GithubEntity, instanceTokenGetter auth.InstanceTokenGetter, providers map[string]common.Provider, store dbCommon.Store) (common.PoolManager, error) {
|
||||
ctx = garmUtil.WithSlogContext(ctx, slog.Any("pool_mgr", entity.String()), slog.Any("pool_type", entity.EntityType))
|
||||
ghc, err := ghClient.GithubClient(ctx, entity)
|
||||
ghc, err := ghClient.Client(ctx, entity)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "getting github client")
|
||||
}
|
||||
|
|
@ -1044,7 +1044,7 @@ func (r *basePoolManager) scaleDownOnePool(ctx context.Context, pool params.Pool
|
|||
return nil
|
||||
}
|
||||
|
||||
surplus := float64(len(idleWorkers) - int(pool.MinIdleRunners))
|
||||
surplus := float64(len(idleWorkers) - pool.MinIdleRunnersAsInt())
|
||||
|
||||
if surplus <= 0 {
|
||||
return nil
|
||||
|
|
@ -1124,7 +1124,7 @@ func (r *basePoolManager) addRunnerToPool(pool params.Pool, aditionalLabels []st
|
|||
return fmt.Errorf("failed to list pool instances: %w", err)
|
||||
}
|
||||
|
||||
if poolInstanceCount >= int64(pool.MaxRunners) {
|
||||
if poolInstanceCount >= int64(pool.MaxRunnersAsInt()) {
|
||||
return fmt.Errorf("max workers (%d) reached for pool %s", pool.MaxRunners, pool.ID)
|
||||
}
|
||||
|
||||
|
|
@ -1160,14 +1160,19 @@ func (r *basePoolManager) ensureIdleRunnersForOnePool(pool params.Pool) error {
|
|||
}
|
||||
|
||||
var required int
|
||||
if len(idleOrPendingWorkers) < int(pool.MinIdleRunners) {
|
||||
if len(idleOrPendingWorkers) < pool.MinIdleRunnersAsInt() {
|
||||
// get the needed delta.
|
||||
required = int(pool.MinIdleRunners) - len(idleOrPendingWorkers)
|
||||
required = pool.MinIdleRunnersAsInt() - len(idleOrPendingWorkers)
|
||||
|
||||
projectedInstanceCount := len(existingInstances) + required
|
||||
if uint(projectedInstanceCount) > pool.MaxRunners {
|
||||
|
||||
var projected uint
|
||||
if projectedInstanceCount > 0 {
|
||||
projected = uint(projectedInstanceCount)
|
||||
}
|
||||
if projected > pool.MaxRunners {
|
||||
// ensure we don't go above max workers
|
||||
delta := projectedInstanceCount - int(pool.MaxRunners)
|
||||
delta := projectedInstanceCount - pool.MaxRunnersAsInt()
|
||||
required -= delta
|
||||
}
|
||||
}
|
||||
|
|
@ -1748,7 +1753,7 @@ func (r *basePoolManager) consumeQueuedJobs() error {
|
|||
continue
|
||||
}
|
||||
|
||||
if time.Since(job.UpdatedAt) < time.Second*time.Duration(r.controllerInfo.MinimumJobAgeBackoff) {
|
||||
if time.Since(job.UpdatedAt) < time.Second*r.controllerInfo.JobBackoff() {
|
||||
// give the idle runners a chance to pick up the job.
|
||||
slog.DebugContext(
|
||||
r.ctx, "job backoff not reached", "backoff_interval", r.controllerInfo.MinimumJobAgeBackoff,
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ func (r *basePoolManager) handleControllerUpdateEvent(controllerInfo params.Cont
|
|||
func (r *basePoolManager) getClientOrStub() runnerCommon.GithubClient {
|
||||
var err error
|
||||
var ghc runnerCommon.GithubClient
|
||||
ghc, err = ghClient.GithubClient(r.ctx, r.entity)
|
||||
ghc, err = ghClient.Client(r.ctx, r.entity)
|
||||
if err != nil {
|
||||
slog.WarnContext(r.ctx, "failed to create github client", "error", err)
|
||||
ghc = &stubGithubClient{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ func (suite *GarmSuite) TestGithubCredentialsErrorOnDuplicateCredentialsName() {
|
|||
creds, err := suite.createDummyCredentials(dummyCredentialsName, defaultEndpointName)
|
||||
suite.NoError(err)
|
||||
t.Cleanup(func() {
|
||||
suite.DeleteGithubCredential(int64(creds.ID))
|
||||
suite.DeleteGithubCredential(int64(creds.ID)) //nolint:gosec
|
||||
})
|
||||
|
||||
createCredsParams := params.CreateGithubCredentialsParams{
|
||||
|
|
@ -54,10 +54,10 @@ func (suite *GarmSuite) TestGithubCredentialsFailsToDeleteWhenInUse() {
|
|||
suite.NoError(err)
|
||||
t.Cleanup(func() {
|
||||
deleteRepo(suite.cli, suite.authToken, repo.ID)
|
||||
deleteGithubCredentials(suite.cli, suite.authToken, int64(creds.ID))
|
||||
deleteGithubCredentials(suite.cli, suite.authToken, int64(creds.ID)) //nolint:gosec
|
||||
})
|
||||
|
||||
err = deleteGithubCredentials(suite.cli, suite.authToken, int64(creds.ID))
|
||||
err = deleteGithubCredentials(suite.cli, suite.authToken, int64(creds.ID)) //nolint:gosec
|
||||
suite.Error(err, "expected error when deleting credentials in use")
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +120,7 @@ func (suite *GarmSuite) TestGithubCredentialsUpdateFailsWhenBothPATAndAppAreSupp
|
|||
creds, err := suite.createDummyCredentials(dummyCredentialsName, defaultEndpointName)
|
||||
suite.NoError(err)
|
||||
t.Cleanup(func() {
|
||||
suite.DeleteGithubCredential(int64(creds.ID))
|
||||
suite.DeleteGithubCredential(int64(creds.ID)) //nolint:gosec
|
||||
})
|
||||
|
||||
privateKeyBytes, err := getTestFileContents("certs/srv-key.pem")
|
||||
|
|
@ -135,7 +135,7 @@ func (suite *GarmSuite) TestGithubCredentialsUpdateFailsWhenBothPATAndAppAreSupp
|
|||
PrivateKeyBytes: privateKeyBytes,
|
||||
},
|
||||
}
|
||||
_, err = updateGithubCredentials(suite.cli, suite.authToken, int64(creds.ID), updateCredsParams)
|
||||
_, err = updateGithubCredentials(suite.cli, suite.authToken, int64(creds.ID), updateCredsParams) //nolint:gosec
|
||||
suite.Error(err, "expected error when updating credentials with both PAT and App")
|
||||
expectAPIStatusCode(err, 400)
|
||||
}
|
||||
|
|
@ -182,7 +182,7 @@ func (suite *GarmSuite) TestGithubCredentialsFailsOnDuplicateName() {
|
|||
creds, err := suite.createDummyCredentials(dummyCredentialsName, defaultEndpointName)
|
||||
suite.NoError(err)
|
||||
t.Cleanup(func() {
|
||||
suite.DeleteGithubCredential(int64(creds.ID))
|
||||
suite.DeleteGithubCredential(int64(creds.ID)) //nolint:gosec
|
||||
})
|
||||
|
||||
createCredsParams := params.CreateGithubCredentialsParams{
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ func (suite *GarmSuite) TestGithubEndpointDeletionFailsWhenCredentialsExist() {
|
|||
err = deleteGithubEndpoint(suite.cli, suite.authToken, endpoint.Name)
|
||||
suite.Error(err, "expected error when deleting endpoint with credentials")
|
||||
|
||||
err = suite.DeleteGithubCredential(int64(creds.ID))
|
||||
err = suite.DeleteGithubCredential(int64(creds.ID)) //nolint:gosec
|
||||
suite.NoError(err, "error deleting credentials")
|
||||
err = suite.DeleteGithubEndpoint(endpoint.Name)
|
||||
suite.NoError(err, "error deleting endpoint")
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func (suite *GarmSuite) WaitPoolInstances(poolID string, status commonParams.Ins
|
|||
"Pool instance with pool_id %s reached status %v and runner_status %v, desired_instance_count %d, pool_instance_count %d",
|
||||
poolID, status, runnerStatus, instancesCount,
|
||||
len(poolInstances))
|
||||
if int(pool.MinIdleRunners) == instancesCount {
|
||||
if pool.MinIdleRunnersAsInt() == instancesCount {
|
||||
return nil
|
||||
}
|
||||
time.Sleep(5 * time.Second)
|
||||
|
|
|
|||
|
|
@ -445,7 +445,7 @@ func (g *githubClient) GithubBaseURL() *url.URL {
|
|||
return g.cli.BaseURL
|
||||
}
|
||||
|
||||
func GithubClient(ctx context.Context, entity params.GithubEntity) (common.GithubClient, error) {
|
||||
func Client(ctx context.Context, entity params.GithubEntity) (common.GithubClient, error) {
|
||||
// func GithubClient(ctx context.Context, entity params.GithubEntity) (common.GithubClient, error) {
|
||||
httpClient, err := entity.Credentials.GetHTTPClient(ctx)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -29,10 +29,10 @@ type acquireJobsResult struct {
|
|||
Value []int64 `json:"value"`
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) AcquireJobs(ctx context.Context, runnerScaleSetId int, messageQueueAccessToken string, requestIds []int64) ([]int64, error) {
|
||||
u := fmt.Sprintf("%s/%d/acquirejobs?api-version=6.0-preview", scaleSetEndpoint, runnerScaleSetId)
|
||||
func (s *ScaleSetClient) AcquireJobs(ctx context.Context, runnerScaleSetID int, messageQueueAccessToken string, requestIDs []int64) ([]int64, error) {
|
||||
u := fmt.Sprintf("%s/%d/acquirejobs?api-version=6.0-preview", scaleSetEndpoint, runnerScaleSetID)
|
||||
|
||||
body, err := json.Marshal(requestIds)
|
||||
body, err := json.Marshal(requestIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -60,8 +60,8 @@ func (s *ScaleSetClient) AcquireJobs(ctx context.Context, runnerScaleSetId int,
|
|||
return acquiredJobs.Value, nil
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) GetAcquirableJobs(ctx context.Context, runnerScaleSetId int) (params.AcquirableJobList, error) {
|
||||
path := fmt.Sprintf("%d/acquirablejobs", runnerScaleSetId)
|
||||
func (s *ScaleSetClient) GetAcquirableJobs(ctx context.Context, runnerScaleSetID int) (params.AcquirableJobList, error) {
|
||||
path := fmt.Sprintf("%d/acquirablejobs", runnerScaleSetID)
|
||||
|
||||
req, err := s.newActionsRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -17,11 +17,12 @@ package scalesets
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"math/rand/v2"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
|
@ -103,7 +104,7 @@ func (m *MessageSession) SessionsRelativeURL() (string, error) {
|
|||
if m.session.RunnerScaleSet == nil {
|
||||
return "", fmt.Errorf("runner scale set is nil")
|
||||
}
|
||||
relativePath := fmt.Sprintf("%s/%d/sessions/%s", scaleSetEndpoint, m.session.RunnerScaleSet.Id, m.session.SessionId.String())
|
||||
relativePath := fmt.Sprintf("%s/%d/sessions/%s", scaleSetEndpoint, m.session.RunnerScaleSet.ID, m.session.SessionID.String())
|
||||
return relativePath, nil
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +139,11 @@ func (m *MessageSession) maybeRefreshToken(ctx context.Context) error {
|
|||
return fmt.Errorf("session is nil")
|
||||
}
|
||||
// add some jitter
|
||||
jitter := time.Duration(rand.IntN(10000)) * time.Millisecond
|
||||
randInt, err := rand.Int(rand.Reader, big.NewInt(1000))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get a random number")
|
||||
}
|
||||
jitter := time.Duration(randInt.Int64()) * time.Millisecond
|
||||
if m.session.ExpiresIn(2*time.Minute + jitter) {
|
||||
if err := m.Refresh(ctx); err != nil {
|
||||
return fmt.Errorf("failed to refresh message queue token: %w", err)
|
||||
|
|
@ -147,15 +152,15 @@ func (m *MessageSession) maybeRefreshToken(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *MessageSession) GetMessage(ctx context.Context, lastMessageId int64, maxCapacity uint) (params.RunnerScaleSetMessage, error) {
|
||||
u, err := url.Parse(m.session.MessageQueueUrl)
|
||||
func (m *MessageSession) GetMessage(ctx context.Context, lastMessageID int64, maxCapacity uint) (params.RunnerScaleSetMessage, error) {
|
||||
u, err := url.Parse(m.session.MessageQueueURL)
|
||||
if err != nil {
|
||||
return params.RunnerScaleSetMessage{}, err
|
||||
}
|
||||
|
||||
if lastMessageId > 0 {
|
||||
if lastMessageID > 0 {
|
||||
q := u.Query()
|
||||
q.Set("lastMessageId", strconv.FormatInt(lastMessageId, 10))
|
||||
q.Set("lastMessageId", strconv.FormatInt(lastMessageID, 10))
|
||||
u.RawQuery = q.Encode()
|
||||
}
|
||||
|
||||
|
|
@ -185,13 +190,13 @@ func (m *MessageSession) GetMessage(ctx context.Context, lastMessageId int64, ma
|
|||
return message, nil
|
||||
}
|
||||
|
||||
func (m *MessageSession) DeleteMessage(ctx context.Context, messageId int64) error {
|
||||
u, err := url.Parse(m.session.MessageQueueUrl)
|
||||
func (m *MessageSession) DeleteMessage(ctx context.Context, messageID int64) error {
|
||||
u, err := url.Parse(m.session.MessageQueueURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
u.Path = fmt.Sprintf("%s/%d", u.Path, messageId)
|
||||
u.Path = fmt.Sprintf("%s/%d", u.Path, messageID)
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, u.String(), nil)
|
||||
if err != nil {
|
||||
|
|
@ -210,8 +215,8 @@ func (m *MessageSession) DeleteMessage(ctx context.Context, messageId int64) err
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) CreateMessageSession(ctx context.Context, runnerScaleSetId int, owner string) (*MessageSession, error) {
|
||||
path := fmt.Sprintf("%s/%d/sessions", scaleSetEndpoint, runnerScaleSetId)
|
||||
func (s *ScaleSetClient) CreateMessageSession(ctx context.Context, runnerScaleSetID int, owner string) (*MessageSession, error) {
|
||||
path := fmt.Sprintf("%s/%d/sessions", scaleSetEndpoint, runnerScaleSetID)
|
||||
|
||||
newSession := params.RunnerScaleSetSession{
|
||||
OwnerName: owner,
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ func (s *ScaleSetClient) GenerateJitRunnerConfig(ctx context.Context, runnerName
|
|||
return params.RunnerScaleSetJitRunnerConfig{}, err
|
||||
}
|
||||
|
||||
req, err := s.newActionsRequest(ctx, http.MethodPost, scaleSet.RunnerJitConfigUrl, bytes.NewBuffer(body))
|
||||
req, err := s.newActionsRequest(ctx, http.MethodPost, scaleSet.RunnerJitConfigURL, bytes.NewBuffer(body))
|
||||
if err != nil {
|
||||
return params.RunnerScaleSetJitRunnerConfig{}, fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
|
|
@ -59,8 +59,8 @@ func (s *ScaleSetClient) GenerateJitRunnerConfig(ctx context.Context, runnerName
|
|||
return runnerJitConfig, nil
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) GetRunner(ctx context.Context, runnerId int64) (params.RunnerReference, error) {
|
||||
path := fmt.Sprintf("%s/%d", runnerEndpoint, runnerId)
|
||||
func (s *ScaleSetClient) GetRunner(ctx context.Context, runnerID int64) (params.RunnerReference, error) {
|
||||
path := fmt.Sprintf("%s/%d", runnerEndpoint, runnerID)
|
||||
|
||||
req, err := s.newActionsRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
|
|
@ -111,8 +111,8 @@ func (s *ScaleSetClient) GetRunnerByName(ctx context.Context, runnerName string)
|
|||
return runnerList.RunnerReferences[0], nil
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) RemoveRunner(ctx context.Context, runnerId int64) error {
|
||||
path := fmt.Sprintf("%s/%d", runnerEndpoint, runnerId)
|
||||
func (s *ScaleSetClient) RemoveRunner(ctx context.Context, runnerID int64) error {
|
||||
path := fmt.Sprintf("%s/%d", runnerEndpoint, runnerID)
|
||||
|
||||
req, err := s.newActionsRequest(ctx, http.MethodDelete, path, nil)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ const (
|
|||
HeaderGitHubRequestID = "X-GitHub-Request-Id"
|
||||
)
|
||||
|
||||
func (s *ScaleSetClient) GetRunnerScaleSetByNameAndRunnerGroup(ctx context.Context, runnerGroupId int, name string) (params.RunnerScaleSet, error) {
|
||||
path := fmt.Sprintf("%s?runnerGroupId=%d&name=%s", scaleSetEndpoint, runnerGroupId, name)
|
||||
func (s *ScaleSetClient) GetRunnerScaleSetByNameAndRunnerGroup(ctx context.Context, runnerGroupID int, name string) (params.RunnerScaleSet, error) {
|
||||
path := fmt.Sprintf("%s?runnerGroupId=%d&name=%s", scaleSetEndpoint, runnerGroupID, name)
|
||||
req, err := s.newActionsRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return params.RunnerScaleSet{}, err
|
||||
|
|
@ -53,7 +53,7 @@ func (s *ScaleSetClient) GetRunnerScaleSetByNameAndRunnerGroup(ctx context.Conte
|
|||
return params.RunnerScaleSet{}, fmt.Errorf("failed to decode response: %w", err)
|
||||
}
|
||||
if runnerScaleSetList.Count == 0 {
|
||||
return params.RunnerScaleSet{}, runnerErrors.NewNotFoundError("runner scale set with name %s and runner group ID %d was not found", name, runnerGroupId)
|
||||
return params.RunnerScaleSet{}, runnerErrors.NewNotFoundError("runner scale set with name %s and runner group ID %d was not found", name, runnerGroupID)
|
||||
}
|
||||
|
||||
// Runner scale sets must have a uniqe name. Attempting to create a runner scale set with the same name as
|
||||
|
|
@ -61,8 +61,8 @@ func (s *ScaleSetClient) GetRunnerScaleSetByNameAndRunnerGroup(ctx context.Conte
|
|||
return runnerScaleSetList.RunnerScaleSets[0], nil
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) GetRunnerScaleSetById(ctx context.Context, runnerScaleSetId int) (params.RunnerScaleSet, error) {
|
||||
path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetId)
|
||||
func (s *ScaleSetClient) GetRunnerScaleSetByID(ctx context.Context, runnerScaleSetID int) (params.RunnerScaleSet, error) {
|
||||
path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetID)
|
||||
req, err := s.newActionsRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return params.RunnerScaleSet{}, err
|
||||
|
|
@ -70,7 +70,7 @@ func (s *ScaleSetClient) GetRunnerScaleSetById(ctx context.Context, runnerScaleS
|
|||
|
||||
resp, err := s.Do(req)
|
||||
if err != nil {
|
||||
return params.RunnerScaleSet{}, fmt.Errorf("failed to get runner scaleset with ID %d: %w", runnerScaleSetId, err)
|
||||
return params.RunnerScaleSet{}, fmt.Errorf("failed to get runner scaleset with ID %d: %w", runnerScaleSetID, err)
|
||||
}
|
||||
|
||||
var runnerScaleSet params.RunnerScaleSet
|
||||
|
|
@ -127,8 +127,8 @@ func (s *ScaleSetClient) CreateRunnerScaleSet(ctx context.Context, runnerScaleSe
|
|||
return createdRunnerScaleSet, nil
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) UpdateRunnerScaleSet(ctx context.Context, runnerScaleSetId int, runnerScaleSet params.RunnerScaleSet) (params.RunnerScaleSet, error) {
|
||||
path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetId)
|
||||
func (s *ScaleSetClient) UpdateRunnerScaleSet(ctx context.Context, runnerScaleSetID int, runnerScaleSet params.RunnerScaleSet) (params.RunnerScaleSet, error) {
|
||||
path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetID)
|
||||
|
||||
body, err := json.Marshal(runnerScaleSet)
|
||||
if err != nil {
|
||||
|
|
@ -152,8 +152,8 @@ func (s *ScaleSetClient) UpdateRunnerScaleSet(ctx context.Context, runnerScaleSe
|
|||
return ret, nil
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) DeleteRunnerScaleSet(ctx context.Context, runnerScaleSetId int) error {
|
||||
path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetId)
|
||||
func (s *ScaleSetClient) DeleteRunnerScaleSet(ctx context.Context, runnerScaleSetID int) error {
|
||||
path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetID)
|
||||
req, err := s.newActionsRequest(ctx, http.MethodDelete, path, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -26,12 +26,12 @@ func (s *ScaleSetClient) newActionsRequest(ctx context.Context, method, path str
|
|||
return nil, fmt.Errorf("failed to update token: %w", err)
|
||||
}
|
||||
|
||||
actionsUri, err := s.actionsServiceInfo.GetURL()
|
||||
actionsURI, err := s.actionsServiceInfo.GetURL()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get pipeline URL: %w", err)
|
||||
}
|
||||
|
||||
uri, err := actionsUri.Parse(path)
|
||||
uri, err := actionsURI.Parse(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse path: %w", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue