Fix lint errors

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2025-04-06 17:54:35 +00:00
parent d7d6d1e31a
commit e51f19acc8
15 changed files with 109 additions and 68 deletions

View file

@ -106,7 +106,7 @@ $(LOCALBIN):
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
## Tool Versions ## Tool Versions
GOLANGCI_LINT_VERSION ?= v1.61.0 GOLANGCI_LINT_VERSION ?= v1.64.8
.PHONY: golangci-lint .PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. If wrong version is installed, it will be overwritten. golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. If wrong version is installed, it will be overwritten.

View file

@ -18,6 +18,7 @@ import (
"context" "context"
"fmt" "fmt"
"log/slog" "log/slog"
"math"
"net/http" "net/http"
"strings" "strings"
"time" "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 // 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 // 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. // 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{ expires := &jwt.NumericDate{
Time: expireToken, Time: expireToken,
} }

View file

@ -238,16 +238,16 @@ type RunnerScaleSetStatistic struct {
} }
type RunnerScaleSet struct { type RunnerScaleSet struct {
Id int `json:"id,omitempty"` ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
RunnerGroupId int `json:"runnerGroupId,omitempty"` RunnerGroupID int `json:"runnerGroupId,omitempty"`
RunnerGroupName string `json:"runnerGroupName,omitempty"` RunnerGroupName string `json:"runnerGroupName,omitempty"`
Labels []Label `json:"labels,omitempty"` Labels []Label `json:"labels,omitempty"`
RunnerSetting RunnerSetting `json:"RunnerSetting,omitempty"` RunnerSetting RunnerSetting `json:"RunnerSetting,omitempty"`
CreatedOn time.Time `json:"createdOn,omitempty"` CreatedOn time.Time `json:"createdOn,omitempty"`
RunnerJitConfigUrl string `json:"runnerJitConfigUrl,omitempty"` RunnerJitConfigURL string `json:"runnerJitConfigUrl,omitempty"`
GetAcquirableJobsUrl string `json:"getAcquirableJobsUrl,omitempty"` GetAcquirableJobsURL string `json:"getAcquirableJobsUrl,omitempty"`
AcquireJobsUrl string `json:"acquireJobsUrl,omitempty"` AcquireJobsURL string `json:"acquireJobsUrl,omitempty"`
Statistics *RunnerScaleSetStatistic `json:"statistics,omitempty"` Statistics *RunnerScaleSetStatistic `json:"statistics,omitempty"`
Status string `json:"status,omitempty"` Status string `json:"status,omitempty"`
Enabled *bool `json:"enabled,omitempty"` Enabled *bool `json:"enabled,omitempty"`
@ -327,19 +327,19 @@ type ActionsServiceAdminInfoRequest struct {
} }
type RunnerScaleSetSession struct { type RunnerScaleSetSession struct {
SessionId *uuid.UUID `json:"sessionId,omitempty"` SessionID *uuid.UUID `json:"sessionId,omitempty"`
OwnerName string `json:"ownerName,omitempty"` OwnerName string `json:"ownerName,omitempty"`
RunnerScaleSet *RunnerScaleSet `json:"runnerScaleSet,omitempty"` RunnerScaleSet *RunnerScaleSet `json:"runnerScaleSet,omitempty"`
MessageQueueUrl string `json:"messageQueueUrl,omitempty"` MessageQueueURL string `json:"messageQueueUrl,omitempty"`
MessageQueueAccessToken string `json:"messageQueueAccessToken,omitempty"` MessageQueueAccessToken string `json:"messageQueueAccessToken,omitempty"`
Statistics *RunnerScaleSetStatistic `json:"statistics,omitempty"` Statistics *RunnerScaleSetStatistic `json:"statistics,omitempty"`
} }
func (a RunnerScaleSetSession) GetURL() (*url.URL, error) { func (a RunnerScaleSetSession) GetURL() (*url.URL, error) {
if a.MessageQueueUrl == "" { if a.MessageQueueURL == "" {
return nil, fmt.Errorf("no url specified") return nil, fmt.Errorf("no url specified")
} }
u, err := url.ParseRequestURI(a.MessageQueueUrl) u, err := url.ParseRequestURI(a.MessageQueueURL)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to parse URL: %w", err) 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 { type RunnerScaleSetMessage struct {
MessageId int64 `json:"messageId"` MessageID int64 `json:"messageId"`
MessageType string `json:"messageType"` MessageType string `json:"messageType"`
Body string `json:"body"` Body string `json:"body"`
Statistics *RunnerScaleSetStatistic `json:"statistics"` Statistics *RunnerScaleSetStatistic `json:"statistics"`
} }
type RunnerReference struct { type RunnerReference struct {
Id int `json:"id"` ID int `json:"id"`
Name string `json:"name"` Name string `json:"name"`
RunnerScaleSetId int `json:"runnerScaleSetId"` RunnerScaleSetID int `json:"runnerScaleSetId"`
CreatedOn time.Time `json:"createdOn"` CreatedOn time.Time `json:"createdOn"`
RunnerGroupID uint64 `json:"runnerGroupId"` RunnerGroupID uint64 `json:"runnerGroupId"`
RunnerGroupName string `json:"runnerGroupName"` RunnerGroupName string `json:"runnerGroupName"`
@ -431,9 +431,9 @@ type AcquirableJobList struct {
} }
type AcquirableJob struct { type AcquirableJob struct {
AcquireJobUrl string `json:"acquireJobUrl"` AcquireJobURL string `json:"acquireJobUrl"`
MessageType string `json:"messageType"` MessageType string `json:"messageType"`
RunnerRequestId int64 `json:"run0ne00rRequestId"` RunnerRequestID int64 `json:"run0ne00rRequestId"`
RepositoryName string `json:"repositoryName"` RepositoryName string `json:"repositoryName"`
OwnerName string `json:"ownerName"` OwnerName string `json:"ownerName"`
JobWorkflowRef string `json:"jobWorkflowRef"` JobWorkflowRef string `json:"jobWorkflowRef"`

View file

@ -22,6 +22,7 @@ import (
"encoding/json" "encoding/json"
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"math"
"net/http" "net/http"
"time" "time"
@ -326,6 +327,21 @@ type Pool struct {
Priority uint `json:"priority,omitempty"` 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) { func (p Pool) GithubEntity() (GithubEntity, error) {
switch p.PoolType() { switch p.PoolType() {
case GithubEntityTypeRepository: case GithubEntityTypeRepository:
@ -611,6 +627,14 @@ type ControllerInfo struct {
Version string `json:"version,omitempty"` 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 { type GithubCredentials struct {
ID uint `json:"id,omitempty"` ID uint `json:"id,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`

View file

@ -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) { 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)) 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 { if err != nil {
return nil, errors.Wrap(err, "getting github client") return nil, errors.Wrap(err, "getting github client")
} }
@ -1044,7 +1044,7 @@ func (r *basePoolManager) scaleDownOnePool(ctx context.Context, pool params.Pool
return nil return nil
} }
surplus := float64(len(idleWorkers) - int(pool.MinIdleRunners)) surplus := float64(len(idleWorkers) - pool.MinIdleRunnersAsInt())
if surplus <= 0 { if surplus <= 0 {
return nil 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) 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) 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 var required int
if len(idleOrPendingWorkers) < int(pool.MinIdleRunners) { if len(idleOrPendingWorkers) < pool.MinIdleRunnersAsInt() {
// get the needed delta. // get the needed delta.
required = int(pool.MinIdleRunners) - len(idleOrPendingWorkers) required = pool.MinIdleRunnersAsInt() - len(idleOrPendingWorkers)
projectedInstanceCount := len(existingInstances) + required 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 // ensure we don't go above max workers
delta := projectedInstanceCount - int(pool.MaxRunners) delta := projectedInstanceCount - pool.MaxRunnersAsInt()
required -= delta required -= delta
} }
} }
@ -1748,7 +1753,7 @@ func (r *basePoolManager) consumeQueuedJobs() error {
continue 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. // give the idle runners a chance to pick up the job.
slog.DebugContext( slog.DebugContext(
r.ctx, "job backoff not reached", "backoff_interval", r.controllerInfo.MinimumJobAgeBackoff, r.ctx, "job backoff not reached", "backoff_interval", r.controllerInfo.MinimumJobAgeBackoff,

View file

@ -28,7 +28,7 @@ func (r *basePoolManager) handleControllerUpdateEvent(controllerInfo params.Cont
func (r *basePoolManager) getClientOrStub() runnerCommon.GithubClient { func (r *basePoolManager) getClientOrStub() runnerCommon.GithubClient {
var err error var err error
var ghc runnerCommon.GithubClient var ghc runnerCommon.GithubClient
ghc, err = ghClient.GithubClient(r.ctx, r.entity) ghc, err = ghClient.Client(r.ctx, r.entity)
if err != nil { if err != nil {
slog.WarnContext(r.ctx, "failed to create github client", "error", err) slog.WarnContext(r.ctx, "failed to create github client", "error", err)
ghc = &stubGithubClient{ ghc = &stubGithubClient{

View file

@ -18,7 +18,7 @@ func (suite *GarmSuite) TestGithubCredentialsErrorOnDuplicateCredentialsName() {
creds, err := suite.createDummyCredentials(dummyCredentialsName, defaultEndpointName) creds, err := suite.createDummyCredentials(dummyCredentialsName, defaultEndpointName)
suite.NoError(err) suite.NoError(err)
t.Cleanup(func() { t.Cleanup(func() {
suite.DeleteGithubCredential(int64(creds.ID)) suite.DeleteGithubCredential(int64(creds.ID)) //nolint:gosec
}) })
createCredsParams := params.CreateGithubCredentialsParams{ createCredsParams := params.CreateGithubCredentialsParams{
@ -54,10 +54,10 @@ func (suite *GarmSuite) TestGithubCredentialsFailsToDeleteWhenInUse() {
suite.NoError(err) suite.NoError(err)
t.Cleanup(func() { t.Cleanup(func() {
deleteRepo(suite.cli, suite.authToken, repo.ID) 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") suite.Error(err, "expected error when deleting credentials in use")
} }
@ -120,7 +120,7 @@ func (suite *GarmSuite) TestGithubCredentialsUpdateFailsWhenBothPATAndAppAreSupp
creds, err := suite.createDummyCredentials(dummyCredentialsName, defaultEndpointName) creds, err := suite.createDummyCredentials(dummyCredentialsName, defaultEndpointName)
suite.NoError(err) suite.NoError(err)
t.Cleanup(func() { t.Cleanup(func() {
suite.DeleteGithubCredential(int64(creds.ID)) suite.DeleteGithubCredential(int64(creds.ID)) //nolint:gosec
}) })
privateKeyBytes, err := getTestFileContents("certs/srv-key.pem") privateKeyBytes, err := getTestFileContents("certs/srv-key.pem")
@ -135,7 +135,7 @@ func (suite *GarmSuite) TestGithubCredentialsUpdateFailsWhenBothPATAndAppAreSupp
PrivateKeyBytes: privateKeyBytes, 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") suite.Error(err, "expected error when updating credentials with both PAT and App")
expectAPIStatusCode(err, 400) expectAPIStatusCode(err, 400)
} }
@ -182,7 +182,7 @@ func (suite *GarmSuite) TestGithubCredentialsFailsOnDuplicateName() {
creds, err := suite.createDummyCredentials(dummyCredentialsName, defaultEndpointName) creds, err := suite.createDummyCredentials(dummyCredentialsName, defaultEndpointName)
suite.NoError(err) suite.NoError(err)
t.Cleanup(func() { t.Cleanup(func() {
suite.DeleteGithubCredential(int64(creds.ID)) suite.DeleteGithubCredential(int64(creds.ID)) //nolint:gosec
}) })
createCredsParams := params.CreateGithubCredentialsParams{ createCredsParams := params.CreateGithubCredentialsParams{

View file

@ -100,7 +100,7 @@ func (suite *GarmSuite) TestGithubEndpointDeletionFailsWhenCredentialsExist() {
err = deleteGithubEndpoint(suite.cli, suite.authToken, endpoint.Name) err = deleteGithubEndpoint(suite.cli, suite.authToken, endpoint.Name)
suite.Error(err, "expected error when deleting endpoint with credentials") 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") suite.NoError(err, "error deleting credentials")
err = suite.DeleteGithubEndpoint(endpoint.Name) err = suite.DeleteGithubEndpoint(endpoint.Name)
suite.NoError(err, "error deleting endpoint") suite.NoError(err, "error deleting endpoint")

View file

@ -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", "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, poolID, status, runnerStatus, instancesCount,
len(poolInstances)) len(poolInstances))
if int(pool.MinIdleRunners) == instancesCount { if pool.MinIdleRunnersAsInt() == instancesCount {
return nil return nil
} }
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)

View file

@ -445,7 +445,7 @@ func (g *githubClient) GithubBaseURL() *url.URL {
return g.cli.BaseURL 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) { // func GithubClient(ctx context.Context, entity params.GithubEntity) (common.GithubClient, error) {
httpClient, err := entity.Credentials.GetHTTPClient(ctx) httpClient, err := entity.Credentials.GetHTTPClient(ctx)
if err != nil { if err != nil {

View file

@ -29,10 +29,10 @@ type acquireJobsResult struct {
Value []int64 `json:"value"` Value []int64 `json:"value"`
} }
func (s *ScaleSetClient) AcquireJobs(ctx context.Context, runnerScaleSetId int, messageQueueAccessToken string, requestIds []int64) ([]int64, error) { 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) 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 { if err != nil {
return nil, err return nil, err
} }
@ -60,8 +60,8 @@ func (s *ScaleSetClient) AcquireJobs(ctx context.Context, runnerScaleSetId int,
return acquiredJobs.Value, nil return acquiredJobs.Value, nil
} }
func (s *ScaleSetClient) GetAcquirableJobs(ctx context.Context, runnerScaleSetId int) (params.AcquirableJobList, error) { func (s *ScaleSetClient) GetAcquirableJobs(ctx context.Context, runnerScaleSetID int) (params.AcquirableJobList, error) {
path := fmt.Sprintf("%d/acquirablejobs", runnerScaleSetId) path := fmt.Sprintf("%d/acquirablejobs", runnerScaleSetID)
req, err := s.newActionsRequest(ctx, http.MethodGet, path, nil) req, err := s.newActionsRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {

View file

@ -17,11 +17,12 @@ package scalesets
import ( import (
"bytes" "bytes"
"context" "context"
"crypto/rand"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"log/slog" "log/slog"
"math/rand/v2" "math/big"
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
@ -103,7 +104,7 @@ func (m *MessageSession) SessionsRelativeURL() (string, error) {
if m.session.RunnerScaleSet == nil { if m.session.RunnerScaleSet == nil {
return "", fmt.Errorf("runner scale set is 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 return relativePath, nil
} }
@ -138,7 +139,11 @@ func (m *MessageSession) maybeRefreshToken(ctx context.Context) error {
return fmt.Errorf("session is nil") return fmt.Errorf("session is nil")
} }
// add some jitter // 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 m.session.ExpiresIn(2*time.Minute + jitter) {
if err := m.Refresh(ctx); err != nil { if err := m.Refresh(ctx); err != nil {
return fmt.Errorf("failed to refresh message queue token: %w", err) 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 return nil
} }
func (m *MessageSession) GetMessage(ctx context.Context, lastMessageId int64, maxCapacity uint) (params.RunnerScaleSetMessage, error) { func (m *MessageSession) GetMessage(ctx context.Context, lastMessageID int64, maxCapacity uint) (params.RunnerScaleSetMessage, error) {
u, err := url.Parse(m.session.MessageQueueUrl) u, err := url.Parse(m.session.MessageQueueURL)
if err != nil { if err != nil {
return params.RunnerScaleSetMessage{}, err return params.RunnerScaleSetMessage{}, err
} }
if lastMessageId > 0 { if lastMessageID > 0 {
q := u.Query() q := u.Query()
q.Set("lastMessageId", strconv.FormatInt(lastMessageId, 10)) q.Set("lastMessageId", strconv.FormatInt(lastMessageID, 10))
u.RawQuery = q.Encode() u.RawQuery = q.Encode()
} }
@ -185,13 +190,13 @@ func (m *MessageSession) GetMessage(ctx context.Context, lastMessageId int64, ma
return message, nil return message, nil
} }
func (m *MessageSession) DeleteMessage(ctx context.Context, messageId int64) error { func (m *MessageSession) DeleteMessage(ctx context.Context, messageID int64) error {
u, err := url.Parse(m.session.MessageQueueUrl) u, err := url.Parse(m.session.MessageQueueURL)
if err != nil { if err != nil {
return err 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) req, err := http.NewRequestWithContext(ctx, http.MethodDelete, u.String(), nil)
if err != nil { if err != nil {
@ -210,8 +215,8 @@ func (m *MessageSession) DeleteMessage(ctx context.Context, messageId int64) err
return nil return nil
} }
func (s *ScaleSetClient) CreateMessageSession(ctx context.Context, runnerScaleSetId int, owner string) (*MessageSession, error) { func (s *ScaleSetClient) CreateMessageSession(ctx context.Context, runnerScaleSetID int, owner string) (*MessageSession, error) {
path := fmt.Sprintf("%s/%d/sessions", scaleSetEndpoint, runnerScaleSetId) path := fmt.Sprintf("%s/%d/sessions", scaleSetEndpoint, runnerScaleSetID)
newSession := params.RunnerScaleSetSession{ newSession := params.RunnerScaleSetSession{
OwnerName: owner, OwnerName: owner,

View file

@ -41,7 +41,7 @@ func (s *ScaleSetClient) GenerateJitRunnerConfig(ctx context.Context, runnerName
return params.RunnerScaleSetJitRunnerConfig{}, err 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 { if err != nil {
return params.RunnerScaleSetJitRunnerConfig{}, fmt.Errorf("failed to create request: %w", err) 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 return runnerJitConfig, nil
} }
func (s *ScaleSetClient) GetRunner(ctx context.Context, runnerId int64) (params.RunnerReference, error) { func (s *ScaleSetClient) GetRunner(ctx context.Context, runnerID int64) (params.RunnerReference, error) {
path := fmt.Sprintf("%s/%d", runnerEndpoint, runnerId) path := fmt.Sprintf("%s/%d", runnerEndpoint, runnerID)
req, err := s.newActionsRequest(ctx, http.MethodGet, path, nil) req, err := s.newActionsRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
@ -111,8 +111,8 @@ func (s *ScaleSetClient) GetRunnerByName(ctx context.Context, runnerName string)
return runnerList.RunnerReferences[0], nil return runnerList.RunnerReferences[0], nil
} }
func (s *ScaleSetClient) RemoveRunner(ctx context.Context, runnerId int64) error { func (s *ScaleSetClient) RemoveRunner(ctx context.Context, runnerID int64) error {
path := fmt.Sprintf("%s/%d", runnerEndpoint, runnerId) path := fmt.Sprintf("%s/%d", runnerEndpoint, runnerID)
req, err := s.newActionsRequest(ctx, http.MethodDelete, path, nil) req, err := s.newActionsRequest(ctx, http.MethodDelete, path, nil)
if err != nil { if err != nil {

View file

@ -36,8 +36,8 @@ const (
HeaderGitHubRequestID = "X-GitHub-Request-Id" HeaderGitHubRequestID = "X-GitHub-Request-Id"
) )
func (s *ScaleSetClient) GetRunnerScaleSetByNameAndRunnerGroup(ctx context.Context, runnerGroupId int, name string) (params.RunnerScaleSet, error) { 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) path := fmt.Sprintf("%s?runnerGroupId=%d&name=%s", scaleSetEndpoint, runnerGroupID, name)
req, err := s.newActionsRequest(ctx, http.MethodGet, path, nil) req, err := s.newActionsRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return params.RunnerScaleSet{}, err 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) return params.RunnerScaleSet{}, fmt.Errorf("failed to decode response: %w", err)
} }
if runnerScaleSetList.Count == 0 { 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 // 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 return runnerScaleSetList.RunnerScaleSets[0], nil
} }
func (s *ScaleSetClient) GetRunnerScaleSetById(ctx context.Context, runnerScaleSetId int) (params.RunnerScaleSet, error) { func (s *ScaleSetClient) GetRunnerScaleSetByID(ctx context.Context, runnerScaleSetID int) (params.RunnerScaleSet, error) {
path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetId) path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetID)
req, err := s.newActionsRequest(ctx, http.MethodGet, path, nil) req, err := s.newActionsRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return params.RunnerScaleSet{}, err return params.RunnerScaleSet{}, err
@ -70,7 +70,7 @@ func (s *ScaleSetClient) GetRunnerScaleSetById(ctx context.Context, runnerScaleS
resp, err := s.Do(req) resp, err := s.Do(req)
if err != nil { 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 var runnerScaleSet params.RunnerScaleSet
@ -127,8 +127,8 @@ func (s *ScaleSetClient) CreateRunnerScaleSet(ctx context.Context, runnerScaleSe
return createdRunnerScaleSet, nil return createdRunnerScaleSet, nil
} }
func (s *ScaleSetClient) UpdateRunnerScaleSet(ctx context.Context, runnerScaleSetId int, runnerScaleSet params.RunnerScaleSet) (params.RunnerScaleSet, error) { func (s *ScaleSetClient) UpdateRunnerScaleSet(ctx context.Context, runnerScaleSetID int, runnerScaleSet params.RunnerScaleSet) (params.RunnerScaleSet, error) {
path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetId) path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetID)
body, err := json.Marshal(runnerScaleSet) body, err := json.Marshal(runnerScaleSet)
if err != nil { if err != nil {
@ -152,8 +152,8 @@ func (s *ScaleSetClient) UpdateRunnerScaleSet(ctx context.Context, runnerScaleSe
return ret, nil return ret, nil
} }
func (s *ScaleSetClient) DeleteRunnerScaleSet(ctx context.Context, runnerScaleSetId int) error { func (s *ScaleSetClient) DeleteRunnerScaleSet(ctx context.Context, runnerScaleSetID int) error {
path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetId) path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetID)
req, err := s.newActionsRequest(ctx, http.MethodDelete, path, nil) req, err := s.newActionsRequest(ctx, http.MethodDelete, path, nil)
if err != nil { if err != nil {
return err return err

View file

@ -26,12 +26,12 @@ func (s *ScaleSetClient) newActionsRequest(ctx context.Context, method, path str
return nil, fmt.Errorf("failed to update token: %w", err) return nil, fmt.Errorf("failed to update token: %w", err)
} }
actionsUri, err := s.actionsServiceInfo.GetURL() actionsURI, err := s.actionsServiceInfo.GetURL()
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get pipeline URL: %w", err) return nil, fmt.Errorf("failed to get pipeline URL: %w", err)
} }
uri, err := actionsUri.Parse(path) uri, err := actionsURI.Parse(path)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to parse path: %w", err) return nil, fmt.Errorf("failed to parse path: %w", err)
} }