Skip to content

Consistent labels for channel and provisioner#698

Merged
knative-prow-robot merged 7 commits into
knative:masterfrom
sbezverk:labels
Jan 4, 2019
Merged

Consistent labels for channel and provisioner#698
knative-prow-robot merged 7 commits into
knative:masterfrom
sbezverk:labels

Conversation

@sbezverk
Copy link
Copy Markdown
Contributor

@sbezverk sbezverk commented Jan 3, 2019

Signed-off-by: Serguei Bezverkhi sbezverk@cisco.com

Fixes #690

Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jan 3, 2019
@knative-prow-robot knative-prow-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jan 3, 2019
@sbezverk
Copy link
Copy Markdown
Contributor Author

sbezverk commented Jan 3, 2019

/assign @vaikas-google

@sbezverk
Copy link
Copy Markdown
Contributor Author

sbezverk commented Jan 3, 2019

@vaikas-google @grantr I do not like this solution as labels are not defined in one place. Please advise if I could create a common package where I could define these labels and then make a func which would return them to any func where it is needed.

@grantr
Copy link
Copy Markdown
Contributor

grantr commented Jan 4, 2019

Thanks @sbezverk! Seems like the label keys could be constants in the provisioners package.

@sbezverk
Copy link
Copy Markdown
Contributor Author

sbezverk commented Jan 4, 2019

@grantr ok make sense and it looks like provisioners package gets imported in some tests.

@Harwayne
Copy link
Copy Markdown
Contributor

Harwayne commented Jan 4, 2019

We have to be careful with how we do this, it will cause duplicate VirtualServices. See #674 (comment).

We can make this backwards compatible. In this release, search based on the old labels and have the controller add the both the new and old labels to all Services and VirtualServices. Next release, only recognize the new labels (and stop writing them to existing Services and VirtualServices). This means that anyone upgrading 0.2 -> 0.3 -> 0.4 works. 0.2 -> 0.4 would have the same possible problems discussed above.

Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
@sbezverk
Copy link
Copy Markdown
Contributor Author

sbezverk commented Jan 4, 2019

@Harwayne thank you for your comment. Could you please provide steps to reproduce messages you posted in #674. I would like to see how it could be solved. Unit testing does not catch this condition.

@vaikas
Copy link
Copy Markdown
Contributor

vaikas commented Jan 4, 2019

@sbezverk I think @Harwayne is talking about an upgrade path. If somebody upgrades the eventing components and the new labels get applied.

@sbezverk
Copy link
Copy Markdown
Contributor Author

sbezverk commented Jan 4, 2019

@vaikas-google @Harwayne what about preserving old labels and add new set of labels and then at one point deprecate old labels?

@grantr
Copy link
Copy Markdown
Contributor

grantr commented Jan 4, 2019

Yep that seems like the right approach. For N releases we'll have both label styles applied.

@vaikas
Copy link
Copy Markdown
Contributor

vaikas commented Jan 4, 2019

That might work but I defer to @Harwayne because I thought there were some corner cases here.

@Harwayne
Copy link
Copy Markdown
Contributor

Harwayne commented Jan 4, 2019

@vaikas-google @Harwayne what about preserving old labels and add new set of labels and then at one point deprecate old labels?

Yes, that is the general idea. I think the procedure is:

  1. Change CreateVirtualService to compare labels, in addition to the current comparing spec. If the labels differ, update the VirtualService.

  2. Change CreateK8sService to act like CreateVirtualService, in that it compares the existing to the desired and updates existing to match desired.

  3. Add the new labels to all created Services and VirtualServices. But, only search for them based on the old labels (i.e. getK8sService and getVirtualService use a label selector that only uses the old labels).

    • The combination of this and the previous two steps means that existing Services and VirtualServices will get the updated labels added.
  4. Wait a full release.

  5. No longer search for or create using the old labels.

@sbezverk
Copy link
Copy Markdown
Contributor Author

sbezverk commented Jan 4, 2019

@Harwayne WRT point 1 of your comment. Based on the code and updated newVirtualService, see: https://github.com/knative/eventing/blob/master/pkg/provisioners/channel_util.go#L161

new newVirtualService will return VirtualService with old and new labels, if there is already VirtualService with just old labels, the equality check will fail and the existing VirtualService will be updated with new labels. It seems nothing else is required. Please confirm or Am I missing something?

Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 4, 2019
@Harwayne
Copy link
Copy Markdown
Contributor

Harwayne commented Jan 4, 2019

@Harwayne WRT point 1 of your comment. Based on the code and updated newVirtualService, see: https://github.com/knative/eventing/blob/master/pkg/provisioners/channel_util.go#L161

new newVirtualService will return VirtualService with old and new labels, if there is already VirtualService with just old labels, the equality check will fail and the existing VirtualService will be updated with new labels. It seems nothing else is required. Please confirm or Am I missing something?

You are correct that newVirtualService now creates with both old and new labels. So point 3 is finished. However, the equality check is only on spec, so if the only change is labels, it will get ignored. I think it needs to be changed to something like:

	if !equality.Semantic.DeepDerivative(expected.Spec, virtualService.Spec) || !equality.Semantic.DeepEqual(expected.Meta.Labels, virtualService.Meta.Labels) {
		virtualService.Spec = expected.Spec
		virtualService.Meta.Labels = expected.Meta.Labels
		err := client.Update(ctx, virtualService)
		if err != nil {
			return nil, err
		}
	}

That would fix point 1.

Then we would still need to make CreateK8sService look like CreateVirtualService (point 2).

Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 4, 2019
Copy link
Copy Markdown
Contributor

@Harwayne Harwayne left a comment

Choose a reason for hiding this comment

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

I think copying over non-interfering labels is a very good idea.

And I was wrong about point 2 above, it has already been done.

Comment thread pkg/provisioners/channel_util.go Outdated

// checkExpectedLabels checks the presence of expected labels and its values and return true
// if all labels are found.
func checkExpectedLabels(actual, expected map[string]string) bool {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe this is equivalent to equality.Semantic.DeepDerivative(expected, actual).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Harwayne I get your point, I was just trying to be more specific in what I check and can control. I think usage DeepDerivative in this specific case is too generic, but I do not have a strong opinion about it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have a slight preference towards using DeepDerivative, but it is weak considering how simple this function is. But, if we are going to keep it, please add unit tests for it.

Comment thread pkg/provisioners/channel_util.go Outdated
}
// Second add all missing expected labels
for k, v := range expected {
if va, ok := consolidated[k]; ok {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't this always overwrite? If the value of the label is different than expected, don't we want to overwrite that value to be what we expect?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yep, you are right, thanks for catching it.

Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
@vaikas
Copy link
Copy Markdown
Contributor

vaikas commented Jan 4, 2019

/approve

@knative-prow-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbezverk, vaikas-google

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 4, 2019
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
OldEventingProvisionerLabel: "provisioner-1",
},
shouldFail: false,
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add a test where actual has extraneous extra labels, to ensure we only return true when the expected ones are there.

{
			name: "all good",
			actual: map[string]string{
				EventingChannelLabel:        "channel-1",
				OldEventingChannelLabel:     "channel-1",
				EventingProvisionerLabel:    "provisioner-1",
				OldEventingProvisionerLabel: "provisioner-1",
				"extra-label-that-should-be-ignored": "foo",
			},
			expected: map[string]string{
				EventingChannelLabel:        "channel-1",
				OldEventingChannelLabel:     "channel-1",
				EventingProvisionerLabel:    "provisioner-1",
				OldEventingProvisionerLabel: "provisioner-1",
			},
			shouldFail: false,
		},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will add.

Comment thread pkg/provisioners/channel_util.go Outdated

// checkExpectedLabels checks the presence of expected labels and its values and return true
// if all labels are found.
func checkExpectedLabels(actual, expected map[string]string) bool {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we change the name to expectedLabelsPresent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure thing.

Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
@knative-metrics-robot
Copy link
Copy Markdown

The following is the coverage report on pkg/.
Say /test pull-knative-eventing-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/provisioners/channel_util.go 94.0% 94.9% 1.0

@Harwayne
Copy link
Copy Markdown
Contributor

Harwayne commented Jan 4, 2019

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 4, 2019
@knative-prow-robot knative-prow-robot merged commit 44f4bc3 into knative:master Jan 4, 2019
@sbezverk sbezverk deleted the labels branch January 4, 2019 19:02
@grantr
Copy link
Copy Markdown
Contributor

grantr commented Jan 4, 2019

/milestone v0.3

@knative-prow-robot
Copy link
Copy Markdown
Contributor

@grantr: The provided milestone is not valid for this repository. Milestones in this repository: [v0.2.2, v0.3.0]

Use /milestone clear to clear the milestone.

Details

In response to this:

/milestone v0.3

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.

@grantr
Copy link
Copy Markdown
Contributor

grantr commented Jan 4, 2019

/milestone v0.3.0

@knative-prow-robot knative-prow-robot added this to the v0.3.0 milestone Jan 4, 2019
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. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants