From 4a2322fb8408035935e0c543d9e671c57a349b1b Mon Sep 17 00:00:00 2001 From: Miciah Masters Date: Thu, 26 Aug 2021 13:13:09 -0400 Subject: [PATCH] Configure router to use "source" for passthrough Configure OpenShift router to use the "source" balancing algorithm for passthrough routes in order to provide some session-affinity. This was the behavior for passthrough routes before OpenShift 4.8, and changing it was unintentional. Follow-up to commit e83b057c6b5e18341cad743a056795ba255bc3cf. This commit fixes bug 1997407. https://bugzilla.redhat.com/show_bug.cgi?id=1997407 * pkg/operator/controller/ingress/deployment.go (RouterTCPLoadBalancingAlgorithmEnvName): New const for the "ROUTER_TCP_BALANCE_SCHEME" environment variable. (desiredRouterDeployment): Set ROUTER_TCP_BALANCE_SCHEME to "source". * pkg/operator/controller/ingress/deployment_test.go (TestDesiredRouterDeployment): Verify that desiredRouterDeployment sets ROUTER_TCP_BALANCE_SCHEME appropriately. --- pkg/operator/controller/ingress/deployment.go | 10 +++++++++- pkg/operator/controller/ingress/deployment_test.go | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/operator/controller/ingress/deployment.go b/pkg/operator/controller/ingress/deployment.go index 4306f64c8..37931efe5 100644 --- a/pkg/operator/controller/ingress/deployment.go +++ b/pkg/operator/controller/ingress/deployment.go @@ -60,7 +60,8 @@ const ( RouterHeaderBufferSize = "ROUTER_BUF_SIZE" RouterHeaderBufferMaxRewriteSize = "ROUTER_MAX_REWRITE_SIZE" - RouterLoadBalancingAlgorithmEnvName = "ROUTER_LOAD_BALANCE_ALGORITHM" + RouterLoadBalancingAlgorithmEnvName = "ROUTER_LOAD_BALANCE_ALGORITHM" + RouterTCPLoadBalancingAlgorithmEnvName = "ROUTER_TCP_BALANCE_SCHEME" RouterMaxConnectionsEnvName = "ROUTER_MAX_CONNECTIONS" @@ -467,6 +468,10 @@ 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" switch unsupportedConfigOverrides.LoadBalancingAlgorithm { case "leastconn": @@ -475,6 +480,9 @@ func desiredRouterDeployment(ci *operatorv1.IngressController, ingressController env = append(env, corev1.EnvVar{ Name: RouterLoadBalancingAlgorithmEnvName, Value: loadBalancingAlgorithm, + }, corev1.EnvVar{ + Name: RouterTCPLoadBalancingAlgorithmEnvName, + Value: "source", }) switch v := unsupportedConfigOverrides.MaxConnections; { diff --git a/pkg/operator/controller/ingress/deployment_test.go b/pkg/operator/controller/ingress/deployment_test.go index 6e8ddbb9a..d3c74ed62 100644 --- a/pkg/operator/controller/ingress/deployment_test.go +++ b/pkg/operator/controller/ingress/deployment_test.go @@ -221,6 +221,7 @@ func TestDesiredRouterDeployment(t *testing.T) { checkDeploymentHasEnvVar(t, deployment, "ROUTER_HAPROXY_CONFIG_MANAGER", false, "") checkDeploymentHasEnvVar(t, deployment, "ROUTER_LOAD_BALANCE_ALGORITHM", true, "random") + checkDeploymentHasEnvVar(t, deployment, "ROUTER_TCP_BALANCE_SCHEME", true, "source") checkDeploymentDoesNotHaveEnvVar(t, deployment, "ROUTER_ERRORFILE_503") checkDeploymentDoesNotHaveEnvVar(t, deployment, "ROUTER_ERRORFILE_404") @@ -414,6 +415,7 @@ func TestDesiredRouterDeployment(t *testing.T) { checkDeploymentHasEnvVar(t, deployment, "ROUTER_HAPROXY_CONFIG_MANAGER", false, "") checkDeploymentHasEnvVar(t, deployment, "ROUTER_LOAD_BALANCE_ALGORITHM", true, "leastconn") + checkDeploymentHasEnvVar(t, deployment, "ROUTER_TCP_BALANCE_SCHEME", true, "source") if len(deployment.Spec.Template.Spec.Containers[0].VolumeMounts) <= 4 || deployment.Spec.Template.Spec.Containers[0].VolumeMounts[4].Name != "error-pages" { t.Errorf("hi") t.Errorf("deployment.Spec.Template.Spec.Containers[0].VolumeMounts[4].Name %v", deployment.Spec.Template.Spec.Containers[0].VolumeMounts) @@ -505,6 +507,7 @@ func TestDesiredRouterDeployment(t *testing.T) { checkDeploymentHasEnvVar(t, deployment, "ROUTER_HAPROXY_CONFIG_MANAGER", true, "true") checkDeploymentHasEnvVar(t, deployment, "ROUTER_LOAD_BALANCE_ALGORITHM", true, "random") + checkDeploymentHasEnvVar(t, deployment, "ROUTER_TCP_BALANCE_SCHEME", true, "source") checkDeploymentHasEnvVar(t, deployment, "ROUTER_MAX_CONNECTIONS", true, "40000")