Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

🐛 Fix error-return for machine-cluster association #226

Conversation

kashifest
Copy link
Contributor

@kashifest kashifest commented Sep 13, 2019

What this PR does / why we need it:
Removes error and waits again if

a) machine does not have any associated cluster
b) Machine has associate cluster but it is still non-existent

Which issue(s) this PR fixes (optional, in fixes #(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #212

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 13, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @kashifest. Thanks for your PR.

I'm waiting for a kubernetes-sigs or kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 13, 2019
@kashifest
Copy link
Contributor Author

/assign @vincepri

@detiber
Copy link
Contributor

detiber commented Sep 13, 2019

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 13, 2019
} else {
log.Error(err, "could not get cluster by machine metadata")
return ctrl.Result{}, err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not seeing a clean way to switch this into a switch statement to appease the linter, but since each branch has a return, you can remove the else clauses:

		if errors.Cause(err) == util.ErrNoCluster {
			log.Info("Machine does not belong to a cluster yet, waiting until its part of a cluster")
			return ctrl.Result{}, nil
		}

		if apierrors.IsNotFound(err) {
			log.Info("Cluster does not exist yet , waiting until it is created")
			return ctrl.Result{}, nil
		}

		log.Error(err, "could not get cluster by machine metadata")
		return ctrl.Result{}, err		

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@detiber Thanks. I will do the change

@kashifest kashifest force-pushed the bugfix/kubeadmController-issue214 branch from c569a9d to 1da771e Compare September 13, 2019 12:28
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 13, 2019
@@ -127,6 +127,16 @@ func (r *KubeadmConfigReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, re
// Lookup the cluster the machine is associated with
cluster, err := util.GetClusterFromMetadata(ctx, r.Client, machine.ObjectMeta)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do y'all think about a switch statement instead?

switch {
case errors.Cause(err) == util.ErrNoCluster:
case apierrors.IsNotFound(err):
case err != nil:
}

?

@chuckha
Copy link
Contributor

chuckha commented Sep 13, 2019

/approve

if you end up using the switch that's cool, but i'm happy with this as is also!

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chuckha, kashifest

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 Sep 13, 2019
@detiber
Copy link
Contributor

detiber commented Sep 13, 2019

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 13, 2019
@k8s-ci-robot k8s-ci-robot merged commit 093a241 into kubernetes-retired:master Sep 13, 2019
@kashifest kashifest deleted the bugfix/kubeadmController-issue214 branch September 16, 2019 05:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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 Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

should return without an error if no cluster is set on the machine
5 participants