-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Refactor k8s rule type annotation parsing/retrieval. #1151
Refactor k8s rule type annotation parsing/retrieval. #1151
Conversation
dd29713
to
69315de
Compare
@emilevauge @errm This is the referenced, original PR trimmed done to the refactoring parts as announced. Could you please take a look? Thanks! |
provider/kubernetes_test.go
Outdated
tests := []struct { | ||
desc string | ||
ingressRuleType string | ||
serviceRuleType string |
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.
Just realized I forgot to remove this one. Will do so later.
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.
Done!
69315de
to
0d1eb9a
Compare
d36f4ce
to
1f5c33c
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.
LGTM 🐸
provider/kubernetes.go
Outdated
ruleType = "PathPrefix" | ||
if len(pa.Path) > 0 { | ||
ruleType, unknown := getRuleTypeFromAnnotation(i.Annotations) | ||
switch { |
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 may be a dumb question, but If you are not switching on a variable, should you still have a default in the event that neither of the cases are 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.
Not a dumb question at all!
I agree with you that there should usually be a default
case when you use a switch statement in an exhaustive way: Handle all acceptable inputs and do something for the unexpected case (like returning an error).
The other type of switch usage in Go is a more readable version of multiple / nested / complex if-else statements. This one doesn't necessarily need a default
case in my opinion, and it's the one I had in mind here.
Admittedly, I could have also written
if unknown {
log.Warnf("Unknown RuleType ...")
}
if ruleType == "" {
ruleType = ruleTypePathPrefix
}
I prefer the switch variant because I can use fallthrough
to shortcut right to setting a default value in case of an unknown rule type (fallthrough
ignores the condition of the following case expression) and don't need to depend onruleType
having a particular value (empty string here).
If you think that two if statements would be better, I'm happy to change.
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.
Nope. LGTM
1f5c33c
to
12d7904
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.
LGTM
@vdemeester @dtomcej okay to merge? |
@timoreimann I'm still not sure maintaining another rule (incomplete) list is a good idea. Rules are defined https://github.com/containous/traefik/blob/master/rules.go#L107 and again https://github.com/containous/traefik/pull/1151/files#diff-f9e99fb6bddb36d1640e40bc4bd36bc1R22 in |
@emilevauge I agree with you in general. However, the PR did not introduce any new rules: It's a refactoring (and test-extending) change only which IMHO already provides an incremental improvement over the previous state. Put in a different way, it still contains the same level of duplication but makes it more readable (agile, yay :-) ). My suggestion would be to move forward with this PR and follow-up with some de-duplication effort afterwards. That way, we don't conflate a fairly limited and simple refactoring with a bigger change that could possibly be more difficult to design and implement. |
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 👍
12d7904
to
f68e016
Compare
- Move annotation logic into function. - Constantify strings. - Refactor TestRuleType. - Add test for GetRuleTypeFromAnnotations.
f68e016
to
f3598e6
Compare
You're right, in my opinion, we shouldn't have accepted the previous state. |
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!
Carved out of #1129.