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

Merge rules per ingress by the same host, pathType and backend service #2986

Closed
wants to merge 3 commits into from

Conversation

oliviassss
Copy link
Collaborator

@oliviassss oliviassss commented Jan 20, 2023

Issue

#2203
#2678

Description

Merged the rules per ingress if:

  • they are routing to the same services, and
  • they have the same host, and
  • they are of the same pathType

Tests

  • Added unit tests
  • Created Ingress with multiple rules, verified that paths were merged only when they have the same host, pathType and backend service. Also verified that when the count of the condition values exceed 5, the merged paths will flow over to a new rule in order to fulfill the current quota limit for rules.

Checklist

  • Added tests that cover your change (if possible)
  • Added/modified documentation as required (such as the README.md, or the docs directory)
  • Manually tested
  • Made sure the title of the PR is a good description that can go into the release notes

BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯

  • Backfilled missing tests for code in same general area 🎉
  • Refactored something and made the world a better place 🌟

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 20, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @oliviassss. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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 the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jan 20, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: oliviassss
Once this PR has been reviewed and has the lgtm label, please assign kishorj for approval by writing /assign @kishorj in a comment. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@oliviassss oliviassss changed the title Merge rules per ingress bt the same host, pathType and backend service Merge rules per ingress by the same host, pathType and backend service Jan 20, 2023
@codecov-commenter
Copy link

Codecov Report

Base: 54.09% // Head: 53.91% // Decreases project coverage by -0.18% ⚠️

Coverage data is based on head (33674b3) compared to base (3a98bf0).
Patch coverage: 50.31% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2986      +/-   ##
==========================================
- Coverage   54.09%   53.91%   -0.18%     
==========================================
  Files         144      145       +1     
  Lines        8291     8422     +131     
==========================================
+ Hits         4485     4541      +56     
- Misses       3479     3546      +67     
- Partials      327      335       +8     
Impacted Files Coverage Δ
pkg/algorithm/integers.go 0.00% <0.00%> (ø)
pkg/ingress/model_build_listener_rules.go 49.34% <51.28%> (-3.32%) ⬇️
pkg/deploy/elbv2/target_group_synthesizer.go 51.04% <0.00%> (-2.15%) ⬇️
pkg/service/model_build_target_group.go 85.67% <0.00%> (-0.30%) ⬇️
pkg/deploy/stack_deployer.go 0.00% <0.00%> (ø)
pkg/service/model_builder.go 88.17% <0.00%> (+0.12%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@johngmyers johngmyers left a comment

Choose a reason for hiding this comment

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

Is there a big advantage to having a separate code path for unmerged listener rules? It seems like a lot of complexity and I worry about test coverage.

@@ -3,40 +3,116 @@ package ingress
import (
"context"
"fmt"
"sigs.k8s.io/aws-load-balancer-controller/pkg/k8s"
"sigs.k8s.io/aws-load-balancer-controller/pkg/model/core"
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use goimports sorting style

Comment on lines 17 to 20
//func (t *defaultModelBuildTask) buildListenerRules(ctx context.Context, lsARN core.StringToken, port int64, protocol elbv2model.Protocol, ingList []ClassifiedIngress) error {
// if t.sslRedirectConfig != nil && protocol == elbv2model.ProtocolHTTP {
// return nil
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

Please edit this out of the commit.

// e.g. {(hostA, pathTypeA, serviceNameA, PortNumberA): [path1, path2,...],
// (hostB, pathTypeB, serviceNameB, PortNumberB): [path3, path4,...],
// ...}
mergeRefMap := make(map[[4]string][]networking.HTTPIngressPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a struct instead of a [4]string as the map key

// ...}
mergeRefMap := make(map[[4]string][]networking.HTTPIngressPath)
// pathToRuleMap stores {path: ruleIdx} relationship
pathToRuleMap := make(map[networking.HTTPIngressPath]int)
Copy link
Contributor

Choose a reason for hiding this comment

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

pathToRuleIndexMap?

}
host := rule.Host
for _, path := range rule.HTTP.Paths {
//if path.PathType != nil && (*path.PathType != networking.PathTypePrefix ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Please edit out of the commit. It's hard to review with commented-out code.

@@ -119,20 +243,83 @@ func (t *defaultModelBuildTask) classifyIngressPathsByType(paths []networking.HT
return exactPaths, prefixPaths, implementationSpecificPaths, nil
}

func (t *defaultModelBuildTask) buildRuleConditions(ctx context.Context, rule networking.IngressRule,
path networking.HTTPIngressPath, backend EnhancedBackend) ([]elbv2model.RuleCondition, error) {
// func (t *defaultModelBuildTask) buildRuleConditions(ctx context.Context, rule networking.IngressRule,
Copy link
Contributor

Choose a reason for hiding this comment

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

Edit this commented-out block from the commit

minIdx := pathToRuleMap[mergedPaths[0]]
for _, path := range mergedPaths {
currIdx := pathToRuleMap[path]
minIdx = algorithm.GetMin(minIdx, currIdx)
Copy link
Contributor

Choose a reason for hiding this comment

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

The Go way is to just inline this.

// use a map to help merge rules by host, pathType and service
// getRulesToMerge classifies rules into two categories - rules with unique host, rules with replicate hosts
// only rules with replicate hosts need merge
func (t *defaultModelBuildTask) getRulesToMerge(rules []networking.IngressRule) ([]networking.IngressRule, []networking.IngressRule, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps name the return values?

Comment on lines +164 to +169
_, exists := hostToRulesMap[host]
if exists {
hostToRulesMap[host] = append(hostToRulesMap[host], rule)
} else {
hostToRulesMap[host] = []networking.IngressRule{rule}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

hostToRulesMap[host] = append(hostToRulesMap[host], rule)

// getRulesToMerge classifies rules into two categories - rules with unique host, rules with replicate hosts
// only rules with replicate hosts need merge
func (t *defaultModelBuildTask) getRulesToMerge(rules []networking.IngressRule) ([]networking.IngressRule, []networking.IngressRule, error) {
var rulesWithReplicateHosts []networking.IngressRule
Copy link
Contributor

Choose a reason for hiding this comment

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

rulesWithReplicatedHosts

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 24, 2023
@oliviassss oliviassss closed this May 10, 2023
@johngmyers johngmyers mentioned this pull request Aug 23, 2023
12 tasks
@oliviassss oliviassss deleted the merge-rules branch January 3, 2024 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants