Update ExecutorProvider interface signature

Update the `Release` signature of the `ExecutorProvider` interface.
Returning an error when releasing a resource is not actionable, and all
of the implementations of `ExecutorProvider` do not return an error.
parent 19f454ae
Pipeline #44489257 passed with stages
in 27 minutes and 9 seconds
......@@ -216,21 +216,14 @@ func (mr *RunCommand) acquireRunnerResources(provider common.ExecutorProvider, r
return nil, func() {}, fmt.Errorf("failed to update executor: %v", err)
}
releaseProviderFn := func() {
err := provider.Release(runner, executorData)
if err != nil {
logrus.WithError(err).Error("Failed to release executor")
}
}
if !mr.buildsHelper.acquireBuild(runner) {
releaseProviderFn()
provider.Release(runner, executorData)
return nil, nil, errors.New("failed to request job, runner limit met")
}
releaseFn := func() {
mr.buildsHelper.releaseBuild(runner)
releaseProviderFn()
provider.Release(runner, executorData)
}
return executorData, releaseFn, nil
......
......@@ -48,7 +48,7 @@ type ExecutorProvider interface {
CanCreate() bool
Create() Executor
Acquire(config *RunnerConfig) (ExecutorData, error)
Release(config *RunnerConfig, data ExecutorData) error
Release(config *RunnerConfig, data ExecutorData)
GetFeatures(features *FeaturesInfo) error
GetDefaultShell() string
}
......
......@@ -93,15 +93,6 @@ func (_m *MockExecutorProvider) GetFeatures(features *FeaturesInfo) error {
}
// Release provides a mock function with given fields: config, data
func (_m *MockExecutorProvider) Release(config *RunnerConfig, data ExecutorData) error {
ret := _m.Called(config, data)
var r0 error
if rf, ok := ret.Get(0).(func(*RunnerConfig, ExecutorData) error); ok {
r0 = rf(config, data)
} else {
r0 = ret.Error(0)
}
return r0
func (_m *MockExecutorProvider) Release(config *RunnerConfig, data ExecutorData) {
_m.Called(config, data)
}
......@@ -27,9 +27,7 @@ func (e DefaultExecutorProvider) Acquire(config *common.RunnerConfig) (common.Ex
return nil, nil
}
func (e DefaultExecutorProvider) Release(config *common.RunnerConfig, data common.ExecutorData) error {
return nil
}
func (e DefaultExecutorProvider) Release(config *common.RunnerConfig, data common.ExecutorData) {}
func (e DefaultExecutorProvider) GetFeatures(features *common.FeaturesInfo) error {
if e.FeaturesUpdater == nil {
......
......@@ -379,7 +379,7 @@ func (m *machineProvider) Use(config *common.RunnerConfig, data common.ExecutorD
return
}
func (m *machineProvider) Release(config *common.RunnerConfig, data common.ExecutorData) error {
func (m *machineProvider) Release(config *common.RunnerConfig, data common.ExecutorData) {
// Release machine
details, ok := data.(*machineDetails)
if ok {
......@@ -393,12 +393,11 @@ func (m *machineProvider) Release(config *common.RunnerConfig, data common.Execu
config.Machine.MaxBuilds > 0 && details.UsedCount >= config.Machine.MaxBuilds {
err := m.remove(details.Name, "Too many builds")
if err == nil {
return nil
return
}
}
details.State = machineStateIdle
}
return nil
}
func (m *machineProvider) CanCreate() bool {
......
......@@ -564,8 +564,7 @@ func TestMachineReleaseIfInvalidDataArePassed(t *testing.T) {
assert.NotNil(t, nd)
assertTotalMachines(t, p, 1, "it creates one machine")
err = p.Release(nil, nd)
assert.NoError(t, err, "it should not fail")
p.Release(nil, nd)
}
func TestMachineCreationIfFailedToConnect(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment