Skip to content

Commit

Permalink
Merge pull request #670 from frobware/4.8-manual-backport-pr663
Browse files Browse the repository at this point in the history
[release-4.8] Bug 2017708: Change default balancing algorithm to "leastconn"
  • Loading branch information
openshift-merge-robot committed Oct 28, 2021
2 parents 3257f07 + b1a5040 commit cb61412
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
19 changes: 12 additions & 7 deletions pkg/operator/controller/ingress/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,19 @@ func desiredRouterDeployment(ci *operatorv1.IngressController, ingressController
}
}

// For non-TLS, edge-terminated, and reencrypt routes, use the "random"
// balancing algorithm by default, but allow an unsupported config
// override to override it. For passthrough routes, use the "source"
// balancing algorithm in order to provide some session-affinity.
loadBalancingAlgorithm := "random"
// For non-TLS, edge-terminated, and reencrypt routes, use the
// "leastconn" balancing algorithm by default, but allow an unsupported
// config override to override it. For passthrough routes, use the
// "source" balancing algorithm in order to provide some
// session-affinity. This code at one time used "random" as the default
// for non-passthrough routes, but we changed it to "leastconn" upon
// discovering that "random" incurs significant memory overhead for each
// backend that uses it. See
// <https://bugzilla.redhat.com/show_bug.cgi?id=2007581>.
loadBalancingAlgorithm := "leastconn"
switch unsupportedConfigOverrides.LoadBalancingAlgorithm {
case "leastconn":
loadBalancingAlgorithm = "leastconn"
case "random":
loadBalancingAlgorithm = "random"
}
env = append(env, corev1.EnvVar{
Name: RouterLoadBalancingAlgorithmEnvName,
Expand Down
10 changes: 5 additions & 5 deletions pkg/operator/controller/ingress/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func TestDesiredRouterDeployment(t *testing.T) {
deployment.Spec.Template.Spec.Tolerations)
}

checkDeploymentHasEnvVar(t, deployment, "ROUTER_LOAD_BALANCE_ALGORITHM", true, "random")
checkDeploymentHasEnvVar(t, deployment, "ROUTER_LOAD_BALANCE_ALGORITHM", true, "leastconn")
checkDeploymentHasEnvVar(t, deployment, "ROUTER_TCP_BALANCE_SCHEME", true, "source")

checkDeploymentHasEnvVar(t, deployment, "ROUTER_USE_PROXY_PROTOCOL", false, "")
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestDesiredRouterDeployment(t *testing.T) {
var expectedReplicas int32 = 8
ci.Spec.Replicas = &expectedReplicas
ci.Spec.UnsupportedConfigOverrides = runtime.RawExtension{
Raw: []byte(`{"loadBalancingAlgorithm":"leastconn"}`),
Raw: []byte(`{"loadBalancingAlgorithm":"random","dynamicConfigManager":"false","maxConnections":-1,"reloadInterval":15}`),
}
ci.Status.Domain = "example.com"
ci.Status.EndpointPublishingStrategy.Type = operatorv1.LoadBalancerServiceStrategyType
Expand Down Expand Up @@ -378,7 +378,7 @@ func TestDesiredRouterDeployment(t *testing.T) {
t.Errorf("expected empty startup probe host, got %q", deployment.Spec.Template.Spec.Containers[0].StartupProbe.Handler.HTTPGet.Host)
}

checkDeploymentHasEnvVar(t, deployment, "ROUTER_LOAD_BALANCE_ALGORITHM", true, "leastconn")
checkDeploymentHasEnvVar(t, deployment, "ROUTER_LOAD_BALANCE_ALGORITHM", true, "random")
checkDeploymentHasEnvVar(t, deployment, "ROUTER_TCP_BALANCE_SCHEME", true, "source")

checkDeploymentHasEnvVar(t, deployment, "ROUTER_USE_PROXY_PROTOCOL", true, "true")
Expand Down Expand Up @@ -411,7 +411,7 @@ func TestDesiredRouterDeployment(t *testing.T) {

checkDeploymentHasEnvVar(t, deployment, "ROUTER_IP_V4_V6_MODE", true, "v4v6")

// Any value for loadBalancingAlgorithm other than "leastconn" should be
// Any value for loadBalancingAlgorithm other than "random" should be
// ignored.
ci.Spec.UnsupportedConfigOverrides = runtime.RawExtension{
Raw: []byte(`{"loadBalancingAlgorithm":"source"}`),
Expand Down Expand Up @@ -448,7 +448,7 @@ func TestDesiredRouterDeployment(t *testing.T) {
t.Errorf("expected empty startup probe host, got %q", deployment.Spec.Template.Spec.Containers[0].StartupProbe.Handler.HTTPGet.Host)
}

checkDeploymentHasEnvVar(t, deployment, "ROUTER_LOAD_BALANCE_ALGORITHM", true, "random")
checkDeploymentHasEnvVar(t, deployment, "ROUTER_LOAD_BALANCE_ALGORITHM", true, "leastconn")
checkDeploymentHasEnvVar(t, deployment, "ROUTER_TCP_BALANCE_SCHEME", true, "source")

checkDeploymentDoesNotHaveEnvVar(t, deployment, "ROUTER_USE_PROXY_PROTOCOL")
Expand Down
24 changes: 16 additions & 8 deletions test/e2e/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1938,9 +1938,11 @@ func TestUniqueIdHeader(t *testing.T) {
}

// TestLoadBalancingAlgorithmUnsupportedConfigOverride verifies that the
// operator configures router pod replicas to use the "leastconn" load-balancing
// algorithm if the ingresscontroller is so configured using an unsupported
// config override.
// operator configures router pod replicas to use the "random" load-balancing
// algorithm for non-passthrough routes if the ingresscontroller is so
// configured using an unsupported config override. The test also verifies that
// the operator always configures router pod replicas to use the "source"
// algorithm for passthrough routes irrespective of the override.
func TestLoadBalancingAlgorithmUnsupportedConfigOverride(t *testing.T) {
icName := types.NamespacedName{Namespace: operatorNamespace, Name: "leastconn"}
domain := icName.Name + "." + dnsConfig.Spec.BaseDomain
Expand All @@ -1961,20 +1963,26 @@ func TestLoadBalancingAlgorithmUnsupportedConfigOverride(t *testing.T) {
if err := kclient.Get(context.TODO(), controller.RouterDeploymentName(ic), deployment); err != nil {
t.Fatalf("failed to get ingresscontroller deployment: %v", err)
}
expectedAlgorithm := "random"
expectedAlgorithm := "leastconn"
if err := waitForDeploymentEnvVar(t, kclient, deployment, 30*time.Second, "ROUTER_LOAD_BALANCE_ALGORITHM", expectedAlgorithm); err != nil {
t.Fatalf("expected initial deployment to use the %q algorithm: %v", expectedAlgorithm, err)
t.Fatalf("expected initial deployment to have ROUTER_LOAD_BALANCE_ALGORITHM=%s: %v", expectedAlgorithm, err)
}
if err := waitForDeploymentEnvVar(t, kclient, deployment, 30*time.Second, "ROUTER_TCP_BALANCE_SCHEME", "source"); err != nil {
t.Fatalf("expected initial deployment to have ROUTER_TCP_BALANCE_SCHEME=source: %v", err)
}

ic.Spec.UnsupportedConfigOverrides = runtime.RawExtension{
Raw: []byte(`{"loadBalancingAlgorithm":"leastconn"}`),
Raw: []byte(`{"loadBalancingAlgorithm":"random"}`),
}
if err := kclient.Update(context.TODO(), ic); err != nil {
t.Fatalf("failed to update ingresscontroller: %v", err)
}
expectedAlgorithm = "leastconn"
expectedAlgorithm = "random"
if err := waitForDeploymentEnvVar(t, kclient, deployment, 1*time.Minute, "ROUTER_LOAD_BALANCE_ALGORITHM", expectedAlgorithm); err != nil {
t.Fatalf("expected updated deployment to use the %q algorithm: %v", expectedAlgorithm, err)
t.Fatalf("expected updated deployment to have ROUTER_LOAD_BALANCE_ALGORITHM=%s: %v", expectedAlgorithm, err)
}
if err := waitForDeploymentEnvVar(t, kclient, deployment, 30*time.Second, "ROUTER_TCP_BALANCE_SCHEME", "source"); err != nil {
t.Fatalf("expected updated deployment to have ROUTER_TCP_BALANCE_SCHEME=source: %v", err)
}
}

Expand Down

0 comments on commit cb61412

Please sign in to comment.