-
Notifications
You must be signed in to change notification settings - Fork 301
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 loadbalancer features #812
Refactor loadbalancer features #812
Conversation
Hi @spencerhance. 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. |
/ok-to-test |
/assign @bowei |
} | ||
|
||
// All of these fields must be filled in to allow L7ILBVersions() to work | ||
var l7IlbVersions = ResourceVersions{ |
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 can have a
var (
...
)
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
fs := sets.NewString(strings...) | ||
if fs.HasAny(resourceToVersionMap[resource][meta.VersionAlpha]...) { | ||
return meta.VersionAlpha | ||
func versionsFromFeatures(features []string) ResourceVersions { |
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.
It's probably easier to implement it like this:
func NewResourceVersions() *ResourceVersions {
return &ResourceVersions{ /* all verisonGA */ }
}
// Merge two resource versions together, returning a new one with the combined
// versions for each resource.
func (r *ResourceVersions) Merge(other *ResourceVersions) *ResourceVersions {
return &ResourceVersions{
UrlMap: mergeVersions(r.UrlMap, other.UrlMap),
...
}
}
func mergeVersions(a, b meta.Version) meta.Version {
if versionOrdinal(a) < versionOrdinal(b) {
return b
}
return a
}
func versionOrdinal(v meta.Version) int {
switch v {
case meta.VersionAlpha: return 2
case meta.VersionBeta: return 1
}
return 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.
Done
b9e070d
to
121b5e2
Compare
TargetHttpsProxy LBResource = "TargetHttpsProxy" | ||
SslCertificate LBResource = "SslCertificate" | ||
// ResourceVersions allows you to define all the versions required for each resource | ||
// for a feature. Empty fields are considered equivalent to meta.VersionGA |
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.
remove "Empty fields" etc
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
return meta.VersionAlpha | ||
func versionsFromFeatures(features []string) *ResourceVersions { | ||
result := NewResourceVersions() | ||
if len(features) == 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.
if is not needed i think
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
return 0 | ||
} | ||
|
||
// Figure out the correct version |
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.
// mergeVersions returns the newer API (e.g. mergeVersions(alpha, GA) = alpha).
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
}{ | ||
{ | ||
desc: "No Features", | ||
versionMap: map[LBResource]meta.Version{ | ||
expected: &ResourceVersions{ |
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.
NewResourceVersions()
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
}, | ||
}, | ||
{ | ||
desc: "Differing versions", | ||
features: []string{fakeGaFeature, fakeAlphaFeatureUrlMapOnly}, | ||
versionMap: map[LBResource]meta.Version{ | ||
expected: &ResourceVersions{ |
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 can do this neat one-liner:
NewResourceVersions().Merge(&ResourceVersions{UrlMap:meta.VersionAlpha})
if we change versionOrdinal to return -1 for ""
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. Also I realized how much I miss one-liners from the python world.
Just a couple of things and this one is good for merging. |
121b5e2
to
a18d97f
Compare
Features are now defined with structs instead of nested maps
a18d97f
to
ad7abb9
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bowei, spencerhance 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 |
Features are now defined with structs instead of nested maps