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

chore: make logic more readable #148

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions controllers/provisioner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ func (r *ProvisionerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
Step 1: Add or remove the label.
*/

labelShouldBePresent := node.Annotations[addKWasmNodeLabelAnnotation] == "true"
labelIsPresent := node.Labels[nodeNameLabel] == node.Name
shouldProvision := node.Annotations[addKWasmNodeLabelAnnotation] == "true" || r.AutoProvision
provisioned := node.Labels[nodeNameLabel] == node.Name

if labelShouldBePresent == labelIsPresent && !r.AutoProvision {
if shouldProvision == provisioned {
// The desired state and actual state of the Node are the same.
// No further action is required by the operator at this moment.

return ctrl.Result{}, nil
}
if labelShouldBePresent || r.AutoProvision && !labelIsPresent {

if shouldProvision && !provisioned {
// If the label should be set but is not, set it.
if node.Labels == nil {
node.Labels = make(map[string]string)
Expand All @@ -108,7 +108,9 @@ func (r *ProvisionerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
log.Err(err).Msg("Failed to create new Job " + req.Namespace + " Job.Name " + req.Name)
return ctrl.Result{}, fmt.Errorf("failed to create new job: %w", err)
}
} else if !r.AutoProvision {
}

if !shouldProvision && provisioned {
// If the label should not be set but is, remove it.
delete(node.Labels, nodeNameLabel)
log.Info().Msg("Label removed. Removing Job.")
Expand Down