Skip to content
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

Merged
merged 1 commit into from
Aug 6, 2019

Conversation

spencerhance
Copy link
Contributor

Features are now defined with structs instead of nested maps

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 2, 2019
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 2, 2019
@rramkumar1
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 2, 2019
@spencerhance
Copy link
Contributor Author

/assign @bowei

}

// All of these fields must be filled in to allow L7ILBVersions() to work
var l7IlbVersions = ResourceVersions{
Copy link
Member

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 (
  ...
)

Copy link
Contributor Author

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 {
Copy link
Member

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
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove "Empty fields" etc

Copy link
Contributor Author

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 {
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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).

Copy link
Contributor Author

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{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewResourceVersions()

Copy link
Contributor Author

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{
Copy link
Member

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 ""

Copy link
Contributor Author

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.

@bowei
Copy link
Member

bowei commented Aug 6, 2019

Just a couple of things and this one is good for merging.

Features are now defined with structs instead of nested maps
@bowei
Copy link
Member

bowei commented Aug 6, 2019

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 6, 2019
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 6, 2019
@k8s-ci-robot k8s-ci-robot merged commit b193608 into kubernetes:master Aug 6, 2019
@spencerhance spencerhance deleted the refactor-lb-features branch August 6, 2019 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants