Skip to content

Commit 6ac3b9f

Browse files
frobwarealebedev87
authored andcommitted
OCPBUGS-43745: Add support for idle connection termination policy
Introduce logic in desiredRouterDeployment to set the environment variable `ROUTER_IDLE_CLOSE_ON_RESPONSE` when the `IdleConnectionTerminationPolicy` field in the IngressController spec is set to `Deferred`. This change enables configuring HAProxy with the `idle-close-on-response` option for better control over idle connection termination behaviour.
1 parent 506fced commit 6ac3b9f

File tree

4 files changed

+684
-0
lines changed

4 files changed

+684
-0
lines changed

pkg/operator/controller/ingress/deployment.go

+7
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,13 @@ func desiredRouterDeployment(ci *operatorv1.IngressController, ingressController
11851185
)
11861186
}
11871187

1188+
if ci.Spec.IdleConnectionTerminationPolicy == operatorv1.IngressControllerConnectionTerminationPolicyDeferred {
1189+
env = append(env, corev1.EnvVar{
1190+
Name: "ROUTER_IDLE_CLOSE_ON_RESPONSE",
1191+
Value: "true",
1192+
})
1193+
}
1194+
11881195
// TODO: The only connections from the router that may need the cluster-wide proxy are those for downloading CRLs,
11891196
// which, as of writing this, will always be http. If https becomes necessary, the router will need to mount the
11901197
// trusted CA bundle that cluster-network-operator generates. The process for adding that is described here:

pkg/operator/controller/ingress/deployment_test.go

+51
Original file line numberDiff line numberDiff line change
@@ -2564,3 +2564,54 @@ func TestDesiredRouterDeploymentRouterExternalCertificate(t *testing.T) {
25642564

25652565
checkDeploymentHasEnvSorted(t, deployment)
25662566
}
2567+
2568+
// Test_IdleConnectionTerminationPolicy validates that the ingress
2569+
// controller correctly sets the ROUTER_IDLE_CLOSE_ON_RESPONSE
2570+
// environment variable based on the setting of the
2571+
// IngressController's IdleConnectionTerminationPolicy.
2572+
func Test_IdleConnectionTerminationPolicy(t *testing.T) {
2573+
ic, ingressConfig, infraConfig, apiConfig, networkConfig, proxyNeeded, clusterProxyConfig := getRouterDeploymentComponents(t)
2574+
2575+
for _, tc := range []struct {
2576+
name string
2577+
policy operatorv1.IngressControllerConnectionTerminationPolicy
2578+
expectEnvVarPresent bool
2579+
expectedEnvVarValue string
2580+
}{{
2581+
name: "IdleConnectionTerminationPolicy is Deferred",
2582+
policy: operatorv1.IngressControllerConnectionTerminationPolicyDeferred,
2583+
expectEnvVarPresent: true,
2584+
expectedEnvVarValue: "true",
2585+
}, {
2586+
name: "IdleConnectionTerminationPolicy is not set",
2587+
policy: "",
2588+
expectEnvVarPresent: false,
2589+
expectedEnvVarValue: "",
2590+
}, {
2591+
name: "IdleConnectionTerminationPolicy is Immediate (default)",
2592+
policy: operatorv1.IngressControllerConnectionTerminationPolicyImmediate,
2593+
expectEnvVarPresent: false,
2594+
expectedEnvVarValue: "",
2595+
}} {
2596+
t.Run(tc.name, func(t *testing.T) {
2597+
ic.Spec.IdleConnectionTerminationPolicy = tc.policy
2598+
2599+
deployment, err := desiredRouterDeployment(ic, ingressControllerImage, ingressConfig, infraConfig, apiConfig, networkConfig, proxyNeeded, false, nil, clusterProxyConfig, false, false)
2600+
if err != nil {
2601+
t.Fatalf("failed to generate desired router Deployment: %v", err)
2602+
}
2603+
2604+
expectedEnv := []envData{{
2605+
name: "ROUTER_IDLE_CLOSE_ON_RESPONSE",
2606+
expectPresent: tc.expectEnvVarPresent,
2607+
expectedValue: tc.expectedEnvVarValue,
2608+
}}
2609+
2610+
if err := checkDeploymentEnvironment(t, deployment, expectedEnv); err != nil {
2611+
t.Errorf("environment variable check failed: %v", err)
2612+
}
2613+
2614+
checkDeploymentHasEnvSorted(t, deployment)
2615+
})
2616+
}
2617+
}

test/e2e/all_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ func TestAll(t *testing.T) {
8888
t.Run("TestUnmanagedAWSLBSubnets", TestUnmanagedAWSLBSubnets)
8989
t.Run("TestAWSEIPAllocationsForNLB", TestAWSEIPAllocationsForNLB)
9090
t.Run("TestUnmanagedAWSEIPAllocations", TestUnmanagedAWSEIPAllocations)
91+
t.Run("Test_IdleConnectionTerminationPolicyImmediate", Test_IdleConnectionTerminationPolicyImmediate)
92+
t.Run("Test_IdleConnectionTerminationPolicyDeferred", Test_IdleConnectionTerminationPolicyDeferred)
9193
})
9294

9395
t.Run("serial", func(t *testing.T) {

0 commit comments

Comments
 (0)