Skip to content

Commit

Permalink
Add "ingress.operator.openshift.io/hard-stop-after" annotation
Browse files Browse the repository at this point in the history
Annotating either an ingresscontroller or the ingress config with this
new annoation will redeploy the router and that will configure haproxy
to emit the haproxy "hard-stop-after" global option.

An ingresscontroller with a valid annotation set will override
ingresses.config/cluster (if set).

Examples:

Annotating the ingress config:

    $ oc annotate ingresses.config/cluster ingress.operator.openshift.io/hard-stop-after=1h

Annotating the "default" ingresscontroller:

    $ oc -n openshift-ingress-operator annotate ingresscontrollers/default ingress.operator.openshift.io/hard-stop-after=30m
  • Loading branch information
frobware committed Jan 8, 2021
1 parent 9f2b030 commit 9bc4ee7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/operator/controller/ingress/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ const (

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

RouterHardStopAfterEnvName = "ROUTER_HARD_STOP_AFTER"
RouterHardStopAfterAnnotation = "ingress.operator.openshift.io/hard-stop-after"
)

// ensureRouterDeployment ensures the router deployment exists for a given
Expand Down Expand Up @@ -136,6 +139,28 @@ func HTTP2IsEnabled(ic *operatorv1.IngressController, ingressConfig *configv1.In
return configHasHTTP2Enabled
}

// HardStopAfterIsEnabledByAnnotation returns true if the map m has
// the key RouterHardStopAfterEnvName and its value is not the empty
// string ("").
func HardStopAfterIsEnabledByAnnotation(m map[string]string) (bool, string) {
if val, ok := m[RouterHardStopAfterAnnotation]; ok && len(val) > 0 {
return true, val
}
return false, ""
}

// HardStopAfterIsEnabled returns true if either the ingress
// controller or the ingress config has the "hard-stop-after"
// annotation. The presence of the annoation on the ingress
// controller, irrespective of its value, always overrides any setting
// on the ingress config.
func HardStopAfterIsEnabled(ic *operatorv1.IngressController, ingressConfig *configv1.Ingress) (bool, string) {
if controllerAnnotation, controllerValue := HardStopAfterIsEnabledByAnnotation(ic.Annotations); controllerAnnotation {
return controllerAnnotation, controllerValue
}
return HardStopAfterIsEnabledByAnnotation(ingressConfig.Annotations)
}

// desiredRouterDeployment returns the desired router deployment.
func desiredRouterDeployment(ci *operatorv1.IngressController, ingressControllerImage string, ingressConfig *configv1.Ingress, apiConfig *configv1.APIServer, networkConfig *configv1.Network, proxyNeeded bool) (*appsv1.Deployment, error) {
deployment := manifests.RouterDeployment()
Expand Down Expand Up @@ -623,6 +648,10 @@ func desiredRouterDeployment(ci *operatorv1.IngressController, ingressController
env = append(env, corev1.EnvVar{Name: RouterDisableHTTP2EnvName, Value: "true"})
}

if enabled, value := HardStopAfterIsEnabled(ci, ingressConfig); enabled && len(value) > 0 {
env = append(env, corev1.EnvVar{Name: RouterHardStopAfterEnvName, Value: value})
}

deployment.Spec.Template.Spec.Volumes = volumes
deployment.Spec.Template.Spec.Containers[0].VolumeMounts = routerVolumeMounts
deployment.Spec.Template.Spec.Containers[0].Env = append(deployment.Spec.Template.Spec.Containers[0].Env, env...)
Expand Down
2 changes: 2 additions & 0 deletions pkg/operator/controller/ingress/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ func TestDesiredRouterDeployment(t *testing.T) {
checkDeploymentHasEnvVar(t, deployment, "ROUTER_UNIQUE_ID_FORMAT", true, `"foo"`)

checkDeploymentHasEnvVar(t, deployment, "ROUTER_H1_CASE_ADJUST", false, "")
checkDeploymentHasEnvVar(t, deployment, "ROUTER_H1_CASE_ADJUST", false, "")
checkDeploymentHasEnvVar(t, deployment, RouterHardStopAfterEnvName, false, "")
}

func TestInferTLSProfileSpecFromDeployment(t *testing.T) {
Expand Down

0 comments on commit 9bc4ee7

Please sign in to comment.