Skip to content

Commit

Permalink
Add unsupported config override for reload interval
Browse files Browse the repository at this point in the history
* pkg/operator/controller/ingress/deployment.go
(RouterReloadIntervalEnvName): New const.
(desiredRouterDeployment): Add unsupported config override for
RELOAD_INTERVAL.
* pkg/operator/controller/ingress/deployment_test.go
(TestDesiredRouterDeployment): Verify that desiredRouterDeployment sets
RELOAD_INTERVAL as expected.
* test/e2e/operator_test.go (TestReloadIntervalUnsupportedConfigOverride):
Verify that the operator sets RELOAD_INTERVAL to the value specified in the
unsupported configuration override or to the default value of 5 if no
override is specified.
  • Loading branch information
Miciah committed Jun 26, 2021
1 parent f9b7a8a commit c0a7ca5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
11 changes: 11 additions & 0 deletions pkg/operator/controller/ingress/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const (

RouterLoadBalancingAlgorithmEnvName = "ROUTER_LOAD_BALANCE_ALGORITHM"

RouterReloadIntervalEnvName = "RELOAD_INTERVAL"

RouterDisableHTTP2EnvName = "ROUTER_DISABLE_HTTP2"
RouterDefaultEnableHTTP2Annotation = "ingress.operator.openshift.io/default-enable-http2"

Expand Down Expand Up @@ -440,6 +442,7 @@ func desiredRouterDeployment(ci *operatorv1.IngressController, ingressController

var unsupportedConfigOverrides struct {
LoadBalancingAlgorithm string `json:"loadBalancingAlgorithm"`
ReloadInterval int32 `json:"reloadInterval"`
}
if len(ci.Spec.UnsupportedConfigOverrides.Raw) > 0 {
if err := json.Unmarshal(ci.Spec.UnsupportedConfigOverrides.Raw, &unsupportedConfigOverrides); err != nil {
Expand All @@ -455,6 +458,14 @@ func desiredRouterDeployment(ci *operatorv1.IngressController, ingressController
Name: RouterLoadBalancingAlgorithmEnvName,
Value: loadBalancingAlgorithm,
})
reloadInterval := 5
if unsupportedConfigOverrides.ReloadInterval > 0 {
reloadInterval = int(unsupportedConfigOverrides.ReloadInterval)
}
env = append(env, corev1.EnvVar{
Name: RouterReloadIntervalEnvName,
Value: strconv.Itoa(reloadInterval),
})

if len(ci.Status.Domain) > 0 {
env = append(env, corev1.EnvVar{Name: "ROUTER_CANONICAL_HOSTNAME", Value: "router-" + ci.Name + "." + ci.Status.Domain})
Expand Down
8 changes: 7 additions & 1 deletion pkg/operator/controller/ingress/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ func TestDesiredRouterDeployment(t *testing.T) {
checkDeploymentDoesNotHaveEnvVar(t, deployment, "ROUTER_ERRORFILE_503")
checkDeploymentDoesNotHaveEnvVar(t, deployment, "ROUTER_ERRORFILE_404")

checkDeploymentHasEnvVar(t, deployment, "RELOAD_INTERVAL", true, "5")

checkDeploymentHasEnvVar(t, deployment, "ROUTER_USE_PROXY_PROTOCOL", false, "")

checkDeploymentHasEnvVar(t, deployment, "ROUTER_CANONICAL_HOSTNAME", false, "")
Expand Down Expand Up @@ -349,7 +351,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":"leastconn","reloadInterval":15}`),
}
ci.Spec.HttpErrorCodePages = configv1.ConfigMapNameReference{
Name: "my-custom-error-code-pages",
Expand Down Expand Up @@ -390,6 +392,8 @@ func TestDesiredRouterDeployment(t *testing.T) {
t.Error("router Deployment is missing error code pages volume mount")
}

checkDeploymentHasEnvVar(t, deployment, "RELOAD_INTERVAL", true, "15")

checkDeploymentHasEnvVar(t, deployment, "ROUTER_USE_PROXY_PROTOCOL", true, "true")

checkDeploymentHasEnvVar(t, deployment, "ROUTER_UNIQUE_ID_HEADER_NAME", true, "unique-id")
Expand Down Expand Up @@ -459,6 +463,8 @@ func TestDesiredRouterDeployment(t *testing.T) {

checkDeploymentHasEnvVar(t, deployment, "ROUTER_LOAD_BALANCE_ALGORITHM", true, "random")

checkDeploymentHasEnvVar(t, deployment, "RELOAD_INTERVAL", true, "5")

checkDeploymentDoesNotHaveEnvVar(t, deployment, "ROUTER_USE_PROXY_PROTOCOL")

checkDeploymentHasEnvVar(t, deployment, "ROUTER_UNIQUE_ID_HEADER_NAME", true, "unique-id")
Expand Down
40 changes: 40 additions & 0 deletions test/e2e/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2100,6 +2100,46 @@ func TestLocalWithFallbackOverrideForNodePortService(t *testing.T) {
}
}

// TestReloadIntervalUnsupportedConfigOverride verifies that the operator
// configures router pod replicas with the specified value for RELOAD_INTERVAL
// if one is specified using an unsupported config override on the
// ingresscontroller.
func TestReloadIntervalUnsupportedConfigOverride(t *testing.T) {
icName := types.NamespacedName{Namespace: operatorNamespace, Name: "reload-interval"}
domain := icName.Name + "." + dnsConfig.Spec.BaseDomain
ic := newPrivateController(icName, domain)
if err := kclient.Create(context.TODO(), ic); err != nil {
t.Fatalf("failed to create ingresscontroller: %v", err)
}
defer assertIngressControllerDeleted(t, kclient, ic)

if err := waitForIngressControllerCondition(t, kclient, 5*time.Minute, icName, availableConditionsForPrivateIngressController...); err != nil {
t.Fatalf("failed to observe expected conditions: %w", err)
}

if err := kclient.Get(context.TODO(), icName, ic); err != nil {
t.Fatalf("failed to get ingresscontroller: %v", err)
}

deployment := &appsv1.Deployment{}
if err := kclient.Get(context.TODO(), controller.RouterDeploymentName(ic), deployment); err != nil {
t.Fatalf("failed to get ingresscontroller deployment: %v", err)
}
if err := waitForDeploymentEnvVar(t, kclient, deployment, 30*time.Second, "RELOAD_INTERVAL", "5"); err != nil {
t.Fatalf("expected initial deployment to set RELOAD_INTERVAL=5: %v", err)
}

ic.Spec.UnsupportedConfigOverrides = runtime.RawExtension{
Raw: []byte(`{"reloadInterval":"60"}`),
}
if err := kclient.Update(context.TODO(), ic); err != nil {
t.Fatalf("failed to update ingresscontroller: %v", err)
}
if err := waitForDeploymentEnvVar(t, kclient, deployment, 1*time.Minute, "RELOAD_INTERVAL", "60"); err != nil {
t.Fatalf("expected updated deployment to set RELOAD_INTERVAL=60: %v", err)
}
}

// TestCustomErrorpages verifies that the custom error-pages API works properly,
// and that the error-page configmap controller properly synchs the operator's
// error-page configmap when it is deleted or when the user-provided configmap
Expand Down

0 comments on commit c0a7ca5

Please sign in to comment.