-
Notifications
You must be signed in to change notification settings - Fork 91
Ms/validate sec groups #4269
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
base: main
Are you sure you want to change the base?
Ms/validate sec groups #4269
Conversation
controllers/webhooks/networking/security_groups/validator_test.go
Outdated
Show resolved
Hide resolved
8fbe095 to
fa724b3
Compare
danail-branekov
left a 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.
I have added minor style comments. However, I believe we need tests for the new logic in the validator
| for i, rule := range rules { | ||
| if err := validateRuleDestination(rule.Destination); err != nil { | ||
| return fmt.Errorf("rules[%d]: %w", i, err) | ||
| if strings.Contains(rule.Destination, ",") { |
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.
You do not need to check whether the string contains a comma or not, SplitSeq would return an iterator with a single element if not, or an iterator with multiple elements if so.
Consider the following example:
func main() {
stringWithoutComma := "foo"
stringWithComma := "bar,baz"
fmt.Printf("slices.Collect(strings.SplitSeq(stringWithoutComma, \",\")) = %+v\n", slices.Collect(strings.SplitSeq(stringWithoutComma, ",")))
fmt.Printf("slices.Collect(strings.SplitSeq(stringWitComma, \",\")) = %+v\n", slices.Collect(strings.SplitSeq(stringWithComma, ",")))
}
it produces
slices.Collect(strings.SplitSeq(stringWithoutComma, ",")) = [foo]
slices.Collect(strings.SplitSeq(stringWitComma, ",")) = [bar baz]
Having said that, you could iterate over the iterator directly, it does not make a difference whether the string contains commas or not
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 fixed that but Copilot is telling me, that this is buggy and I should just use strings.Split. What do you think - it could be wrong of course...
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.
My initial thought was to use strings.Split but as you used SplitSeq I thought it should be all right. Maybe strings.Split would be simpler.
Out of curiosity, why does copilot think it is buggy?
|
I added some more tests |
Is there a related GitHub Issue?
#4103
What is this change about?
Updating and enhancing the existing Validator for Security Groups
Does this PR introduce a breaking change?
It should not as Security Groups are not supported, yet.
Acceptance Steps
create sec-group.json:
E.g.:
then create them:
cf curl -X POST "/v3/security_groups" [email protected]
Tag your pair, your PM, and/or team
@danail-branekov, @georgethebeatle