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

✨Refactor CreateInstance and CreateBastion #1191

Merged
merged 4 commits into from
Apr 1, 2022

Conversation

mdbooth
Copy link
Contributor

@mdbooth mdbooth commented Apr 1, 2022

What this PR does / why we need it:
The primary purpose of this this PR is to cleanup the interface of compute.CreateInstance and make the separation of concerns between the machine controller (for Machines), the cluster controller (for the Bastion), and compute (for actual server creation) better defined.

The Bastion host is represented in the cluster spec as an Instance. An OpenStackMachine is represented by context in OpenStackMachine as well as OpenStackCluster. So while they both create a server in the same way, they both source the server's parameters in slightly different ways using different source objects.

At some point in history we also used Instance as the intermediate representation for an OpenStackMachine. That is, we combined parameters from an OpenStackMachine and an OpenStackCluster into an Instance, then passed that to CreateInstance. Instance is not ideal for this purpose as it is both Spec and Status. It contains fields which cannot be used as input parameters to CreateInstance. Therefore we refactored this into the internal-only InstanceSpec, which contains only spec fields.

This refactor takes this further. Firstly we ensure that creating an InstanceSpec from an OpenStackMachine or a cluster bastion is strictly data transformation and therefore very cheap. Anything expensive moves into the new CreateInstance. Secondly we move this code to the controller where it is relevant, and add new unit tests covering the transformation. This also reduces the scope of the CreateInstance unit tests, making them simpler.

Special notes for your reviewer:
I don't intend to squash these commits. They are intended to be independent logical steps. You may find it easier to review this PR by commit rather than as a single change.

This is the code motion portion of #1153 with functional changes to Bastion reconciliation removed.

/hold

Common network and security group handling between CreateBastion() and
CreateInstance().

A principal advantage of this refactor is that it makes the marshalling
of OpenStackMachineSpec and Instance respectively into an InstanceSpec a
cheap operation which makes no API calls.
Refactor instance creation in machine controller and cluster
controller (for the bastion) to call compute.CreateInstance() with an
InstanceSpec.
@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 1, 2022
@netlify
Copy link

netlify bot commented Apr 1, 2022

Deploy Preview for kubernetes-sigs-cluster-api-openstack ready!

Name Link
🔨 Latest commit 9b96c8f
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-openstack/deploys/62468f1811ca1a00096c8bee
😎 Deploy Preview https://deploy-preview-1191--kubernetes-sigs-cluster-api-openstack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 1, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mdbooth

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 1, 2022
@apricote
Copy link
Member

apricote commented Apr 1, 2022

I like this refactoring a lot!

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 1, 2022
@mdbooth
Copy link
Contributor Author

mdbooth commented Apr 1, 2022

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 1, 2022
@k8s-ci-robot k8s-ci-robot merged commit 6ba04de into kubernetes-sigs:main Apr 1, 2022
@mdbooth mdbooth deleted the events branch April 6, 2022 15:55
@mdbooth mdbooth restored the events branch April 6, 2022 15:56
@mdbooth mdbooth deleted the events branch April 6, 2022 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants