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
prow/plugin: Extends label plugin to use Unique Prefixes #26383
prow/plugin: Extends label plugin to use Unique Prefixes #26383
Conversation
Hi @RaghavRoy145. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the 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. |
/assign @nikhita |
/cc @MadhavJivrajani |
3c7dc01
to
af391b8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spoke with @RaghavRoy145 offline, left a few minor suggestions below. @nikhita could you weigh in on the below points as I may be lacking some context here:
- Is the intent of this change to be a mechanism that ensures unique prefixes or is the intent that a unique label that matches a given regex should exist?
- Because there might be cases where the user could provide non-prefix regexes
- And also there might be a few funny cases where a regex could match all labels and the implementation can remove all of them (providing safeguards probably isn't too difficult here tho).
- If we go with the former, can we drop regexes altogether and stick with
strings.HasPrefix
?- Similar concerns as above for
HasPrefix
, we would probably need a validate function for theLabel
plugin inconfig.go
that ensures that no item in theUniquePrefixes
list is an empty string (since""
is a prefix to everything).
- Similar concerns as above for
prow/plugins/config.go
Outdated
// UniquePrefixList is the list of label prefixes that can only exist | ||
// once per issue, | ||
UniquePrefixes []string `json:"unique_prefixes,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: UniquePrefixes
the field name is not the same as UniquePrefixList
which is mentioned in the comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should go with UniquePrefixes
since it sounds more canonical and fix the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the naming should be corrected in the test file as well.
prow/plugins/label/label.go
Outdated
Copyright 2016 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change isn't needed :D
prow/plugins/label/label.go
Outdated
prefixList := config.UniquePrefixes | ||
for _, prefix := range prefixList { | ||
for _, label := range labels { | ||
if matched, _ := regexp.MatchString(prefix, label.Name); matched { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably shouldn't ignore errors here. Errors would creep up in case the regex can't be Compile
d.
prow/plugins/label/label.go
Outdated
// The second check (labelSplit[0] == "priority") can be removed or extended in the future to generalise | ||
// the functionality of removing labels of the same class | ||
if len(labelSplit) == 2 && labelSplit[0] == "priority" { | ||
labelsMap[labelSplit[0]] = append(labelsMap[labelSplit[0]], labelSplit[1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this logic still needed? If I understand correctly, this change is meant for unique prefixes and not necessarily just priority labels.
prow/plugins/label/label.go
Outdated
uniqueLabelsMap := getExistingUniquePrefixlabels(config, labels) | ||
var labelsWithPrefixExist = false | ||
for prefix := range uniqueLabelsMap { | ||
if matched, _ := regexp.MatchString(prefix, labelToAdd); matched { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above regarding ignoring errors.
/ok-to-test |
/retest |
af391b8
to
0aa2a88
Compare
@MadhavJivrajani answering your questions from #26383 (review):
Neither. The intent is to follow something similar to the lifecycle label: test-infra/prow/plugins/lifecycle/lifecycle.go Lines 129 to 138 in 0cd7957
If a PR already has
I agree. Might be easier to deal with errors if we use @RaghavRoy145 the PR body was empty. I have edited the PR body to point to the issue that this PR is resolving. Can you also add more content to the PR body with details on why/what this PR is doing? Please also include these details in the commit message. |
Thanks Nikhita!
That’s my bad, I should’ve been clearer. I agree with your point! I meant unique prefixes as a mechanism to decide if something with that prefix exists (for ex priority/) and if it does, remove it and add the one that’s commented (like you said). This is probably for another PR, but if we do end up doing a generic mechanism to implement the above (I.e. not just restrict to priority or lifecycle labels), we could have the opportunity to maybe reuse this for the lifecycle label logic as well. |
0aa2a88
to
0ccef3b
Compare
0ccef3b
to
471cd8e
Compare
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
This commit takes care of label prefixes that can only exist once per issue. This is done by using a list of unique prefixes to create a map that maps these prefixes to existing labels that match the prefix. When a new label is needed to be added that matches a unique prefix, the pre-existing labels in this map that match the same prefix are removed and then the new label is added. Signed-off-by: Raghav Roy <raghavroy145@gmail.com>
471cd8e
to
37b977f
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: RaghavRoy145 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hey @MadhavJivrajani |
/remove-lifecycle stale |
@@ -1077,6 +1080,15 @@ func (c *Configuration) ValidatePluginsUnknown() error { | |||
return utilerrors.NewAggregate(errors) | |||
} | |||
|
|||
func validateUniquePrefixes(uniquePrefixes []string) error { | |||
for _, prefix := range uniquePrefixes { | |||
if len(prefix) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also look for duplicates, and perhaps also for one prefix being a prefix of another (foo
and foobar
eg) to avoid interaction between different prefixes
if tC.isErrorNil && err != nil { | ||
t.Errorf("expected nil error got %s", err) | ||
} else if !tC.isErrorNil && err == nil { | ||
t.Errorf("expected non nil error, got nil") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we test for full error like the test above?
test-infra/prow/plugins/config_test.go
Lines 101 to 103 in 37b977f
if !reflect.DeepEqual(err, test.expectedErr) { | |
t.Errorf("unexpected error: %v, expected: %v", err, test.expectedErr) | |
} |
for prefix := range uniqueLabelsMap { | ||
if matched := strings.HasPrefix(labelToAdd, prefix); matched { | ||
labelPrefix = prefix | ||
labelsWithPrefixExist = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need an additional variable, we can just reset labelPrefix
in each iteration and use labelPrefix != ""
as a check
if labelsWithPrefixExist { | ||
for _, label := range uniqueLabelsMap[labelPrefix] { | ||
if label != labelToAdd && github.HasLabel(label, labels) { | ||
if err := gc.RemoveLabel(org, repo, e.Number, label); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ability to remote a labelj can be behind a permission (see L279), so we need to test whether the user is able to remove the label (and handle that situation well, as ignoring that condition would lead to a duplicate label on the issue/pr)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @petr-muller thanks for reviewing this!
I wanted some clarification on this comment.
L235 already has the check which checks user permissions (which when fails, does not enter the de-duplication logic that I have added, and you have pointed to).
I'm not sure how this can lead to duplicate labels?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L235 checks for the permission to add the new label, but your L258 removes a different label, which the user may not have a permission to remove. Imagine this:
- Prow is configured to restrict
priority/urgent
to senior engineers - Prow is configured to only allow one label with
priority/
prefix - PR has
priority/urgent
- Non-senior engineer labels the PR with
priority/low
Your code would remove the priority/urgent
(which the user has no permission to remove normally). If you fix this simply by denying the removal but allow adding priority/low
then you have duplicate labels.
PR needs rebase. 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. |
@RaghavRoy145: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. I understand the commands that are listed here. |
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /close |
@k8s-triage-robot: Closed this PR. In 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. |
Ref: #6095
This commit takes care of label prefixes that can only exist once per issue. This is done by using a list of unique prefixes to create a map that maps these prefixes to existing labels that match the prefix. When a new label is needed to be added that matches a unique prefix, the pre-existing labels in this map that match the same prefix are removed and then the new label is added.