kinvolk / lokomotive

🪦 DISCONTINUED Further Lokomotive development has been discontinued. Lokomotive is a 100% open-source, easy to use and secure Kubernetes distribution from the volks at Kinvolk
https://kinvolk.io/lokomotive-kubernetes/
Apache License 2.0
321 stars 49 forks source link

Refactor platform handling #716

Open johananl opened 4 years ago

johananl commented 4 years ago

General

At the moment the platform package has multiple responsibilities:

We should consider refactoring the platform package to have a single purpose: defining the contents of a Lokomotive platform. The rationale for doing the refactor:

Following the refactoring, the following should be true:

Implementation

When implementing this change, we should look for cases where we have "specialized" logic for a platform and ideally eliminate such cases. This is important if we want to make Terraform-related code generic. An example of such specialized logic:

https://github.com/kinvolk/lokomotive/blob/fee1edde76bf3d1a667f1fc0443802863569958e/pkg/platform/packet/packet.go#L142-L160

https://github.com/kinvolk/lokomotive/blob/fee1edde76bf3d1a667f1fc0443802863569958e/pkg/platform/aws/aws.go#L143-L152

As can be seen above, the Packet implementation of Initialize() contains things like API token validation and DNS config validation whereas the AWS implementation of the same function does not.

If we realize we can't make Terraform-related code completely generic, we can look into allowing arbitrary logic to be specified in a platform implementation, for example using callback functions. We should do our best to keep things well defined if we go in this direction. For example, we may want to consider defining a small set of "hooks" to allow a platform implementation to specific, for example, that some arbitrary logic needs to be run before/after executing terraform apply, before/after applying Lokomotive components etc.

A central part of this refactoring should be re-examining the Platform interface and changing it so that it properly matches the responsibility of the platform package and exposes a limited set of methods which every platform implementation should implement.

@invidian, @iaguis - FYI.

johananl commented 4 years ago

A relevant discussion: https://github.com/kinvolk/lokomotive/pull/655#issuecomment-654840222

invidian commented 4 years ago

IMO The main constraint for the refactoring would be to make platform-specific packages (e.g. pkg/platform/aws, pkg/platform/packet) to contain only platform-unique information. This would include:

Following actions should be generic to all platforms:

Configuration loading should be done separately from the platform-specific package, perhaps in HCL package (which we do not have right now). I guess this can be left for later.

Also related: #666 #499 #478

rugwirobaker commented 3 years ago

Is it a must for baremetal to use matchbox? Cause I am exploring other projects in the same space. https://github.com/plunder-app/plunder and http://tinkerbell.org/ to name a few.

invidian commented 3 years ago

@rugwirobaker I'm not sure what you mean, but you might also be interested in https://github.com/kinvolk/lokomotive/pull/392, where experimental support for Tinkerbell is implemented.

rugwirobaker commented 3 years ago

@invidian just skimming through the code in pkg/platform the structure seemed it is intended to support just one bare-metal provisioner. I'm gonna go ahead and checkout it.

invidian commented 3 years ago

@rugwirobaker ah, I know what you mean now. We also have #383 to actually rename baremetal to matchbox, so we can support more.

rugwirobaker commented 3 years ago

@invidian is there somewhere a setup guide using Tinkerbell?

invidian commented 3 years ago

There are some hints here: https://github.com/kinvolk/lokomotive/pull/392/files#diff-7196abe142cd5822d69f345a960f986fR1

For setting up Tinkerbell, follow https://tinkerbell.org/docs/setup/.

For the configuration structure, you can look at https://github.com/kinvolk/lokomotive/pull/392/files#diff-f0ab264028d0de5d78c3665c00a126f2R31-R72.

I hope that helps, given that the PR is not fully ready yet.