Skip to content

Commit

Permalink
Add configurable httpd timeout
Browse files Browse the repository at this point in the history
This patch adds an apiTimeout field to the OctaviaSpecCore
to the already OctaviaSpec one to allow configure the timeouts
for HAProxy and Apache.

Also fixing *core* API spec version of the new
GetDefaultRouteAnnotations function.

Jira: https://issues.redhat.com/browse/OSPRH-6713
  • Loading branch information
Fernando Royo committed Oct 24, 2024
1 parent 930f347 commit 586f791
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 3 deletions.
4 changes: 4 additions & 0 deletions api/bases/octavia.openstack.org_octaviaapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
spec:
description: OctaviaAPISpec defines the desired state of OctaviaAPI
properties:
apiTimeout:
description: APITimeout for HAProxy and Apache defaults to OctaviaSpecCore
APITimeout (seconds)
type: string
containerImage:
description: Octavia Container Image URL
type: string
Expand Down
4 changes: 4 additions & 0 deletions api/bases/octavia.openstack.org_octavias.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ spec:
description: OctaviaAPI - Spec definition for the API service of the
Octavia deployment
properties:
apiTimeout:
description: APITimeout for HAProxy and Apache defaults to OctaviaSpecCore
APITimeout (seconds)
type: string
containerImage:
description: Octavia Container Image URL
type: string
Expand Down
31 changes: 28 additions & 3 deletions api/v1beta1/octavia_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,34 @@ func (r *Octavia) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}

func (spec *OctaviaSpec) GetDefaultRouteAnnotations() (annotations map[string]string) {
annotations = map[string]string{
func (spec *OctaviaAPISpecCore) GetDefaultRouteAnnotations() (annotations map[string]string) {
return map[string]string{
"haproxy.router.openshift.io/timeout": octaviaDefaults.OctaviaAPIRouteTimeout,
}
return
}

// SetDefaultRouteAnnotations sets HAProxy timeout values of the route
func (octaviaAPI *OctaviaAPISpecCore) SetDefaultRouteAnnotations(annotations map[string]string) {
const haProxyAnno = "haproxy.router.openshift.io/timeout"
// Use a custom annotation to flag when the operator has set the default HAProxy timeout
// With the annotation func determines when to overwrite existing HAProxy timeout with the APITimeout
const octaviaAnno = "api.octavia.openstack.org/timeout"

valOctavia, okOctavia := annotations[octaviaAnno]
valHAProxy, okHAProxy := annotations[haProxyAnno]

// Human operator set the HAProxy timeout manually
if !okOctavia && okHAProxy {
return
}

// Human operator modified the HAProxy timeout manually without removing the Octavia flag
if okOctavia && okHAProxy && valOctavia != valHAProxy {
delete(annotations, octaviaAnno)
return
}

timeout := octaviaAPI.APITimeout + "s"
annotations[octaviaAnno] = timeout
annotations[haProxyAnno] = timeout
}
4 changes: 4 additions & 0 deletions api/v1beta1/octaviaapi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ type OctaviaAPISpecCore struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec
// TLS - Parameters related to the TLS
TLS OctaviaApiTLS `json:"tls,omitempty"`

// +kubebuilder:validation:Optional
// APITimeout for HAProxy and Apache defaults to OctaviaSpecCore APITimeout (seconds)
APITimeout string `json:"apiTimeout,omitempty"`
}

type OctaviaApiTLS struct {
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/octavia.openstack.org_octaviaapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
spec:
description: OctaviaAPISpec defines the desired state of OctaviaAPI
properties:
apiTimeout:
description: APITimeout for HAProxy and Apache defaults to OctaviaSpecCore
APITimeout (seconds)
type: string
containerImage:
description: Octavia Container Image URL
type: string
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/octavia.openstack.org_octavias.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ spec:
description: OctaviaAPI - Spec definition for the API service of the
Octavia deployment
properties:
apiTimeout:
description: APITimeout for HAProxy and Apache defaults to OctaviaSpecCore
APITimeout (seconds)
type: string
containerImage:
description: Octavia Container Image URL
type: string
Expand Down
2 changes: 2 additions & 0 deletions controllers/octaviaapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,8 @@ func (r *OctaviaAPIReconciler) generateServiceSecrets(
}
templateParameters["OVNDB_TLS"] = instance.Spec.TLS.Ovn.Enabled()

templateParameters["TimeOut"] = instance.Spec.APITimeout

// create httpd vhost template parameters
httpdVhostConfig := map[string]interface{}{}
for _, endpt := range []service.Endpoint{service.EndpointInternal, service.EndpointPublic} {
Expand Down
2 changes: 2 additions & 0 deletions templates/octaviaapi/config/httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ CustomLog /dev/stdout proxy env=forwarded
CustomLog /dev/stdout combined env=!forwarded
CustomLog /dev/stdout proxy env=forwarded

TimeOut {{ $.TimeOut }}

{{- if $vhost.TLS }}
SetEnvIf X-Forwarded-Proto https HTTPS=1

Expand Down

0 comments on commit 586f791

Please sign in to comment.