This branch adds the ability to forcefully remove a runner from GARM. When the operator wishes to manually remove a runner, the workflow is as follows: * Check that the runner exists in GitHub. If it does, attempt to remove it. An error here indicates that the runner may be processing a job. In this case, we don't continue and the operator gets immediate feedback from the API. * Mark the runner in the database as pending_delete * Allow the consolidate loop to reap it from the provider and remove it from the database. Removing the instance from the provider is async. If the provider errs out, GARM will keep trying to remove it in perpetuity until the provider succedes. In situations where the provider is misconfigured, this will never happen, leaving the instance in a permanent state of pending_delete. A provider may fail for various reasons. Either credentials have expired, the API endpoint has changed, the provider is misconfigured or the operator may just have removed it from the config before cleaning up the runners. While some cases are recoverable, some are not. We cannot have a situation in which we cannot clean resources in garm because of a misconfiguration. This change adds the pending_force_delete instance status. Instances marked with this status, will be removed from GARM even if the provider reports an error. The GARM cli has been modified to give new meaning to the --force-remove-runner option. This option in the CLI is no longer mandatory. Instead, setting it will mark the runner with the new pending_force_delete status. Omitting it will mark the runner with the old status of pending_delete. Fixes: #160 Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
231 lines
7.3 KiB
Go
231 lines
7.3 KiB
Go
// Code generated by mockery v2.28.1. DO NOT EDIT.
|
|
|
|
package mocks
|
|
|
|
import (
|
|
context "context"
|
|
|
|
github "github.com/google/go-github/v55/github"
|
|
mock "github.com/stretchr/testify/mock"
|
|
)
|
|
|
|
// GithubEnterpriseClient is an autogenerated mock type for the GithubEnterpriseClient type
|
|
type GithubEnterpriseClient struct {
|
|
mock.Mock
|
|
}
|
|
|
|
// CreateRegistrationToken provides a mock function with given fields: ctx, enterprise
|
|
func (_m *GithubEnterpriseClient) CreateRegistrationToken(ctx context.Context, enterprise string) (*github.RegistrationToken, *github.Response, error) {
|
|
ret := _m.Called(ctx, enterprise)
|
|
|
|
var r0 *github.RegistrationToken
|
|
var r1 *github.Response
|
|
var r2 error
|
|
if rf, ok := ret.Get(0).(func(context.Context, string) (*github.RegistrationToken, *github.Response, error)); ok {
|
|
return rf(ctx, enterprise)
|
|
}
|
|
if rf, ok := ret.Get(0).(func(context.Context, string) *github.RegistrationToken); ok {
|
|
r0 = rf(ctx, enterprise)
|
|
} else {
|
|
if ret.Get(0) != nil {
|
|
r0 = ret.Get(0).(*github.RegistrationToken)
|
|
}
|
|
}
|
|
|
|
if rf, ok := ret.Get(1).(func(context.Context, string) *github.Response); ok {
|
|
r1 = rf(ctx, enterprise)
|
|
} else {
|
|
if ret.Get(1) != nil {
|
|
r1 = ret.Get(1).(*github.Response)
|
|
}
|
|
}
|
|
|
|
if rf, ok := ret.Get(2).(func(context.Context, string) error); ok {
|
|
r2 = rf(ctx, enterprise)
|
|
} else {
|
|
r2 = ret.Error(2)
|
|
}
|
|
|
|
return r0, r1, r2
|
|
}
|
|
|
|
// GenerateEnterpriseJITConfig provides a mock function with given fields: ctx, enterprise, request
|
|
func (_m *GithubEnterpriseClient) GenerateEnterpriseJITConfig(ctx context.Context, enterprise string, request *github.GenerateJITConfigRequest) (*github.JITRunnerConfig, *github.Response, error) {
|
|
ret := _m.Called(ctx, enterprise, request)
|
|
|
|
var r0 *github.JITRunnerConfig
|
|
var r1 *github.Response
|
|
var r2 error
|
|
if rf, ok := ret.Get(0).(func(context.Context, string, *github.GenerateJITConfigRequest) (*github.JITRunnerConfig, *github.Response, error)); ok {
|
|
return rf(ctx, enterprise, request)
|
|
}
|
|
if rf, ok := ret.Get(0).(func(context.Context, string, *github.GenerateJITConfigRequest) *github.JITRunnerConfig); ok {
|
|
r0 = rf(ctx, enterprise, request)
|
|
} else {
|
|
if ret.Get(0) != nil {
|
|
r0 = ret.Get(0).(*github.JITRunnerConfig)
|
|
}
|
|
}
|
|
|
|
if rf, ok := ret.Get(1).(func(context.Context, string, *github.GenerateJITConfigRequest) *github.Response); ok {
|
|
r1 = rf(ctx, enterprise, request)
|
|
} else {
|
|
if ret.Get(1) != nil {
|
|
r1 = ret.Get(1).(*github.Response)
|
|
}
|
|
}
|
|
|
|
if rf, ok := ret.Get(2).(func(context.Context, string, *github.GenerateJITConfigRequest) error); ok {
|
|
r2 = rf(ctx, enterprise, request)
|
|
} else {
|
|
r2 = ret.Error(2)
|
|
}
|
|
|
|
return r0, r1, r2
|
|
}
|
|
|
|
// ListRunnerApplicationDownloads provides a mock function with given fields: ctx, enterprise
|
|
func (_m *GithubEnterpriseClient) ListRunnerApplicationDownloads(ctx context.Context, enterprise string) ([]*github.RunnerApplicationDownload, *github.Response, error) {
|
|
ret := _m.Called(ctx, enterprise)
|
|
|
|
var r0 []*github.RunnerApplicationDownload
|
|
var r1 *github.Response
|
|
var r2 error
|
|
if rf, ok := ret.Get(0).(func(context.Context, string) ([]*github.RunnerApplicationDownload, *github.Response, error)); ok {
|
|
return rf(ctx, enterprise)
|
|
}
|
|
if rf, ok := ret.Get(0).(func(context.Context, string) []*github.RunnerApplicationDownload); ok {
|
|
r0 = rf(ctx, enterprise)
|
|
} else {
|
|
if ret.Get(0) != nil {
|
|
r0 = ret.Get(0).([]*github.RunnerApplicationDownload)
|
|
}
|
|
}
|
|
|
|
if rf, ok := ret.Get(1).(func(context.Context, string) *github.Response); ok {
|
|
r1 = rf(ctx, enterprise)
|
|
} else {
|
|
if ret.Get(1) != nil {
|
|
r1 = ret.Get(1).(*github.Response)
|
|
}
|
|
}
|
|
|
|
if rf, ok := ret.Get(2).(func(context.Context, string) error); ok {
|
|
r2 = rf(ctx, enterprise)
|
|
} else {
|
|
r2 = ret.Error(2)
|
|
}
|
|
|
|
return r0, r1, r2
|
|
}
|
|
|
|
// ListRunnerGroups provides a mock function with given fields: ctx, enterprise, opts
|
|
func (_m *GithubEnterpriseClient) ListRunnerGroups(ctx context.Context, enterprise string, opts *github.ListEnterpriseRunnerGroupOptions) (*github.EnterpriseRunnerGroups, *github.Response, error) {
|
|
ret := _m.Called(ctx, enterprise, opts)
|
|
|
|
var r0 *github.EnterpriseRunnerGroups
|
|
var r1 *github.Response
|
|
var r2 error
|
|
if rf, ok := ret.Get(0).(func(context.Context, string, *github.ListEnterpriseRunnerGroupOptions) (*github.EnterpriseRunnerGroups, *github.Response, error)); ok {
|
|
return rf(ctx, enterprise, opts)
|
|
}
|
|
if rf, ok := ret.Get(0).(func(context.Context, string, *github.ListEnterpriseRunnerGroupOptions) *github.EnterpriseRunnerGroups); ok {
|
|
r0 = rf(ctx, enterprise, opts)
|
|
} else {
|
|
if ret.Get(0) != nil {
|
|
r0 = ret.Get(0).(*github.EnterpriseRunnerGroups)
|
|
}
|
|
}
|
|
|
|
if rf, ok := ret.Get(1).(func(context.Context, string, *github.ListEnterpriseRunnerGroupOptions) *github.Response); ok {
|
|
r1 = rf(ctx, enterprise, opts)
|
|
} else {
|
|
if ret.Get(1) != nil {
|
|
r1 = ret.Get(1).(*github.Response)
|
|
}
|
|
}
|
|
|
|
if rf, ok := ret.Get(2).(func(context.Context, string, *github.ListEnterpriseRunnerGroupOptions) error); ok {
|
|
r2 = rf(ctx, enterprise, opts)
|
|
} else {
|
|
r2 = ret.Error(2)
|
|
}
|
|
|
|
return r0, r1, r2
|
|
}
|
|
|
|
// ListRunners provides a mock function with given fields: ctx, enterprise, opts
|
|
func (_m *GithubEnterpriseClient) ListRunners(ctx context.Context, enterprise string, opts *github.ListOptions) (*github.Runners, *github.Response, error) {
|
|
ret := _m.Called(ctx, enterprise, opts)
|
|
|
|
var r0 *github.Runners
|
|
var r1 *github.Response
|
|
var r2 error
|
|
if rf, ok := ret.Get(0).(func(context.Context, string, *github.ListOptions) (*github.Runners, *github.Response, error)); ok {
|
|
return rf(ctx, enterprise, opts)
|
|
}
|
|
if rf, ok := ret.Get(0).(func(context.Context, string, *github.ListOptions) *github.Runners); ok {
|
|
r0 = rf(ctx, enterprise, opts)
|
|
} else {
|
|
if ret.Get(0) != nil {
|
|
r0 = ret.Get(0).(*github.Runners)
|
|
}
|
|
}
|
|
|
|
if rf, ok := ret.Get(1).(func(context.Context, string, *github.ListOptions) *github.Response); ok {
|
|
r1 = rf(ctx, enterprise, opts)
|
|
} else {
|
|
if ret.Get(1) != nil {
|
|
r1 = ret.Get(1).(*github.Response)
|
|
}
|
|
}
|
|
|
|
if rf, ok := ret.Get(2).(func(context.Context, string, *github.ListOptions) error); ok {
|
|
r2 = rf(ctx, enterprise, opts)
|
|
} else {
|
|
r2 = ret.Error(2)
|
|
}
|
|
|
|
return r0, r1, r2
|
|
}
|
|
|
|
// RemoveRunner provides a mock function with given fields: ctx, enterprise, runnerID
|
|
func (_m *GithubEnterpriseClient) RemoveRunner(ctx context.Context, enterprise string, runnerID int64) (*github.Response, error) {
|
|
ret := _m.Called(ctx, enterprise, runnerID)
|
|
|
|
var r0 *github.Response
|
|
var r1 error
|
|
if rf, ok := ret.Get(0).(func(context.Context, string, int64) (*github.Response, error)); ok {
|
|
return rf(ctx, enterprise, runnerID)
|
|
}
|
|
if rf, ok := ret.Get(0).(func(context.Context, string, int64) *github.Response); ok {
|
|
r0 = rf(ctx, enterprise, runnerID)
|
|
} else {
|
|
if ret.Get(0) != nil {
|
|
r0 = ret.Get(0).(*github.Response)
|
|
}
|
|
}
|
|
|
|
if rf, ok := ret.Get(1).(func(context.Context, string, int64) error); ok {
|
|
r1 = rf(ctx, enterprise, runnerID)
|
|
} else {
|
|
r1 = ret.Error(1)
|
|
}
|
|
|
|
return r0, r1
|
|
}
|
|
|
|
type mockConstructorTestingTNewGithubEnterpriseClient interface {
|
|
mock.TestingT
|
|
Cleanup(func())
|
|
}
|
|
|
|
// NewGithubEnterpriseClient creates a new instance of GithubEnterpriseClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
|
func NewGithubEnterpriseClient(t mockConstructorTestingTNewGithubEnterpriseClient) *GithubEnterpriseClient {
|
|
mock := &GithubEnterpriseClient{}
|
|
mock.Mock.Test(t)
|
|
|
|
t.Cleanup(func() { mock.AssertExpectations(t) })
|
|
|
|
return mock
|
|
}
|