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

Baseboardmanagement controller implementation #3

Merged
merged 16 commits into from
May 17, 2022

Conversation

pokearu
Copy link
Contributor

@pokearu pokearu commented May 5, 2022

Description

This PR adds the reconciler implementation for the baseboardmanagement controller.
The controller ensures state for baseboardmanagement api type. On each reconcile loop,

  1. Fetch the baseboardmanagement object, error if not found.
  2. resolve the SecretReference to obtain connectivity information.
  3. Initialize a bmc client and do a power status call. If connection error, update .Status.Conditions.
  4. If BMC is not in desired state, set power state and update .Status.Power.

How Has This Been Tested?

I tested by generating a manifest and applying the controller to a cluster.

kind create cluster
make release-manifests
kubectl apply -f out/release/manifest.yaml

How are existing users impacted? What migration steps/scripts do we need?

No impact for existing users.

Checklist:

I have:

  • updated the documentation and/or roadmap (if required)
  • added unit or e2e tests
  • provided instructions on how to upgrade

@pokearu pokearu force-pushed the baseboardmanagement-controller branch from d6f2eb1 to dfe231e Compare May 5, 2022 21:17
@codecov-commenter
Copy link

codecov-commenter commented May 5, 2022

Codecov Report

Merging #3 (65acac8) into main (70769a2) will increase coverage by 54.46%.
The diff coverage is 64.13%.

@@            Coverage Diff             @@
##            main       #3       +/-   ##
==========================================
+ Coverage   0.00%   54.46%   +54.46%     
==========================================
  Files          3        4        +1     
  Lines         21      112       +91     
==========================================
+ Hits           0       61       +61     
- Misses        21       42       +21     
- Partials       0        9        +9     
Impacted Files Coverage Δ
controllers/bmcclient.go 0.00% <0.00%> (ø)
controllers/baseboardmanagement_controller.go 67.03% <69.41%> (+67.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 70769a2...65acac8. Read the comment docs.

config/rbac/role.yaml Outdated Show resolved Hide resolved
controllers/baseboardmanagement_controller.go Outdated Show resolved Hide resolved
controllers/baseboardmanagement_controller.go Outdated Show resolved Hide resolved
controllers/baseboardmanagement_controller.go Outdated Show resolved Hide resolved
}

// Initializing BMC Client connection
r.BMCClient.InitClient(bm.Spec.Connection.Host, "623", username, password)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is port hardcoded? Shouldn't that be configurable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad. I was going to have a TODO to add this to the BaseboardManagement api.
Will update 👍

pkg/bmc/client/factory/factory.go Outdated Show resolved Hide resolved
pkg/bmc/client/client.go Outdated Show resolved Hide resolved
pkg/bmc/client/client.go Outdated Show resolved Hide resolved
pkg/bmc/client/bmclib/bmclib.go Outdated Show resolved Hide resolved
pkg/bmc/client/bmclib/bmclib.go Outdated Show resolved Hide resolved
@pokearu pokearu force-pushed the baseboardmanagement-controller branch from 1fdfb67 to 4038d9e Compare May 12, 2022 22:47
Copy link
Member

@chrisdoherty4 chrisdoherty4 left a comment

Choose a reason for hiding this comment

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

Looks OK. Just need to move the types around and get rid of some redundant code + some cleanup.

pkg/bmcclient/bmcclient.go Outdated Show resolved Hide resolved
controllers/baseboardmanagement_controller.go Outdated Show resolved Hide resolved
controllers/baseboardmanagement_controller.go Outdated Show resolved Hide resolved
err = r.BMCClient.OpenConnection(ctx)
if err != nil {
logger.Error(err, "BMC connection failed", "host", bm.Spec.Connection.Host)
result, setConditionErr := r.setCondition(ctx, bm, bmcv1alpha1.ConnectionError, err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

@pokearu Wants to address the conditions discussion in a separate PR so resolving for now.

controllers/baseboardmanagement_controller.go Outdated Show resolved Hide resolved
controllers/baseboardmanagement_controller.go Outdated Show resolved Hide resolved
controllers/baseboardmanagement_controller.go Outdated Show resolved Hide resolved
controllers/baseboardmanagement_controller.go Outdated Show resolved Hide resolved
controllers/baseboardmanagement_controller.go Outdated Show resolved Hide resolved
controllers/baseboardmanagement_controller.go Show resolved Hide resolved
Copy link
Member

@chrisdoherty4 chrisdoherty4 left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@micahhausler micahhausler left a comment

Choose a reason for hiding this comment

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

Just a few minor questions/changes

controllers/baseboardmanagement_controller.go Outdated Show resolved Hide resolved

// TODO (pokearu): Remove port hardcoding
// Initializing BMC Client
bmcClient, err := r.bmcClientFactory(ctx, bm.Spec.Connection.Host, "623", username, password)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you going to remove this hardcoding in this PR?

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 was planning to do a quick follow up PR. Was going to add it to the BaseboardManagement api connection struct.

}
for _, reconiler := range fieldReconcilers {
if err := reconiler(ctx, bm, bmcClient); err != nil {
logger.Error(err, "Failed to reconcile BaseboardManagement", "host", bm.Spec.Connection.Host)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you still want to update the status on failure. You want to converge on desired state, not make it all-or-nothing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed, I modified the reconciler to update status when reconciling fields 👍


// patchStatus patches the specifies patch on the BaseboardManagement.
func (r *BaseboardManagementReconciler) patchStatus(ctx context.Context, bm *bmcv1alpha1.BaseboardManagement, patch client.Patch) (ctrl.Result, error) {
err := r.client.Status().Patch(ctx, bm, patch)
Copy link
Contributor

Choose a reason for hiding this comment

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

@chrisdoherty4 @jacobweinstock there is no idempotency/locking in the whole reconcile, do we want/need that?

Copy link
Member

Choose a reason for hiding this comment

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

Nope. When you're only considering the object under reconciliation there's no races as the manager ensures you're the only reconciler reconciling that resource.

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, of course, the possibility that an object is patched by something else but I don't think we have those semantics here.

main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
@pokearu pokearu force-pushed the baseboardmanagement-controller branch from 0c60ca4 to 65acac8 Compare May 17, 2022 17:44
Copy link
Contributor

@micahhausler micahhausler left a comment

Choose a reason for hiding this comment

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

LGTM

@micahhausler micahhausler added the ready-to-merge Mergify: Ready for Merging label May 17, 2022
@mergify mergify bot merged commit 0732a9c into tinkerbell:main May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge Mergify: Ready for Merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants