From 29325b123d6a876b7baf1045aca91f5498ac7c61 Mon Sep 17 00:00:00 2001 From: Fabricio Aguiar Date: Mon, 4 Nov 2024 11:40:29 +0100 Subject: [PATCH] Add configurable API Timeouts 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 --- api/bases/heat.openstack.org_heats.yaml | 5 ++++ api/v1beta1/heat_types.go | 6 +++++ api/v1beta1/heat_webhook.go | 27 +++++++++++++++++++ .../crd/bases/heat.openstack.org_heats.yaml | 5 ++++ controllers/heat_controller.go | 1 + templates/heat/config/heat-api-httpd.conf | 2 +- templates/heat/config/heat-cfnapi-httpd.conf | 2 +- 7 files changed, 46 insertions(+), 2 deletions(-) diff --git a/api/bases/heat.openstack.org_heats.yaml b/api/bases/heat.openstack.org_heats.yaml index 5f383d5a..4fe948bd 100644 --- a/api/bases/heat.openstack.org_heats.yaml +++ b/api/bases/heat.openstack.org_heats.yaml @@ -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 diff --git a/api/v1beta1/heat_types.go b/api/v1beta1/heat_types.go index 59be6cf5..5da2c184 100644 --- a/api/v1beta1/heat_types.go +++ b/api/v1beta1/heat_types.go @@ -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"` } diff --git a/api/v1beta1/heat_webhook.go b/api/v1beta1/heat_webhook.go index 43c73ff9..672a944d 100644 --- a/api/v1beta1/heat_webhook.go +++ b/api/v1beta1/heat_webhook.go @@ -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 +} diff --git a/config/crd/bases/heat.openstack.org_heats.yaml b/config/crd/bases/heat.openstack.org_heats.yaml index 5f383d5a..4fe948bd 100644 --- a/config/crd/bases/heat.openstack.org_heats.yaml +++ b/config/crd/bases/heat.openstack.org_heats.yaml @@ -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 diff --git a/controllers/heat_controller.go b/controllers/heat_controller.go index a9e13b56..2b66b0db 100644 --- a/controllers/heat_controller.go +++ b/controllers/heat_controller.go @@ -1353,6 +1353,7 @@ func initTemplateParameters( "MemcachedServersWithInet": mc.GetMemcachedServerListWithInetString(), "MemcachedTLS": mc.GetMemcachedTLSSupport(), "DatabaseConnection": mysqlConnectionString, + "Timeout": instance.Spec.APITimeout, } } diff --git a/templates/heat/config/heat-api-httpd.conf b/templates/heat/config/heat-api-httpd.conf index a78d1413..2e2c7f35 100644 --- a/templates/heat/config/heat-api-httpd.conf +++ b/templates/heat/config/heat-api-httpd.conf @@ -53,6 +53,6 @@ ErrorLog /dev/stdout WSGIScriptAlias / "/usr/bin/heat-wsgi-api" WSGIPassAuthorization On - Timeout 600 + Timeout {{ $.Timeout }} {{ end }} diff --git a/templates/heat/config/heat-cfnapi-httpd.conf b/templates/heat/config/heat-cfnapi-httpd.conf index 7f8f1852..cb696511 100644 --- a/templates/heat/config/heat-cfnapi-httpd.conf +++ b/templates/heat/config/heat-cfnapi-httpd.conf @@ -53,6 +53,6 @@ ErrorLog /dev/stdout WSGIScriptAlias / "/usr/bin/heat-wsgi-api-cfn" WSGIPassAuthorization On - Timeout 600 + Timeout {{ $.Timeout }} {{ end }}