Skip to content

Commit

Permalink
Add configurable API Timeouts
Browse files Browse the repository at this point in the history
This patch adds an apiTimeout field to the HeatSpecBase to allow human operators to simultaneously configure the timeouts for HAProxy, Apache, and the rpc_response_timeout.

The apiTimeout defaults to 60 seconds, to mimic the behavior present in OSP17.

Having different timeouts for HAProxy, Apache, and rpc_response_timeout is possible setting the HAProxy timeout in the apiOverride, the Apache timeout with apiTimeout, and setting rpc_response_timeout in the top level Heat customServiceConfig.

To be able to change the HAProxy value based on the apiTimeout with any update (and not just the first time) the code adds a custom annotation "api.heat.openstack.org/timeout" with the value that was initially set, this way flags it as being set by the heat-operator.

closes OSPRH-10965

Signed-off-by: Fabricio Aguiar <[email protected]>
  • Loading branch information
fao89 authored and openshift-cherrypick-robot committed Jan 10, 2025
1 parent 93eece5 commit b9b6c5c
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 2 deletions.
5 changes: 5 additions & 0 deletions api/bases/heat.openstack.org_heats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ spec:
spec:
description: HeatSpec defines the desired state of Heat
properties:
apiTimeout:
default: 600
description: APITimeout for Route and Apache
minimum: 60
type: integer
customServiceConfig:
description: CustomServiceConfig - customize the service config using
this parameter to change service defaults, or overwrite rendered
Expand Down
6 changes: 6 additions & 0 deletions api/v1beta1/heat_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ type HeatSpecBase struct {
// NodeSelector to target subset of worker nodes for running the Heat services
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=600
// +kubebuilder:validation:Minimum=60
// APITimeout for Route and Apache
APITimeout int `json:"apiTimeout"`

// Common input parameters for all Heat services
HeatTemplate `json:",inline"`
}
Expand Down
27 changes: 27 additions & 0 deletions api/v1beta1/heat_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,30 @@ func (r *Heat) ValidateDelete() (admission.Warnings, error) {
// TODO(user): fill in your validation logic upon object deletion.
return nil, nil
}

// SetDefaultRouteAnnotations sets HAProxy timeout values of the route
// NOTE: it is used by ctlplane webhook on openstack-operator
func (spec *HeatSpecCore) 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 heatAnno = "api.heat.openstack.org/timeout"

valHeat, okHeat := annotations[heatAnno]
valHAProxy, okHAProxy := annotations[haProxyAnno]

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

// Human operator modified the HAProxy timeout manually without removing the Heat flag
if okHeat && okHAProxy && valHeat != valHAProxy {
delete(annotations, heatAnno)
return
}

timeout := fmt.Sprintf("%ds", spec.APITimeout)
annotations[heatAnno] = timeout
annotations[haProxyAnno] = timeout
}
5 changes: 5 additions & 0 deletions config/crd/bases/heat.openstack.org_heats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ spec:
spec:
description: HeatSpec defines the desired state of Heat
properties:
apiTimeout:
default: 600
description: APITimeout for Route and Apache
minimum: 60
type: integer
customServiceConfig:
description: CustomServiceConfig - customize the service config using
this parameter to change service defaults, or overwrite rendered
Expand Down
1 change: 1 addition & 0 deletions controllers/heat_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,7 @@ func initTemplateParameters(
"MemcachedServersWithInet": mc.GetMemcachedServerListWithInetString(),
"MemcachedTLS": mc.GetMemcachedTLSSupport(),
"DatabaseConnection": mysqlConnectionString,
"Timeout": instance.Spec.APITimeout,
}
}

Expand Down
2 changes: 1 addition & 1 deletion templates/heat/config/heat-api-httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ ErrorLog /dev/stdout
WSGIScriptAlias / "/usr/bin/heat-wsgi-api"
WSGIPassAuthorization On

Timeout 600
Timeout {{ $.Timeout }}
</VirtualHost>
{{ end }}
2 changes: 1 addition & 1 deletion templates/heat/config/heat-cfnapi-httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ ErrorLog /dev/stdout
WSGIScriptAlias / "/usr/bin/heat-wsgi-api-cfn"
WSGIPassAuthorization On

Timeout 600
Timeout {{ $.Timeout }}
</VirtualHost>
{{ end }}

0 comments on commit b9b6c5c

Please sign in to comment.