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 external provider interface versioning #30

Merged
merged 17 commits into from
Aug 21, 2024

Conversation

fabi200123
Copy link
Contributor

This PR adds external 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 ID and Pool ExtraSpecs
  • default version will remain v0.1.0

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 soon


type ExecutionCommand string

const (
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 be in a common package. If we decide to add more commands in newer versions of the interface, we can just use the new commands in the new version while the old version can ignore them.


// If this is a CreateInstance command, we need to get the bootstrap params
// from stdin
if env.Command == CreateInstanceCommand {
Copy link
Member

Choose a reason for hiding this comment

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

There is a lot of common code here that is true for the old version and the new version. Dealing with stdin for example, the need to gather extra info for the CreateInstance command, etc.

We must see what actually differs between the old version and the new version, properly identify what we can reuse or make common and de-duplicate some of this code.

// ExternalProvider defines an interface that external providers need to implement.
// This is very similar to the common.Provider interface, and was redefined here to
// decouple it, in case it may diverge from native providers.
type ExternalProvider interface {
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a ValidatePoolInfo() function and a new associated command that receives image, flavor, provider config and extra specs and returns an error? This would allow us to run a validation check any time a pool is created or updated.

StartInstanceCommand ExecutionCommand = "StartInstance"
StopInstanceCommand ExecutionCommand = "StopInstance"
RemoveAllInstancesCommand ExecutionCommand = "RemoveAllInstances"
ValidatePoolInfoCommand common.ExecutionCommand = "ValidatePoolInfo"
Copy link
Member

Choose a reason for hiding this comment

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

you can add these to the common package as well. Maybe in a separate const() block. This way you can avoid 2 imports in the v0.1.1 package.

Each package does a swirch anyway and only acts on particular commands. There is no overlap in command names, so feel free to move these in the common package as well.

Add a comment that they are a v0.1.1 set of commands and it should be fine.

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

if e.ControllerID == "" {
return fmt.Errorf("missing controller ID")
}
case common.GetVersionCommand:
Copy link
Member

Choose a reason for hiding this comment

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

The GetVersion command currently manually baked into the existing providers will return the version of the provider itself:

https://github.com/cloudbase/garm-provider-openstack/blob/ac46d4d5a542bca96cd0309c89437d3382c3ea26/main.go#L41-L49

Copy link
Member

Choose a reason for hiding this comment

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

The interface version is already an exported field, which is parsed from the variables that the server sets, so there is little chance that the server will want to query that back. And a user will want to essentially get the version of the provider.

// decouple it, in case it may diverge from native providers.
type ExternalProvider interface {
// CreateInstance creates a new compute instance in the provider.
CreateInstance(ctx context.Context, bootstrapParams params.BootstrapInstance) (params.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.

It seems that the signatures for the common functions both this version and the previous version, are identical. It makes sense to create a common interface with the common functions, and embed that common interface in both this one and the previous version.

If the previous version is identical to the base one, you can just create an alias to the base interface. Or just use the base interface directly.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would be better to embed the interface than go directly for the common one. So I went for this implementation

@gabriel-samfira gabriel-samfira merged commit dfdf8e2 into cloudbase:main Aug 21, 2024
2 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