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 23, 2021
1 parent 455fbd0 commit 1267b30
Show file tree
Hide file tree
Showing 3 changed files with 57 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 @@ -406,6 +408,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 @@ -421,6 +424,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: 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 @@ -220,6 +220,8 @@ func TestDesiredRouterDeployment(t *testing.T) {

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

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 @@ -338,7 +340,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.Status.Domain = "example.com"
ci.Status.EndpointPublishingStrategy.Type = operatorv1.LoadBalancerServiceStrategyType
Expand Down Expand Up @@ -370,6 +372,8 @@ func TestDesiredRouterDeployment(t *testing.T) {

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

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 @@ -439,6 +443,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
39 changes: 39 additions & 0 deletions test/e2e/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1925,6 +1925,45 @@ func TestLoadBalancingAlgorithmUnsupportedConfigOverride(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 TestDynamicConfigManagerUnsupportedConfigOverride(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.Errorf("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", ""); err != nil {
t.Fatalf("expected initial deployment not 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 initial deployment to set RELOAD_INTERVAL=60: %v", err)
}
}

func newLoadBalancerController(name types.NamespacedName, domain string) *operatorv1.IngressController {
repl := int32(1)
return &operatorv1.IngressController{
Expand Down

0 comments on commit 1267b30

Please sign in to comment.