-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add provider interface versioning #278
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright 2022 Cloudbase Solutions SRL | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. You may obtain | ||
// a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package common | ||
|
||
import "github.com/cloudbase/garm/params" | ||
|
||
// Constants used for the provider interface version. | ||
const ( | ||
Version010 = "v0.1.0" | ||
Version011 = "v0.1.1" | ||
) | ||
|
||
// Each struct is a wrapper for the actual parameters struct for a specific version. | ||
// Version 0.1.0 doesn't have any specific parameters, so there is no need for a struct for it. | ||
type CreateInstanceParams struct { | ||
CreateInstanceV011 CreateInstanceV011Params | ||
} | ||
|
||
type DeleteInstanceParams struct { | ||
DeleteInstanceV011 DeleteInstanceV011Params | ||
} | ||
|
||
type GetInstanceParams struct { | ||
GetInstanceV011 GetInstanceV011Params | ||
} | ||
|
||
type ListInstancesParams struct { | ||
ListInstancesV011 ListInstancesV011Params | ||
} | ||
|
||
type RemoveAllInstancesParams struct { | ||
RemoveAllInstancesV011 RemoveAllInstancesV011Params | ||
} | ||
|
||
type StopParams struct { | ||
StopV011 StopV011Params | ||
} | ||
|
||
type StartParams struct { | ||
StartV011 StartV011Params | ||
} | ||
|
||
// Struct for the base provider parameters. | ||
type ProviderBaseParams struct { | ||
PoolInfo params.Pool | ||
ControllerInfo params.ControllerInfo | ||
} | ||
|
||
// Structs for version v0.1.1. | ||
type CreateInstanceV011Params struct { | ||
ProviderBaseParams | ||
} | ||
|
||
type DeleteInstanceV011Params struct { | ||
ProviderBaseParams | ||
} | ||
|
||
type GetInstanceV011Params struct { | ||
ProviderBaseParams | ||
} | ||
|
||
type ListInstancesV011Params struct { | ||
ProviderBaseParams | ||
} | ||
|
||
type RemoveAllInstancesV011Params struct { | ||
ProviderBaseParams | ||
} | ||
|
||
type StopV011Params struct { | ||
ProviderBaseParams | ||
} | ||
|
||
type StartV011Params struct { | ||
ProviderBaseParams | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -589,7 +589,15 @@ func (r *basePoolManager) cleanupOrphanedGithubRunners(runners []*github.Runner) | |
slog.DebugContext( | ||
r.ctx, "updating instances cache for pool", | ||
"pool_id", pool.ID) | ||
poolInstances, err = provider.ListInstances(r.ctx, pool.ID) | ||
listInstancesParams := common.ListInstancesParams{ | ||
ListInstancesV011: common.ListInstancesV011Params{ | ||
ProviderBaseParams: common.ProviderBaseParams{ | ||
PoolInfo: pool, | ||
ControllerInfo: r.controllerInfo, | ||
}, | ||
}, | ||
} | ||
poolInstances, err = provider.ListInstances(r.ctx, pool.ID, listInstancesParams) | ||
if err != nil { | ||
return errors.Wrapf(err, "fetching instances for pool %s", pool.ID) | ||
} | ||
|
@@ -654,7 +662,15 @@ func (r *basePoolManager) cleanupOrphanedGithubRunners(runners []*github.Runner) | |
r.ctx, "instance was found in stopped state; starting", | ||
"runner_name", dbInstance.Name) | ||
|
||
if err := provider.Start(r.ctx, dbInstance.ProviderID); err != nil { | ||
startParams := common.StartParams{ | ||
StartV011: common.StartV011Params{ | ||
ProviderBaseParams: common.ProviderBaseParams{ | ||
PoolInfo: pool, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated it now |
||
ControllerInfo: r.controllerInfo, | ||
}, | ||
}, | ||
} | ||
if err := provider.Start(r.ctx, dbInstance.ProviderID, startParams); err != nil { | ||
return errors.Wrapf(err, "starting instance %s", dbInstance.ProviderID) | ||
} | ||
return nil | ||
|
@@ -870,7 +886,15 @@ func (r *basePoolManager) addInstanceToProvider(instance params.Instance) error | |
|
||
defer func() { | ||
if instanceIDToDelete != "" { | ||
if err := provider.DeleteInstance(r.ctx, instanceIDToDelete); err != nil { | ||
deleteInstanceParams := common.DeleteInstanceParams{ | ||
DeleteInstanceV011: common.DeleteInstanceV011Params{ | ||
ProviderBaseParams: common.ProviderBaseParams{ | ||
PoolInfo: pool, | ||
ControllerInfo: r.controllerInfo, | ||
}, | ||
}, | ||
} | ||
if err := provider.DeleteInstance(r.ctx, instanceIDToDelete, deleteInstanceParams); err != nil { | ||
if !errors.Is(err, runnerErrors.ErrNotFound) { | ||
slog.With(slog.Any("error", err)).ErrorContext( | ||
r.ctx, "failed to cleanup instance", | ||
|
@@ -880,7 +904,15 @@ func (r *basePoolManager) addInstanceToProvider(instance params.Instance) error | |
} | ||
}() | ||
|
||
providerInstance, err := provider.CreateInstance(r.ctx, bootstrapArgs) | ||
createInstanceParams := common.CreateInstanceParams{ | ||
CreateInstanceV011: common.CreateInstanceV011Params{ | ||
ProviderBaseParams: common.ProviderBaseParams{ | ||
PoolInfo: pool, | ||
ControllerInfo: r.controllerInfo, | ||
}, | ||
}, | ||
} | ||
providerInstance, err := provider.CreateInstance(r.ctx, bootstrapArgs, createInstanceParams) | ||
if err != nil { | ||
instanceIDToDelete = instance.Name | ||
return errors.Wrap(err, "creating instance") | ||
|
@@ -1316,7 +1348,15 @@ func (r *basePoolManager) deleteInstanceFromProvider(ctx context.Context, instan | |
"runner_name", instance.Name, | ||
"provider_id", identifier) | ||
|
||
if err := provider.DeleteInstance(ctx, identifier); err != nil { | ||
deleteInstanceParams := common.DeleteInstanceParams{ | ||
DeleteInstanceV011: common.DeleteInstanceV011Params{ | ||
ProviderBaseParams: common.ProviderBaseParams{ | ||
PoolInfo: pool, | ||
ControllerInfo: r.controllerInfo, | ||
}, | ||
}, | ||
} | ||
if err := provider.DeleteInstance(ctx, identifier, deleteInstanceParams); err != nil { | ||
return errors.Wrap(err, "removing instance") | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, the base params will always contain the same thing. Please create a function in the
basePoolManager{}
that returns theProviderBaseParams{}
struct. And you can just call it.The function should be protected by
r.mux.Lock()
as the pool info can be changed and updated by the DB watcher.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might also want to switch on the interface version in the future and return the appropriate
ListInstancesParams{}