-
Notifications
You must be signed in to change notification settings - Fork 455
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
Enhance Ensure_
functions from extensions/pkg/webhook
package
#9007
Conversation
9a1a368
to
aff5acd
Compare
/cc @dimityrmirchev |
/assign |
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.
I left some initial comments. Overall there are a lot of breaking changes that I think we should not introduce.
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.
Thanks for the PR
We can simplify few functions to make it more readable.
580b651
to
5628ab5
Compare
Two last notes from my side, other looks good:
|
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.
Cosmetic suggestions, otherwise lgtm
Please:
- Use the imperative, present tense for commit/PR messages:
Enhance `Ensure*` functions from `extensions/pkg/webhook` package
- Improve the release note by enumerating which funcs have the changed behaviour (instead of the used EnsureNo_ thingy) and by adding a release note for the removed func (StringIndex).
extensions/pkg/webhook/utils_test.go
Outdated
"--prefix1=key1=value1,key2=value2,key3=value3", | ||
"--prefix2=key4=value4,key5=value5,key6=value6", | ||
"--prefix1=key7=value7,key8=value8,key9=value9", |
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.
A more real-world example (which is the motivation for #8296) would be:
"--prefix1=key1=value1,key2=value2,key3=value3", | |
"--prefix2=key4=value4,key5=value5,key6=value6", | |
"--prefix1=key7=value7,key8=value8,key9=value9", | |
flags = []string{ | |
"--prefix1-flag1=value1", | |
"--flag2=value2", | |
"--prefix1-flag3=value3", | |
} |
Idk why you put many key-value pairs as flag values. In the common case, flag supports a single value. You could make your flags everywhere single-value ones to make the tests easier to read.
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.
Thanks for the better real-world test. The problem is that for EnsureNoStringWithPrefixContains
and EnsureStringWithPrefixContains
without a breaking change these scenarios can't be covered. We can:
- Cover these cases by introducing breaking change to the implementation of
EnsureNoStringWithPrefixContains
andEnsureStringWithPrefixContains
- Leave those cases and cover only
--prefix1=value1,value3
--prefix2=value2
--prefix1=value1,value4
by result := webhook.EnsureStringWithPrefixContains(flags, "--prefix1=", "value1", ",")
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.
What is exactly the problem with these funcs?
They seem to behave as expected according to my testing:
diff --git a/extensions/pkg/webhook/utils_test.go b/extensions/pkg/webhook/utils_test.go
index 37d8f0b80..59d72234b 100644
--- a/extensions/pkg/webhook/utils_test.go
+++ b/extensions/pkg/webhook/utils_test.go
@@ -501,24 +501,24 @@ var _ = Describe("Utils", func() {
BeforeEach(func() {
flags = []string{
- "--flag1=key1=value1,key2=value2,key3=value3",
- "--flag2=key4=value4,key5=value5,key6=value6",
- "--flag1=key7=value7,key8=value8,key9=value9",
+ "--prefix1-flag1=value1",
+ "--flag2=value2",
+ "--prefix1-flag3=value3",
}
})
It("should ensure the specified key-value pair is in all flags with a given prefix", func() {
- result := webhook.EnsureStringWithPrefixContains(flags, "--flag1=", "key3=value3", ",")
+ result := webhook.EnsureStringWithPrefixContains(flags, "--prefix1", "value4", ",")
Expect(result).To(Equal([]string{
- "--flag1=key1=value1,key2=value2,key3=value3",
- "--flag2=key4=value4,key5=value5,key6=value6",
- "--flag1=key7=value7,key8=value8,key9=value9,key3=value3",
+ "--prefix1-flag1=value1,value4",
+ "--flag2=value2",
+ "--prefix1-flag3=value3,value4",
}))
})
It("should add a new flag with the specified key-value pair if no flag with the given prefix exists", func() {
- result := webhook.EnsureStringWithPrefixContains(flags, "--flag3=", "key10=value10", ",")
- Expect(result).To(Equal(append(flags, "--flag3=key10=value10")))
+ result := webhook.EnsureStringWithPrefixContains(flags, "--flag3=", "value4", ",")
+ Expect(result).To(Equal(append(flags, "--flag3=value4")))
})
})
})
@@ -663,18 +663,18 @@ var _ = Describe("Utils", func() {
BeforeEach(func() {
flags = []string{
- "--prefix1=key1=value1,key2=value2,key3=value3",
- "--prefix2=key4=value4,key5=value5,key6=value6",
- "--prefix1=key7=value7,key8=value8,key9=value9",
+ "--prefix1-flag1=value1,value2",
+ "--flag2=value2",
+ "--prefix1-flag3=value3",
}
})
It("should delete the specified key-value pair from all flags with a given prefix", func() {
- result := webhook.EnsureNoStringWithPrefixContains(flags, "--prefix1=", "key2=value2", ",")
+ result := webhook.EnsureNoStringWithPrefixContains(flags, "--prefix1", "value2", ",")
Expect(result).To(Equal([]string{
- "--prefix1=key1=value1,key3=value3",
- "--prefix2=key4=value4,key5=value5,key6=value6",
- "--prefix1=key7=value7,key8=value8,key9=value9",
+ "--prefix1-flag1=value1",
+ "--flag2=value2",
+ "--prefix1-flag3=value3",
}))
})
})
Am I missing something?
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.
Currently those incorrect tests pass:
It("should ensure the specified key-value pair is in all flags with a given prefix", func() {
result := webhook.EnsureStringWithPrefixContains(flags, "--prefix1", "value1", ",")
Expect(result).To(Equal([]string{
"--prefix1-flag1=value1,value1",
"--flag2=value2",
"--prefix1-flag3=value3,value1",
}))
})
It("should ensure the specified key-value pair is in all flags with a given prefix", func() {
result := webhook.EnsureStringWithPrefixContains(flags, "--prefix1", "-flag1=value1", ",")
Expect(result).To(Equal([]string{
"--prefix1-flag1=value1",
"--flag2=value2",
"--prefix1-flag3=value3,-flag1=value1",
}))
})
Because of this logic on line 150
values := strings.Split(strings.TrimPrefix(items[i], prefix), sep)
in these tests values
is respectively:
["-flag1=value1"]
skipped because not prefixed with --prefix1
["-flag3=value3"]
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.
I see. Then let's add tests for the flag prefix only to the funcs that support it. As shared above, such flags with common prefixes are the motivation for the issue this PR is fixing, hence it would be nice to cover these scenarios with unit tests. You init the flags in BeforeEach for every Describe, hence we could have different flags (with and without prefixes) for the different Describes.
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 had a call with @Kostov6 and we agreed to:
- Add a doc string to
EnsureStringWithPrefixContains
that it does not support cases where a flag prefix (not the whole flag) is passed - Adapt the tests for
EnsureNoStringWithPrefix
to include a test case for deletion by flag prefix - Randomize the used flags as test data - as shared above, right now we only have flags that have key-value pairs as flag value. Instead, let's have flags with single value, multiple values and key-value pairs.
Ensure_
functions from extensions/pkg/webhook
packageEnsure_
functions from extensions/pkg/webhook
package
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.
/lgtm
LGTM label has been added. Git tree hash: 73413987a0a094f06ed3db78626b7e6906a70a3a
|
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.
Minors Nits, otherwise lgtm !
The Gardener project currently lacks enough active contributors to adequately respond to all PRs.
You can:
/lifecycle stale |
/remove-lifecycle stale |
4d4ab4b
to
9afe6b9
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.
Minor suggestions otherwise lgtm
@Kostov6: The following test failed, say
Full PR test history. Your PR dashboard. Command help for this repository. 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. |
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.
/lgtm
LGTM label has been added. Git tree hash: 43fbf52f4d43cfb43ae1c17bd3d19349b045e477
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ialidzhikov 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 |
How to categorize this PR?
/area quality
/kind enhancement
What this PR does / why we need it:
EnsureNo_
,EnsureStringWithPrefix
,EnsureStringWithPrefixContains
act on all matchesextensions/pkg/webhook
usingslices
libraryEnsure_
functionsWhich issue(s) this PR fixes:
Fixes #8296
Special notes for your reviewer:
Release note: