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

Simplify data structures and remove redundant interfaces #305

Merged
merged 2 commits into from
Aug 22, 2023

Conversation

chrisdoherty4
Copy link
Member

@chrisdoherty4 chrisdoherty4 commented Aug 20, 2023

Summary

The existing machine reconciliation code leveraged 3 different data structures (TinkerbellMachineReconciler, machineReconcileContext and baseMachineReconcileContext) and 2 interfaces (ReconcileContext and BaseMachineReconcileContext).

The machineReconcileContext extends the baseMachineReconcileContext but the relationship is misappropriated and superfluous.

The ReconcileContext and the BaseMachineReconcileContext have no discernible purpose.

Changes

  • Delete the ReconcileContext and BaseMachineReconcileContext interfaces.
  • Combine the baseMachineReconcileContext and machineReconcileContext into a single data structure, machineReconcileScope.
  • Move machineReconcileScope construction logic to the TinkerbellMachineReconciler.Reconcile() call keeping the construction in a single place.

Motivation

  • Simpler code is easier to maintain.
  • Updating to newer versions of Cluster API are easier when we understand the code better.

What's next?

  • There's too close a relationship between the construction logic and delete reconciliation.
  • Rework package structure so objects can be better tested (probably through the use of internal packages).
  • Evaluating other logic to check for bugs. On performing this refactor there were some interesting smells that could contribute to recent reports of objects not reconciling.
  • Updating to a recent Cluster API version.

Signed-off-by: Chris Doherty <chris.doherty4@gmail.com>
Copy link
Member Author

@chrisdoherty4 chrisdoherty4 Aug 20, 2023

Choose a reason for hiding this comment

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

The functionality in this file is 90% copy-and-paste from the previous machine.go and base.go files. Lines 705 to 1046 are copied from base.go. Everything else is the original machine.go.

patchHelper *patch.Helper
client client.Client

machine *clusterv1.Machine
Copy link
Member Author

Choose a reason for hiding this comment

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

These 3 fields were moved from the base object to ensure the existing functions could work without alteration.

@chrisdoherty4 chrisdoherty4 force-pushed the chore/remove-redundant-sources branch 3 times, most recently from 0746934 to 722b63a Compare August 20, 2023 23:07
@chrisdoherty4 chrisdoherty4 changed the title Simplify sources Simplify data structures and remove redundant interfaces Aug 20, 2023
@@ -54,30 +56,79 @@ type TinkerbellMachineReconciler struct {
// +kubebuilder:rbac:groups=bmc.tinkerbell.org,resources=jobs,verbs=get;list;watch;create

// Reconcile ensures that all Tinkerbell machines are aligned with a given spec.
func (tmr *TinkerbellMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
bmrc, err := tmr.newReconcileContext(ctx, req.NamespacedName)
Copy link
Member Author

Choose a reason for hiding this comment

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

The implementation of the newReconcileContext() has been moved to the Reconcile() call (lines 64-91).

}

mrc, err := bmrc.IntoMachineReconcileContext()
Copy link
Member Author

Choose a reason for hiding this comment

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

The implementation of IntoMachineReconcileContext() has been moved to the Reconcile() call (lines 97-131).

Comment on lines +599 to +600
t.Run("reconciler_is_nil", machineReconciliationPanicsWhenReconcilerIsNil) //nolint:paralleltest
t.Run("reconciler_has_no_client_set", machineReconciliationPanicsWhenReconcilerHasNoClientSet) //nolint:paralleltest
Copy link
Member Author

@chrisdoherty4 chrisdoherty4 Aug 20, 2023

Choose a reason for hiding this comment

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

See inline comments for explanation on the panic (tinkerbellmachine_controller.go:60)

@chrisdoherty4 chrisdoherty4 marked this pull request as ready for review August 20, 2023 23:38
The base and machine reconciliation contexts were confusing and
indicative of a hierarchical relationship. This change simplifies the 2
data structures into a single machineReconcileScope data structure.

The root TinkerbellMachineController is now responsible for correctly
constructing the scope object before calling its Reconcile() function.
This reduces the reconciliation complexity.

Signed-off-by: Chris Doherty <chris.doherty4@gmail.com>
@chrisdoherty4
Copy link
Member Author

@Mergifyio queue

@mergify
Copy link
Contributor

mergify bot commented Aug 22, 2023

queue

✅ The pull request has been merged automatically

The pull request has been merged automatically at bc4a272

@mergify mergify bot merged commit bc4a272 into tinkerbell:main Aug 22, 2023
7 checks passed
This pull request was closed.
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