Skip to content
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

Merged
merged 4 commits into from
Sep 4, 2024

Conversation

fabi200123
Copy link
Contributor

@fabi200123 fabi200123 commented Jul 22, 2024

This PR adds provider interface versioning:

  • version v0.1.0 will be the old implementation of external provider interface
  • version v0.1.1 will add in each command's Environment the Interface Version, Pool Info and Controller Info
  • default version will remain v0.1.0

NOTE This PR is using garm-provider-common version defined in this PR and must be updated accordingly after merging the PR from garm-provider-common.

Copy link
Member

@gabriel-samfira gabriel-samfira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass. Will do another tomorrow.

runner/common/params.go Outdated Show resolved Hide resolved
if e.cfg == nil {
return false
switch cfg.External.InterfaceVersion {
case "v0.1.0":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably define these as a constant or variable somewhere. We can also reference that constant/variable in the config package where we validate the external provider config, when we make sure that InterfaceVersion is valid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this can probably be:

case "v0.1.0", "":

Which will mean an explicit 0.1.0 or if not set, default to 0.1.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defined "v0.1.0" and "v0.1.1" as constants in runner/common/params.go (where are also the ActionInstanceParams)

runner/providers/external/external.go Show resolved Hide resolved
fmt.Sprintf("GARM_POOL_ID=%s", bootstrapParams.PoolID),
fmt.Sprintf("GARM_PROVIDER_CONFIG_FILE=%s", e.cfg.External.ConfigFile),
fmt.Sprintf("GARM_POOL_IMAGE=%s", createInstanceParams.CreateInstanceV011.PoolInfo.Image),
fmt.Sprintf("GARM_POOL_EXTRASPECS=%s", string(extraspecsValue)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a json may have all sorts of characters that may break shells. Have this be a base64 encoded string. That will ensure no weirdness will happen.

fmt.Sprintf("GARM_CONTROLLER_ID=%s", e.controllerID),
fmt.Sprintf("GARM_POOL_ID=%s", bootstrapParams.PoolID),
fmt.Sprintf("GARM_PROVIDER_CONFIG_FILE=%s", e.cfg.External.ConfigFile),
fmt.Sprintf("GARM_POOL_IMAGE=%s", createInstanceParams.CreateInstanceV011.PoolInfo.Image),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is already set in the bootstrap we send to stdin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, removed it for CreateInstance. For the moment, changed it to CreateInstance(ctx context.Context, bootstrapParams commonParams.BootstrapInstance, _ common.CreateInstanceParams) since we don't use (for now) anything from there

// lifecycle state that it can influence. The sole purpose of a provider is to
// manage the lifecycle of an instance. Statuses that indicate an instance should
// be created or removed, will be set by the controller.
func IsValidProviderStatus(status commonParams.InstanceStatus) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably live in a common package considering this validates what GARM expects from any provider (external or otherwise)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a new util package in runner/providers/util for this common part

@fabi200123 fabi200123 changed the title [WIP] Add provider interface versioning Add provider interface versioning Aug 21, 2024
Copy link
Member

@gabriel-samfira gabriel-samfira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 1 review. Will do another review soon.

@@ -77,6 +77,10 @@ func GetEnvironment() (Environment, error) {
if err := json.Unmarshal(data.Bytes(), &bootstrapParams); err != nil {
return Environment{}, fmt.Errorf("failed to decode instance params: %w", err)
}
if bootstrapParams.ExtraSpecs == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am guessing these files come from a replace statement in the go.mod file.

environmentVariables []string
}

func (e *external) validateResult(inst commonParams.ProviderInstance) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be common. This validates that the provider returns proper values and this is valid for any version.

asEnv := []string{
fmt.Sprintf("GARM_COMMAND=%s", commonExecution.CreateInstanceCommand),
fmt.Sprintf("GARM_CONTROLLER_ID=%s", e.controllerID),
fmt.Sprintf("GARM_POOL_ID=%s", bootstrapParams.PoolID),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be consistent with the rest of the functions, I think we can have the GARM_POOL_EXTRASPECS variable set here as well. I know the CreateInstance command will look for extra specs in the bootstrap instance stdin body, but we should be consistent. The fewer differences in terms of env variables, the better.

poolInstances, err = provider.ListInstances(r.ctx, pool.ID)
listInstancesParams := common.ListInstancesParams{
ListInstancesV011: common.ListInstancesV011Params{
ProviderBaseParams: common.ProviderBaseParams{
Copy link
Member

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 the ProviderBaseParams{} 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.

Copy link
Member

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{}

startParams := common.StartParams{
StartV011: common.StartV011Params{
ProviderBaseParams: common.ProviderBaseParams{
PoolInfo: pool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps r.getProviderBaseParams(pool). Here and everywhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated it now

@gabriel-samfira gabriel-samfira merged commit 3a2061a into cloudbase:main Sep 4, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants