Consistent labels for channel and provisioner#698
Conversation
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
|
/assign @vaikas-google |
|
@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. |
|
Thanks @sbezverk! Seems like the label keys could be constants in the |
|
@grantr ok make sense and it looks like provisioners package gets imported in some tests. |
|
We have to be careful with how we do this, it will cause duplicate
|
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
|
@vaikas-google @Harwayne what about preserving old labels and add new set of labels and then at one point deprecate old labels? |
|
Yep that seems like the right approach. For N releases we'll have both label styles applied. |
|
That might work but I defer to @Harwayne because I thought there were some corner cases here. |
Yes, that is the general idea. I think the procedure is:
|
|
@Harwayne WRT point 1 of your comment. Based on the code and updated new |
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
You are correct that 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 |
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
Harwayne
left a comment
There was a problem hiding this comment.
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.
|
|
||
| // 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 { |
There was a problem hiding this comment.
I believe this is equivalent to equality.Semantic.DeepDerivative(expected, actual).
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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.
| } | ||
| // Second add all missing expected labels | ||
| for k, v := range expected { | ||
| if va, ok := consolidated[k]; ok { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
yep, you are right, thanks for catching it.
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
|
/approve |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
| OldEventingProvisionerLabel: "provisioner-1", | ||
| }, | ||
| shouldFail: false, | ||
| }, |
There was a problem hiding this comment.
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,
},|
|
||
| // 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 { |
There was a problem hiding this comment.
Can we change the name to expectedLabelsPresent?
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
|
The following is the coverage report on pkg/.
|
|
/lgtm |
|
/milestone v0.3 |
|
@grantr: The provided milestone is not valid for this repository. Milestones in this repository: [ Use DetailsIn response to this:
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. |
|
/milestone v0.3.0 |
Signed-off-by: Serguei Bezverkhi sbezverk@cisco.com
Fixes #690