Extend the user agent and fix the build version for the listener app (#2892)
This commit is contained in:
parent
ea2fb32e20
commit
07bff8aa1e
|
|
@ -18,7 +18,7 @@ on:
|
|||
default: false
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
env:
|
||||
|
|
@ -34,16 +34,16 @@ jobs:
|
|||
name: Release
|
||||
runs-on: ubuntu-latest
|
||||
# gha-runner-scale-set has its own release workflow.
|
||||
# We don't want to publish a new actions-runner-controller image
|
||||
# We don't want to publish a new actions-runner-controller image
|
||||
# we release gha-runner-scale-set.
|
||||
if: ${{ !startsWith(github.event.inputs.release_tag_name, 'gha-runner-scale-set-') }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/setup-go@v3
|
||||
- uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.18.2'
|
||||
go-version-file: 'go.mod'
|
||||
|
||||
- name: Install tools
|
||||
run: |
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ RUN go mod download
|
|||
# With the above commmand,
|
||||
# TARGETOS can be "linux", TARGETARCH can be "amd64", "arm64", and "arm", TARGETVARIANT can be "v7".
|
||||
|
||||
ARG TARGETPLATFORM TARGETOS TARGETARCH TARGETVARIANT VERSION=dev
|
||||
ARG TARGETPLATFORM TARGETOS TARGETARCH TARGETVARIANT VERSION=dev COMMIT_SHA=dev
|
||||
|
||||
# We intentionally avoid `--mount=type=cache,mode=0777,target=/go/pkg/mod` in the `go mod download` and the `go build` runs
|
||||
# to avoid https://github.com/moby/buildkit/issues/2334
|
||||
|
|
@ -36,8 +36,8 @@ ENV GOCACHE /build/${TARGETPLATFORM}/root/.cache/go-build
|
|||
RUN --mount=target=. \
|
||||
--mount=type=cache,mode=0777,target=${GOCACHE} \
|
||||
export GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=${TARGETVARIANT#v} && \
|
||||
go build -trimpath -ldflags="-s -w -X 'github.com/actions/actions-runner-controller/build.Version=${VERSION}'" -o /out/manager main.go && \
|
||||
go build -trimpath -ldflags="-s -w" -o /out/github-runnerscaleset-listener ./cmd/githubrunnerscalesetlistener && \
|
||||
go build -trimpath -ldflags="-s -w -X 'github.com/actions/actions-runner-controller/build.Version=${VERSION}' -X 'github.com/actions/actions-runner-controller/build.CommitSHA=${COMMIT_SHA}'" -o /out/manager main.go && \
|
||||
go build -trimpath -ldflags="-s -w -X 'github.com/actions/actions-runner-controller/build.Version=${VERSION}' -X 'github.com/actions/actions-runner-controller/build.CommitSHA=${COMMIT_SHA}'" -o /out/github-runnerscaleset-listener ./cmd/githubrunnerscalesetlistener && \
|
||||
go build -trimpath -ldflags="-s -w" -o /out/github-webhook-server ./cmd/githubwebhookserver && \
|
||||
go build -trimpath -ldflags="-s -w" -o /out/actions-metrics-server ./cmd/actionsmetricsserver && \
|
||||
go build -trimpath -ldflags="-s -w" -o /out/sleep ./cmd/sleep
|
||||
|
|
|
|||
4
Makefile
4
Makefile
|
|
@ -5,6 +5,7 @@ else
|
|||
endif
|
||||
DOCKER_USER ?= $(shell echo ${DOCKER_IMAGE_NAME} | cut -d / -f1)
|
||||
VERSION ?= dev
|
||||
COMMIT_SHA = $(shell git rev-parse HEAD)
|
||||
RUNNER_VERSION ?= 2.309.0
|
||||
TARGETPLATFORM ?= $(shell arch)
|
||||
RUNNER_NAME ?= ${DOCKER_USER}/actions-runner
|
||||
|
|
@ -67,7 +68,7 @@ endif
|
|||
all: manager
|
||||
|
||||
lint:
|
||||
docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:v1.49.0 golangci-lint run
|
||||
docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:v1.54.2 golangci-lint run
|
||||
|
||||
GO_TEST_ARGS ?= -short
|
||||
|
||||
|
|
@ -215,6 +216,7 @@ docker-buildx:
|
|||
--build-arg RUNNER_VERSION=${RUNNER_VERSION} \
|
||||
--build-arg DOCKER_VERSION=${DOCKER_VERSION} \
|
||||
--build-arg VERSION=${VERSION} \
|
||||
--build-arg COMMIT_SHA=${COMMIT_SHA} \
|
||||
-t "${DOCKER_IMAGE_NAME}:${VERSION}" \
|
||||
-f Dockerfile \
|
||||
. ${PUSH_ARG}
|
||||
|
|
|
|||
|
|
@ -2,3 +2,5 @@ package build
|
|||
|
||||
// This is overridden at build-time using go-build ldflags. dev is the fallback value
|
||||
var Version = "NA"
|
||||
|
||||
var CommitSHA = "NA"
|
||||
|
|
|
|||
|
|
@ -190,8 +190,12 @@ func run(ctx context.Context, rc RunnerScaleSetListenerConfig, logger logr.Logge
|
|||
rc,
|
||||
creds,
|
||||
actions.WithLogger(logger),
|
||||
actions.WithUserAgent(fmt.Sprintf("actions-runner-controller/%s", build.Version)),
|
||||
)
|
||||
actionsServiceClient.SetUserAgent(actions.UserAgentInfo{
|
||||
Version: build.Version,
|
||||
CommitSHA: build.CommitSHA,
|
||||
ScaleSetID: rc.RunnerScaleSetId,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create an Actions Service client: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v2.16.0. DO NOT EDIT.
|
||||
// Code generated by mockery v2.33.2. DO NOT EDIT.
|
||||
|
||||
package main
|
||||
|
||||
|
|
@ -41,13 +41,12 @@ func (_m *MockKubernetesManager) UpdateEphemeralRunnerWithJobInfo(ctx context.Co
|
|||
return r0
|
||||
}
|
||||
|
||||
type mockConstructorTestingTNewMockKubernetesManager interface {
|
||||
// NewMockKubernetesManager creates a new instance of MockKubernetesManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewMockKubernetesManager(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// NewMockKubernetesManager creates a new instance of MockKubernetesManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewMockKubernetesManager(t mockConstructorTestingTNewMockKubernetesManager) *MockKubernetesManager {
|
||||
}) *MockKubernetesManager {
|
||||
mock := &MockKubernetesManager{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v2.16.0. DO NOT EDIT.
|
||||
// Code generated by mockery v2.33.2. DO NOT EDIT.
|
||||
|
||||
package main
|
||||
|
||||
|
|
@ -43,13 +43,12 @@ func (_m *MockRunnerScaleSetClient) GetRunnerScaleSetMessage(ctx context.Context
|
|||
return r0
|
||||
}
|
||||
|
||||
type mockConstructorTestingTNewMockRunnerScaleSetClient interface {
|
||||
// NewMockRunnerScaleSetClient creates a new instance of MockRunnerScaleSetClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewMockRunnerScaleSetClient(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// NewMockRunnerScaleSetClient creates a new instance of MockRunnerScaleSetClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewMockRunnerScaleSetClient(t mockConstructorTestingTNewMockRunnerScaleSetClient) *MockRunnerScaleSetClient {
|
||||
}) *MockRunnerScaleSetClient {
|
||||
mock := &MockRunnerScaleSetClient{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -463,6 +463,12 @@ func (r *AutoscalingRunnerSetReconciler) createRunnerScaleSet(ctx context.Contex
|
|||
}
|
||||
}
|
||||
|
||||
actionsClient.SetUserAgent(actions.UserAgentInfo{
|
||||
Version: build.Version,
|
||||
CommitSHA: build.CommitSHA,
|
||||
ScaleSetID: runnerScaleSet.Id,
|
||||
})
|
||||
|
||||
logger.Info("Created/Reused a runner scale set", "id", runnerScaleSet.Id, "runnerGroupName", runnerScaleSet.RunnerGroupName)
|
||||
if autoscalingRunnerSet.Annotations == nil {
|
||||
autoscalingRunnerSet.Annotations = map[string]string{}
|
||||
|
|
|
|||
|
|
@ -888,8 +888,9 @@ var _ = Describe("Test client optional configuration", Ordered, func() {
|
|||
Log: logf.Log,
|
||||
ControllerNamespace: autoscalingNS.Name,
|
||||
DefaultRunnerScaleSetListenerImage: "ghcr.io/actions/arc",
|
||||
ActionsClient: actions.NewMultiClient("test", logr.Discard()),
|
||||
ActionsClient: actions.NewMultiClient(logr.Discard()),
|
||||
}
|
||||
|
||||
err := controller.SetupWithManager(mgr)
|
||||
Expect(err).NotTo(HaveOccurred(), "failed to setup controller")
|
||||
|
||||
|
|
@ -1079,7 +1080,7 @@ var _ = Describe("Test client optional configuration", Ordered, func() {
|
|||
})
|
||||
|
||||
It("should be able to make requests to a server using root CAs", func() {
|
||||
controller.ActionsClient = actions.NewMultiClient("test", logr.Discard())
|
||||
controller.ActionsClient = actions.NewMultiClient(logr.Discard())
|
||||
|
||||
certsFolder := filepath.Join(
|
||||
"../../",
|
||||
|
|
|
|||
|
|
@ -729,7 +729,7 @@ var _ = Describe("EphemeralRunner", func() {
|
|||
|
||||
It("uses an actions client with proxy transport", func() {
|
||||
// Use an actual client
|
||||
controller.ActionsClient = actions.NewMultiClient("test", logr.Discard())
|
||||
controller.ActionsClient = actions.NewMultiClient(logr.Discard())
|
||||
|
||||
proxySuccessfulllyCalled := false
|
||||
proxy := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -914,7 +914,7 @@ var _ = Describe("EphemeralRunner", func() {
|
|||
server.StartTLS()
|
||||
|
||||
// Use an actual client
|
||||
controller.ActionsClient = actions.NewMultiClient("test", logr.Discard())
|
||||
controller.ActionsClient = actions.NewMultiClient(logr.Discard())
|
||||
|
||||
ephemeralRunner := newExampleRunner("test-runner", autoScalingNS.Name, configSecret.Name)
|
||||
ephemeralRunner.Spec.GitHubConfigUrl = server.ConfigURLForOrg("my-org")
|
||||
|
|
|
|||
|
|
@ -753,7 +753,7 @@ var _ = Describe("Test EphemeralRunnerSet controller with proxy settings", func(
|
|||
Client: mgr.GetClient(),
|
||||
Scheme: mgr.GetScheme(),
|
||||
Log: logf.Log,
|
||||
ActionsClient: actions.NewMultiClient("test", logr.Discard()),
|
||||
ActionsClient: actions.NewMultiClient(logr.Discard()),
|
||||
}
|
||||
err := controller.SetupWithManager(mgr)
|
||||
Expect(err).NotTo(HaveOccurred(), "failed to setup controller")
|
||||
|
|
@ -1052,7 +1052,7 @@ var _ = Describe("Test EphemeralRunnerSet controller with custom root CA", func(
|
|||
Client: mgr.GetClient(),
|
||||
Scheme: mgr.GetScheme(),
|
||||
Log: logf.Log,
|
||||
ActionsClient: actions.NewMultiClient("test", logr.Discard()),
|
||||
ActionsClient: actions.NewMultiClient(logr.Discard()),
|
||||
}
|
||||
err = controller.SetupWithManager(mgr)
|
||||
Expect(err).NotTo(HaveOccurred(), "failed to setup controller")
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/actions/actions-runner-controller/build"
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"github.com/google/uuid"
|
||||
|
|
@ -53,6 +54,8 @@ type ActionsService interface {
|
|||
GetRunner(ctx context.Context, runnerId int64) (*RunnerReference, error)
|
||||
GetRunnerByName(ctx context.Context, runnerName string) (*RunnerReference, error)
|
||||
RemoveRunner(ctx context.Context, runnerId int64) error
|
||||
|
||||
SetUserAgent(info UserAgentInfo)
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
|
|
@ -72,7 +75,7 @@ type Client struct {
|
|||
creds *ActionsAuth
|
||||
config *GitHubConfig
|
||||
logger logr.Logger
|
||||
userAgent string
|
||||
userAgent UserAgentInfo
|
||||
|
||||
rootCAs *x509.CertPool
|
||||
tlsInsecureSkipVerify bool
|
||||
|
|
@ -84,10 +87,24 @@ type ProxyFunc func(req *http.Request) (*url.URL, error)
|
|||
|
||||
type ClientOption func(*Client)
|
||||
|
||||
func WithUserAgent(userAgent string) ClientOption {
|
||||
return func(c *Client) {
|
||||
c.userAgent = userAgent
|
||||
type UserAgentInfo struct {
|
||||
Version string
|
||||
CommitSHA string
|
||||
ScaleSetID int
|
||||
}
|
||||
|
||||
func (u UserAgentInfo) String() string {
|
||||
var scaleSetID = "NA"
|
||||
if u.ScaleSetID > 0 {
|
||||
scaleSetID = strconv.Itoa(u.ScaleSetID)
|
||||
}
|
||||
|
||||
return fmt.Sprintf(
|
||||
"actions-runner-controller/%s CommitSHA/%s ScaleSetID/%s",
|
||||
u.Version,
|
||||
u.CommitSHA,
|
||||
scaleSetID,
|
||||
)
|
||||
}
|
||||
|
||||
func WithLogger(logger logr.Logger) ClientOption {
|
||||
|
|
@ -140,6 +157,11 @@ func NewClient(githubConfigURL string, creds *ActionsAuth, options ...ClientOpti
|
|||
// retryablehttp defaults
|
||||
retryMax: 4,
|
||||
retryWaitMax: 30 * time.Second,
|
||||
userAgent: UserAgentInfo{
|
||||
Version: build.Version,
|
||||
CommitSHA: build.CommitSHA,
|
||||
ScaleSetID: 0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, option := range options {
|
||||
|
|
@ -178,6 +200,10 @@ func NewClient(githubConfigURL string, creds *ActionsAuth, options ...ClientOpti
|
|||
return ac, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetUserAgent(info UserAgentInfo) {
|
||||
c.userAgent = info
|
||||
}
|
||||
|
||||
// Identifier returns a string to help identify a client uniquely.
|
||||
// This is used for caching client instances and understanding when a config
|
||||
// change warrants creating a new client. Any changes to Client that would
|
||||
|
|
@ -186,7 +212,7 @@ func (c *Client) Identifier() string {
|
|||
identifier := fmt.Sprintf("configURL:%q,", c.config.ConfigURL.String())
|
||||
|
||||
if c.creds.Token != "" {
|
||||
identifier += fmt.Sprintf("token:%q", c.creds.Token)
|
||||
identifier += fmt.Sprintf("token:%q,", c.creds.Token)
|
||||
}
|
||||
|
||||
if c.creds.AppCreds != nil {
|
||||
|
|
@ -234,9 +260,7 @@ func (c *Client) NewGitHubAPIRequest(ctx context.Context, method, path string, b
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if c.userAgent != "" {
|
||||
req.Header.Set("User-Agent", c.userAgent)
|
||||
}
|
||||
req.Header.Set("User-Agent", c.userAgent.String())
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
|
@ -278,9 +302,7 @@ func (c *Client) NewActionsServiceRequest(ctx context.Context, method, path stri
|
|||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.ActionsServiceAdminToken))
|
||||
if c.userAgent != "" {
|
||||
req.Header.Set("User-Agent", c.userAgent)
|
||||
}
|
||||
req.Header.Set("User-Agent", c.userAgent.String())
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
|
@ -473,9 +495,7 @@ func (c *Client) GetMessage(ctx context.Context, messageQueueUrl, messageQueueAc
|
|||
|
||||
req.Header.Set("Accept", "application/json; api-version=6.0-preview")
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", messageQueueAccessToken))
|
||||
if c.userAgent != "" {
|
||||
req.Header.Set("User-Agent", c.userAgent)
|
||||
}
|
||||
req.Header.Set("User-Agent", c.userAgent.String())
|
||||
|
||||
resp, err := c.Do(req)
|
||||
if err != nil {
|
||||
|
|
@ -524,9 +544,7 @@ func (c *Client) DeleteMessage(ctx context.Context, messageQueueUrl, messageQueu
|
|||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", messageQueueAccessToken))
|
||||
if c.userAgent != "" {
|
||||
req.Header.Set("User-Agent", c.userAgent)
|
||||
}
|
||||
req.Header.Set("User-Agent", c.userAgent.String())
|
||||
|
||||
resp, err := c.Do(req)
|
||||
if err != nil {
|
||||
|
|
@ -624,9 +642,7 @@ func (c *Client) AcquireJobs(ctx context.Context, runnerScaleSetId int, messageQ
|
|||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", messageQueueAccessToken))
|
||||
if c.userAgent != "" {
|
||||
req.Header.Set("User-Agent", c.userAgent)
|
||||
}
|
||||
req.Header.Set("User-Agent", c.userAgent.String())
|
||||
|
||||
resp, err := c.Do(req)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -282,3 +282,5 @@ func (f *FakeClient) GetRunnerByName(ctx context.Context, runnerName string) (*a
|
|||
func (f *FakeClient) RemoveRunner(ctx context.Context, runnerId int64) error {
|
||||
return f.removeRunnerResult.err
|
||||
}
|
||||
|
||||
func (f *FakeClient) SetUserAgent(_ actions.UserAgentInfo) {}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,12 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var testUserAgent = actions.UserAgentInfo{
|
||||
Version: "test",
|
||||
CommitSHA: "test",
|
||||
ScaleSetID: 1,
|
||||
}
|
||||
|
||||
func TestNewGitHubAPIRequest(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
|
|
@ -62,13 +68,15 @@ func TestNewGitHubAPIRequest(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("sets user agent header if present", func(t *testing.T) {
|
||||
client, err := actions.NewClient("http://localhost/my-org", nil, actions.WithUserAgent("my-agent"))
|
||||
client, err := actions.NewClient("http://localhost/my-org", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
client.SetUserAgent(testUserAgent)
|
||||
|
||||
req, err := client.NewGitHubAPIRequest(ctx, http.MethodGet, "/app/installations/123/access_tokens", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "my-agent", req.Header.Get("User-Agent"))
|
||||
assert.Equal(t, testUserAgent.String(), req.Header.Get("User-Agent"))
|
||||
})
|
||||
|
||||
t.Run("sets the body we pass", func(t *testing.T) {
|
||||
|
|
@ -182,13 +190,15 @@ func TestNewActionsServiceRequest(t *testing.T) {
|
|||
t.Run("populates header", func(t *testing.T) {
|
||||
server := testserver.New(t, nil)
|
||||
|
||||
client, err := actions.NewClient(server.ConfigURLForOrg("my-org"), defaultCreds, actions.WithUserAgent("my-agent"))
|
||||
client, err := actions.NewClient(server.ConfigURLForOrg("my-org"), defaultCreds)
|
||||
require.NoError(t, err)
|
||||
|
||||
client.SetUserAgent(testUserAgent)
|
||||
|
||||
req, err := client.NewActionsServiceRequest(ctx, http.MethodGet, "/my/path", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "my-agent", req.Header.Get("User-Agent"))
|
||||
assert.Equal(t, testUserAgent.String(), req.Header.Get("User-Agent"))
|
||||
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v2.16.0. DO NOT EDIT.
|
||||
// Code generated by mockery v2.33.2. DO NOT EDIT.
|
||||
|
||||
package actions
|
||||
|
||||
|
|
@ -19,6 +19,10 @@ func (_m *MockActionsService) AcquireJobs(ctx context.Context, runnerScaleSetId
|
|||
ret := _m.Called(ctx, runnerScaleSetId, messageQueueAccessToken, requestIds)
|
||||
|
||||
var r0 []int64
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int, string, []int64) ([]int64, error)); ok {
|
||||
return rf(ctx, runnerScaleSetId, messageQueueAccessToken, requestIds)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int, string, []int64) []int64); ok {
|
||||
r0 = rf(ctx, runnerScaleSetId, messageQueueAccessToken, requestIds)
|
||||
} else {
|
||||
|
|
@ -27,7 +31,6 @@ func (_m *MockActionsService) AcquireJobs(ctx context.Context, runnerScaleSetId
|
|||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, int, string, []int64) error); ok {
|
||||
r1 = rf(ctx, runnerScaleSetId, messageQueueAccessToken, requestIds)
|
||||
} else {
|
||||
|
|
@ -42,6 +45,10 @@ func (_m *MockActionsService) CreateMessageSession(ctx context.Context, runnerSc
|
|||
ret := _m.Called(ctx, runnerScaleSetId, owner)
|
||||
|
||||
var r0 *RunnerScaleSetSession
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int, string) (*RunnerScaleSetSession, error)); ok {
|
||||
return rf(ctx, runnerScaleSetId, owner)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int, string) *RunnerScaleSetSession); ok {
|
||||
r0 = rf(ctx, runnerScaleSetId, owner)
|
||||
} else {
|
||||
|
|
@ -50,7 +57,6 @@ func (_m *MockActionsService) CreateMessageSession(ctx context.Context, runnerSc
|
|||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, int, string) error); ok {
|
||||
r1 = rf(ctx, runnerScaleSetId, owner)
|
||||
} else {
|
||||
|
|
@ -65,6 +71,10 @@ func (_m *MockActionsService) CreateRunnerScaleSet(ctx context.Context, runnerSc
|
|||
ret := _m.Called(ctx, runnerScaleSet)
|
||||
|
||||
var r0 *RunnerScaleSet
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *RunnerScaleSet) (*RunnerScaleSet, error)); ok {
|
||||
return rf(ctx, runnerScaleSet)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *RunnerScaleSet) *RunnerScaleSet); ok {
|
||||
r0 = rf(ctx, runnerScaleSet)
|
||||
} else {
|
||||
|
|
@ -73,7 +83,6 @@ func (_m *MockActionsService) CreateRunnerScaleSet(ctx context.Context, runnerSc
|
|||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *RunnerScaleSet) error); ok {
|
||||
r1 = rf(ctx, runnerScaleSet)
|
||||
} else {
|
||||
|
|
@ -130,6 +139,10 @@ func (_m *MockActionsService) GenerateJitRunnerConfig(ctx context.Context, jitRu
|
|||
ret := _m.Called(ctx, jitRunnerSetting, scaleSetId)
|
||||
|
||||
var r0 *RunnerScaleSetJitRunnerConfig
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *RunnerScaleSetJitRunnerSetting, int) (*RunnerScaleSetJitRunnerConfig, error)); ok {
|
||||
return rf(ctx, jitRunnerSetting, scaleSetId)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *RunnerScaleSetJitRunnerSetting, int) *RunnerScaleSetJitRunnerConfig); ok {
|
||||
r0 = rf(ctx, jitRunnerSetting, scaleSetId)
|
||||
} else {
|
||||
|
|
@ -138,7 +151,6 @@ func (_m *MockActionsService) GenerateJitRunnerConfig(ctx context.Context, jitRu
|
|||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *RunnerScaleSetJitRunnerSetting, int) error); ok {
|
||||
r1 = rf(ctx, jitRunnerSetting, scaleSetId)
|
||||
} else {
|
||||
|
|
@ -153,6 +165,10 @@ func (_m *MockActionsService) GetAcquirableJobs(ctx context.Context, runnerScale
|
|||
ret := _m.Called(ctx, runnerScaleSetId)
|
||||
|
||||
var r0 *AcquirableJobList
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int) (*AcquirableJobList, error)); ok {
|
||||
return rf(ctx, runnerScaleSetId)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int) *AcquirableJobList); ok {
|
||||
r0 = rf(ctx, runnerScaleSetId)
|
||||
} else {
|
||||
|
|
@ -161,7 +177,6 @@ func (_m *MockActionsService) GetAcquirableJobs(ctx context.Context, runnerScale
|
|||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, int) error); ok {
|
||||
r1 = rf(ctx, runnerScaleSetId)
|
||||
} else {
|
||||
|
|
@ -176,6 +191,10 @@ func (_m *MockActionsService) GetMessage(ctx context.Context, messageQueueUrl st
|
|||
ret := _m.Called(ctx, messageQueueUrl, messageQueueAccessToken, lastMessageId)
|
||||
|
||||
var r0 *RunnerScaleSetMessage
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, string, int64) (*RunnerScaleSetMessage, error)); ok {
|
||||
return rf(ctx, messageQueueUrl, messageQueueAccessToken, lastMessageId)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, string, int64) *RunnerScaleSetMessage); ok {
|
||||
r0 = rf(ctx, messageQueueUrl, messageQueueAccessToken, lastMessageId)
|
||||
} else {
|
||||
|
|
@ -184,7 +203,6 @@ func (_m *MockActionsService) GetMessage(ctx context.Context, messageQueueUrl st
|
|||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, string, string, int64) error); ok {
|
||||
r1 = rf(ctx, messageQueueUrl, messageQueueAccessToken, lastMessageId)
|
||||
} else {
|
||||
|
|
@ -199,6 +217,10 @@ func (_m *MockActionsService) GetRunner(ctx context.Context, runnerId int64) (*R
|
|||
ret := _m.Called(ctx, runnerId)
|
||||
|
||||
var r0 *RunnerReference
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64) (*RunnerReference, error)); ok {
|
||||
return rf(ctx, runnerId)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64) *RunnerReference); ok {
|
||||
r0 = rf(ctx, runnerId)
|
||||
} else {
|
||||
|
|
@ -207,7 +229,6 @@ func (_m *MockActionsService) GetRunner(ctx context.Context, runnerId int64) (*R
|
|||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok {
|
||||
r1 = rf(ctx, runnerId)
|
||||
} else {
|
||||
|
|
@ -222,6 +243,10 @@ func (_m *MockActionsService) GetRunnerByName(ctx context.Context, runnerName st
|
|||
ret := _m.Called(ctx, runnerName)
|
||||
|
||||
var r0 *RunnerReference
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string) (*RunnerReference, error)); ok {
|
||||
return rf(ctx, runnerName)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string) *RunnerReference); ok {
|
||||
r0 = rf(ctx, runnerName)
|
||||
} else {
|
||||
|
|
@ -230,7 +255,6 @@ func (_m *MockActionsService) GetRunnerByName(ctx context.Context, runnerName st
|
|||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
|
||||
r1 = rf(ctx, runnerName)
|
||||
} else {
|
||||
|
|
@ -245,6 +269,10 @@ func (_m *MockActionsService) GetRunnerGroupByName(ctx context.Context, runnerGr
|
|||
ret := _m.Called(ctx, runnerGroup)
|
||||
|
||||
var r0 *RunnerGroup
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string) (*RunnerGroup, error)); ok {
|
||||
return rf(ctx, runnerGroup)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string) *RunnerGroup); ok {
|
||||
r0 = rf(ctx, runnerGroup)
|
||||
} else {
|
||||
|
|
@ -253,7 +281,6 @@ func (_m *MockActionsService) GetRunnerGroupByName(ctx context.Context, runnerGr
|
|||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
|
||||
r1 = rf(ctx, runnerGroup)
|
||||
} else {
|
||||
|
|
@ -268,6 +295,10 @@ func (_m *MockActionsService) GetRunnerScaleSet(ctx context.Context, runnerGroup
|
|||
ret := _m.Called(ctx, runnerGroupId, runnerScaleSetName)
|
||||
|
||||
var r0 *RunnerScaleSet
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int, string) (*RunnerScaleSet, error)); ok {
|
||||
return rf(ctx, runnerGroupId, runnerScaleSetName)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int, string) *RunnerScaleSet); ok {
|
||||
r0 = rf(ctx, runnerGroupId, runnerScaleSetName)
|
||||
} else {
|
||||
|
|
@ -276,7 +307,6 @@ func (_m *MockActionsService) GetRunnerScaleSet(ctx context.Context, runnerGroup
|
|||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, int, string) error); ok {
|
||||
r1 = rf(ctx, runnerGroupId, runnerScaleSetName)
|
||||
} else {
|
||||
|
|
@ -291,6 +321,10 @@ func (_m *MockActionsService) GetRunnerScaleSetById(ctx context.Context, runnerS
|
|||
ret := _m.Called(ctx, runnerScaleSetId)
|
||||
|
||||
var r0 *RunnerScaleSet
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int) (*RunnerScaleSet, error)); ok {
|
||||
return rf(ctx, runnerScaleSetId)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int) *RunnerScaleSet); ok {
|
||||
r0 = rf(ctx, runnerScaleSetId)
|
||||
} else {
|
||||
|
|
@ -299,7 +333,6 @@ func (_m *MockActionsService) GetRunnerScaleSetById(ctx context.Context, runnerS
|
|||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, int) error); ok {
|
||||
r1 = rf(ctx, runnerScaleSetId)
|
||||
} else {
|
||||
|
|
@ -314,6 +347,10 @@ func (_m *MockActionsService) RefreshMessageSession(ctx context.Context, runnerS
|
|||
ret := _m.Called(ctx, runnerScaleSetId, sessionId)
|
||||
|
||||
var r0 *RunnerScaleSetSession
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int, *uuid.UUID) (*RunnerScaleSetSession, error)); ok {
|
||||
return rf(ctx, runnerScaleSetId, sessionId)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int, *uuid.UUID) *RunnerScaleSetSession); ok {
|
||||
r0 = rf(ctx, runnerScaleSetId, sessionId)
|
||||
} else {
|
||||
|
|
@ -322,7 +359,6 @@ func (_m *MockActionsService) RefreshMessageSession(ctx context.Context, runnerS
|
|||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, int, *uuid.UUID) error); ok {
|
||||
r1 = rf(ctx, runnerScaleSetId, sessionId)
|
||||
} else {
|
||||
|
|
@ -346,11 +382,20 @@ func (_m *MockActionsService) RemoveRunner(ctx context.Context, runnerId int64)
|
|||
return r0
|
||||
}
|
||||
|
||||
// SetUserAgent provides a mock function with given fields: info
|
||||
func (_m *MockActionsService) SetUserAgent(info UserAgentInfo) {
|
||||
_m.Called(info)
|
||||
}
|
||||
|
||||
// UpdateRunnerScaleSet provides a mock function with given fields: ctx, runnerScaleSetId, runnerScaleSet
|
||||
func (_m *MockActionsService) UpdateRunnerScaleSet(ctx context.Context, runnerScaleSetId int, runnerScaleSet *RunnerScaleSet) (*RunnerScaleSet, error) {
|
||||
ret := _m.Called(ctx, runnerScaleSetId, runnerScaleSet)
|
||||
|
||||
var r0 *RunnerScaleSet
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int, *RunnerScaleSet) (*RunnerScaleSet, error)); ok {
|
||||
return rf(ctx, runnerScaleSetId, runnerScaleSet)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int, *RunnerScaleSet) *RunnerScaleSet); ok {
|
||||
r0 = rf(ctx, runnerScaleSetId, runnerScaleSet)
|
||||
} else {
|
||||
|
|
@ -359,7 +404,6 @@ func (_m *MockActionsService) UpdateRunnerScaleSet(ctx context.Context, runnerSc
|
|||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, int, *RunnerScaleSet) error); ok {
|
||||
r1 = rf(ctx, runnerScaleSetId, runnerScaleSet)
|
||||
} else {
|
||||
|
|
@ -369,13 +413,12 @@ func (_m *MockActionsService) UpdateRunnerScaleSet(ctx context.Context, runnerSc
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
type mockConstructorTestingTNewMockActionsService interface {
|
||||
// NewMockActionsService creates a new instance of MockActionsService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewMockActionsService(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// NewMockActionsService creates a new instance of MockActionsService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewMockActionsService(t mockConstructorTestingTNewMockActionsService) *MockActionsService {
|
||||
}) *MockActionsService {
|
||||
mock := &MockActionsService{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v2.16.0. DO NOT EDIT.
|
||||
// Code generated by mockery v2.33.2. DO NOT EDIT.
|
||||
|
||||
package actions
|
||||
|
||||
|
|
@ -18,6 +18,10 @@ func (_m *MockSessionService) AcquireJobs(ctx context.Context, requestIds []int6
|
|||
ret := _m.Called(ctx, requestIds)
|
||||
|
||||
var r0 []int64
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, []int64) ([]int64, error)); ok {
|
||||
return rf(ctx, requestIds)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, []int64) []int64); ok {
|
||||
r0 = rf(ctx, requestIds)
|
||||
} else {
|
||||
|
|
@ -26,7 +30,6 @@ func (_m *MockSessionService) AcquireJobs(ctx context.Context, requestIds []int6
|
|||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, []int64) error); ok {
|
||||
r1 = rf(ctx, requestIds)
|
||||
} else {
|
||||
|
|
@ -69,6 +72,10 @@ func (_m *MockSessionService) GetMessage(ctx context.Context, lastMessageId int6
|
|||
ret := _m.Called(ctx, lastMessageId)
|
||||
|
||||
var r0 *RunnerScaleSetMessage
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64) (*RunnerScaleSetMessage, error)); ok {
|
||||
return rf(ctx, lastMessageId)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64) *RunnerScaleSetMessage); ok {
|
||||
r0 = rf(ctx, lastMessageId)
|
||||
} else {
|
||||
|
|
@ -77,7 +84,6 @@ func (_m *MockSessionService) GetMessage(ctx context.Context, lastMessageId int6
|
|||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok {
|
||||
r1 = rf(ctx, lastMessageId)
|
||||
} else {
|
||||
|
|
@ -87,13 +93,12 @@ func (_m *MockSessionService) GetMessage(ctx context.Context, lastMessageId int6
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
type mockConstructorTestingTNewMockSessionService interface {
|
||||
// NewMockSessionService creates a new instance of MockSessionService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewMockSessionService(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// NewMockSessionService creates a new instance of MockSessionService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewMockSessionService(t mockConstructorTestingTNewMockSessionService) *MockSessionService {
|
||||
}) *MockSessionService {
|
||||
mock := &MockSessionService{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,7 @@ type multiClient struct {
|
|||
mu sync.Mutex
|
||||
clients map[ActionsClientKey]*Client
|
||||
|
||||
logger logr.Logger
|
||||
userAgent string
|
||||
logger logr.Logger
|
||||
}
|
||||
|
||||
type GitHubAppAuth struct {
|
||||
|
|
@ -42,12 +41,11 @@ type ActionsClientKey struct {
|
|||
Namespace string
|
||||
}
|
||||
|
||||
func NewMultiClient(userAgent string, logger logr.Logger) MultiClient {
|
||||
func NewMultiClient(logger logr.Logger) MultiClient {
|
||||
return &multiClient{
|
||||
mu: sync.Mutex{},
|
||||
clients: make(map[ActionsClientKey]*Client),
|
||||
logger: logger,
|
||||
userAgent: userAgent,
|
||||
mu: sync.Mutex{},
|
||||
clients: make(map[ActionsClientKey]*Client),
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -66,7 +64,6 @@ func (m *multiClient) GetClientFor(ctx context.Context, githubConfigURL string,
|
|||
githubConfigURL,
|
||||
&creds,
|
||||
append([]ClientOption{
|
||||
WithUserAgent(m.userAgent),
|
||||
WithLogger(m.logger),
|
||||
}, options...)...,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -10,10 +10,16 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var testUserAgent = UserAgentInfo{
|
||||
Version: "test",
|
||||
CommitSHA: "test",
|
||||
ScaleSetID: 1,
|
||||
}
|
||||
|
||||
func TestMultiClientCaching(t *testing.T) {
|
||||
logger := logr.Discard()
|
||||
ctx := context.Background()
|
||||
multiClient := NewMultiClient("test-user-agent", logger).(*multiClient)
|
||||
multiClient := NewMultiClient(logger).(*multiClient)
|
||||
|
||||
defaultNamespace := "default"
|
||||
defaultConfigURL := "https://github.com/org/repo"
|
||||
|
|
@ -61,20 +67,21 @@ func TestMultiClientOptions(t *testing.T) {
|
|||
Token: "token",
|
||||
}
|
||||
|
||||
multiClient := NewMultiClient("test-user-agent", logger)
|
||||
multiClient := NewMultiClient(logger)
|
||||
service, err := multiClient.GetClientFor(
|
||||
ctx,
|
||||
defaultConfigURL,
|
||||
*defaultCreds,
|
||||
defaultNamespace,
|
||||
WithUserAgent("test-option"),
|
||||
)
|
||||
service.SetUserAgent(testUserAgent)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
client := service.(*Client)
|
||||
req, err := client.NewGitHubAPIRequest(ctx, "GET", "/test", nil)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "test-option", req.Header.Get("User-Agent"))
|
||||
assert.Equal(t, testUserAgent.String(), req.Header.Get("User-Agent"))
|
||||
})
|
||||
|
||||
t.Run("GetClientFromSecret", func(t *testing.T) {
|
||||
|
|
@ -82,20 +89,20 @@ func TestMultiClientOptions(t *testing.T) {
|
|||
"github_token": []byte("token"),
|
||||
}
|
||||
|
||||
multiClient := NewMultiClient("test-user-agent", logger)
|
||||
multiClient := NewMultiClient(logger)
|
||||
service, err := multiClient.GetClientFromSecret(
|
||||
ctx,
|
||||
defaultConfigURL,
|
||||
defaultNamespace,
|
||||
secret,
|
||||
WithUserAgent("test-option"),
|
||||
)
|
||||
service.SetUserAgent(testUserAgent)
|
||||
require.NoError(t, err)
|
||||
|
||||
client := service.(*Client)
|
||||
req, err := client.NewGitHubAPIRequest(ctx, "GET", "/test", nil)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "test-option", req.Header.Get("User-Agent"))
|
||||
assert.Equal(t, testUserAgent.String(), req.Header.Get("User-Agent"))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue