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

Fix bug in MergeAddons and test #10045

Merged
merged 3 commits into from
Oct 16, 2020

Conversation

nckturner
Copy link
Contributor

I was a little bit confused by the desired behavior of the AddonMenu merge in channels so I decided to write a test to better understand it. Can someone help me understand the expected behavior after a merge of two AddonMenus, like what happens in apply_channel.go? Unless my understanding is incorrect, (or I've got a bug in the test) it seems like the merge behavior is incorrect, or maybe just confusing.

--- FAIL: Test_MergeAddons (0.00s)
    addons_test.go:223: Unexpected AddonMenu merge result,
        Merged:
        AddonMenu{
          Addon{Name: a, Version: 1.0.0, KubernetesVersion: >=1.18.0, Id: k8s-1.18},
        }
        
        Expected:
        AddonMenu{
          Addon{Name: a, Version: 1.0.1, KubernetesVersion: >=1.18.0, Id: k8s-1.18},
        }
        
    addons_test.go:223: Unexpected AddonMenu merge result,
        Merged:
        AddonMenu{
          Addon{Name: a, Version: 1.0.0, KubernetesVersion: >=1.18.0, Id: k8s-1.18},
        }
        
        Expected:
        AddonMenu{
          Addon{Name: a, Version: 1.0.1, KubernetesVersion: >=1.18.0, Id: k8s-1.18},
        }
        
FAIL
FAIL	k8s.io/kops/channels/pkg/channels	0.016s
FAIL

This test passes with a change in addon.go from:

if existing.ChannelVersion().replaces(v.ChannelVersion()) {

to:

if v.ChannelVersion().replaces(existing.ChannelVersion()) {

So either my intuitive understanding of the MergeAddons function is off or this is a bug?

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 12, 2020
@ayberk
Copy link

ayberk commented Oct 12, 2020

This looks like an actual bug because replaces has to be called from the new version by passing the existing as a parameter. It should be if v.ChannelVersion().replaces(existing.ChannelVersion()) indeed.

@rifelpet
Copy link
Member

Reading over the ChannelVersion.replaces code, I'm inclined to agree that this should be flipped around. Given that, I don't understand how new Kops versions could still be applying addons with updated versions. Most of this code hasn't been touched in over a year, some of it 4 years. How has this bug not been noticed until now?

/cc @justinsb for input

@k8s-ci-robot k8s-ci-robot requested a review from justinsb October 13, 2020 03:09
@k8s-ci-robot
Copy link
Contributor

@rifelpet: GitHub didn't allow me to request PR reviews from the following users: for, input.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

Reading over the ChannelVersion.replaces code, I'm inclined to agree that this should be flipped around. Given that, I don't understand how new Kops versions could still be applying addons with updated versions. Most of this code hasn't been touched in over a year, some of it 4 years. How has this bug not been noticed until now?

/cc @justinsb for input

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.

* Replace existing addon if v (new) replaces() existing, instead
  of the other way around.
@nckturner nckturner changed the title Add test for Addon Menu Fix bug in MergeAddons and test Oct 13, 2020
@nckturner
Copy link
Contributor Author

I've added a commit that modifies the check, as it does seem to make sense as the correct merge behavior, but agree with @rifelpet that its strange this has never been detected. I think its because the usages I see for MergeAddons() are where we merge the addons from the virtual file system (i.e. S3) with those from what appears to be a local filesystem location. I'm not sure this code is even used during normal operations. Further down in apply_channel.go there is additional update code, which I think is the main update logic: https://github.com/kubernetes/kops/blob/master/channels/pkg/cmd/apply_channel.go#L136-L202

Copy link
Member

@hakman hakman left a comment

Choose a reason for hiding this comment

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

These should make staticcheck happy.

@nckturner
Copy link
Contributor Author

@hakman thanks for cleaning that up

@hakman
Copy link
Member

hakman commented Oct 15, 2020

@hakman thanks for cleaning that up

No pb. Let's mention this next office hours and maybe get a quick review from @justinsb .

Co-authored-by: Ciprian Hacman <ciprianhacman@gmail.com>
@hakman
Copy link
Member

hakman commented Oct 15, 2020

/retest

@justinsb
Copy link
Member

Great find & fix - thanks @nckturner

I think we've got away with this in the past because historically we've only normally had a single manifest with our addons, so we likely haven't really gone down this codepath.

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 16, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justinsb, nckturner

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 Oct 16, 2020
@k8s-ci-robot k8s-ci-robot merged commit ba10916 into kubernetes:master Oct 16, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.19 milestone Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/channels cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants