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

MD controller sync getNewMachineSet should not return nil as newMS after updating existingNewMS #970

Closed
chingchiaw opened this issue May 30, 2019 · 7 comments
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete.

Comments

@chingchiaw
Copy link

chingchiaw commented May 30, 2019

/kind bug

In pkg/controller/machinedeployments/sync.go getNewMachineSet, when there's an existing new MS, and its annotations or minReadySeconds need to be updated, the controller update the MS and return nil as new MS, and the error from r.Update as follows:

minReadySecondsNeedsUpdate := msCopy.Spec.MinReadySeconds != *d.Spec.MinReadySeconds
if annotationsUpdated || minReadySecondsNeedsUpdate {
	msCopy.Spec.MinReadySeconds = *d.Spec.MinReadySeconds
	return nil, r.Update(context.Background(), msCopy)
}

IMO it should not return nil, it should return the updated MS (msCopy).

https://github.com/kubernetes-sigs/cluster-api/blame/master/pkg/controller/machinedeployment/sync.go#L111

This was introduced in the major refactoring:
Oct 4 2019: Migrate to kubebuilder #494 (#494)
revision: 80129c0

I looked up the old code before the PR and originally the line was this:

minReadySecondsNeedsUpdate := msCopy.Spec.MinReadySeconds != *d.Spec.MinReadySeconds
		if annotationsUpdated || minReadySecondsNeedsUpdate {
			msCopy.Spec.MinReadySeconds = *d.Spec.MinReadySeconds
			return dc.machineClient.ClusterV1alpha1().MachineSets(msCopy.ObjectMeta.Namespace).Update(msCopy)
	}

And this is the original Update method called:

// Update takes the representation of a machineSet and updates it. Returns the server's representation of the machineSet, and an error, if there is any.
func (c *machineSets) Update(machineSet *v1alpha1.MachineSet) (result *v1alpha1.MachineSet, err error) {
	result = &v1alpha1.MachineSet{}
	err = c.client.Put().
		Namespace(c.ns).
		Resource("machinesets").
		Name(machineSet.Name).
		Body(machineSet).
		Do().
		Into(result)
	return
}

So originally newMS was the updated MS.

I don't have a concrete repro of any issue resulted from this bug, but naively this seems to me an issue to fix.

What did you expect to happen:
The controller method should return msCopy and error from r.Update(..., msCopy) instead

Anything else you would like to add:
NA

Environment:

  • Cluster-api version: all revisions after Oct 4, 2018's 80129c0
  • Minikube/KIND version: NA
  • Kubernetes version: (use kubectl version): NA
  • OS (e.g. from /etc/os-release): NA
@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label May 30, 2019
@timothysc timothysc added good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Jun 21, 2019
@timothysc timothysc added this to the v1alpha2 milestone Jun 21, 2019
@timothysc timothysc added priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Jun 21, 2019
@dlipovetsky
Copy link
Contributor

@calebamiles and I looked at the code together.

From the doc string of getNewMachineSet:

// Returns a machine set that matches the intent of the given deployment. Returns nil if the new machine set doesn't exist yet.

Of course, L113 returns nil even though the new machine set does exist.

But none of the machine deployment tests fail because of this. So either those tests don't catch the issue, or it's not an issue (e.g. the caller of getNewMachineSet doesn't care that it returns a nil when it's supposed to return a MachineSet).

First thing to do might be to write a test for getNewMachineSet, and then to look at the machine deployment tests.

@calebamiles
Copy link

@detiber, maybe a short walkthrough of the code might be helpful. don't know if it makes sense to do so before or after the general cluster api code walkthrough

@calebamiles
Copy link

calebamiles commented Jul 2, 2019

@dlipovetsky I got two examples of testing to look at

@dlipovetsky
Copy link
Contributor

MachineDeployment from the CAPI book: https://cluster-api.sigs.k8s.io/common_code/machinedeployment_controller.html

@calebamiles
Copy link

/unassign

@ncdc ncdc modified the milestones: v0.2.x (v1alpha2), Next Sep 4, 2019
@timothysc timothysc assigned vincepri and unassigned dlipovetsky Sep 26, 2019
@timothysc timothysc removed the good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. label Sep 26, 2019
@timothysc timothysc modified the milestones: Next, v0.3.0 Sep 26, 2019
@ncdc ncdc assigned ncdc and unassigned vincepri Dec 6, 2019
@ncdc ncdc assigned vincepri and unassigned ncdc Jan 22, 2020
@ncdc ncdc modified the milestones: v0.3.0, Next Jan 29, 2020
@vincepri
Copy link
Member

We'll go through some redesign/refactor of these controllers in the future #, I think it's safe to close this for now.

Ref: #1689

/close

@k8s-ci-robot
Copy link
Contributor

@vincepri: Closing this issue.

In response to this:

We'll go through some redesign/refactor of these controllers in the future #, I think it's safe to close this for now.

Ref: #1689

/close

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete.
Projects
None yet
Development

No branches or pull requests

7 participants