From 25d090001fad8214566a14683a000178adbe59b2 Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Wed, 5 Jun 2024 18:03:32 +0200 Subject: [PATCH] Add configurable API Timeouts Multiple limitations exist with existing code: - Human operator cannot configure Apache Timeout, so it's fixed at the defaults of 60 seconds. This is not a big issue since there's only 1 sync operation, but for consistency we adopt the same approach as Cinder and Glance. - Default HAProxy timeout is 30 seconds, which is different than the default in OSP17 (60 seconds) - Human operators would need to sync values between 3 places: HAProxy, Apache, oslo.messaging sync RPC (call). This patch adds an `apiTimeout` field to the `ManilaSpecBase` 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 Manila `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.manila.openstack.org/timeout" with the value that was initially set, this way flags it as being set by the manila-operator. --- api/bases/manila.openstack.org_manilas.yaml | 4 +++ api/v1beta1/manila_types.go | 6 +++++ api/v1beta1/manila_webhook.go | 26 +++++++++++++++++++ .../bases/manila.openstack.org_manilas.yaml | 4 +++ controllers/manila_controller.go | 1 + templates/manila/config/00-config.conf | 3 +++ templates/manila/config/10-manila_wsgi.conf | 2 ++ 7 files changed, 46 insertions(+) diff --git a/api/bases/manila.openstack.org_manilas.yaml b/api/bases/manila.openstack.org_manilas.yaml index a806a2ca..98480c8b 100644 --- a/api/bases/manila.openstack.org_manilas.yaml +++ b/api/bases/manila.openstack.org_manilas.yaml @@ -36,6 +36,10 @@ spec: type: object spec: properties: + apiTimeout: + default: 60 + minimum: 10 + type: integer customServiceConfig: default: '# add your customization here' type: string diff --git a/api/v1beta1/manila_types.go b/api/v1beta1/manila_types.go index bee43490..ed924f9f 100644 --- a/api/v1beta1/manila_types.go +++ b/api/v1beta1/manila_types.go @@ -115,6 +115,12 @@ type ManilaSpecBase struct { // +kubebuilder:validation:Optional // DBPurge parameters - DBPurge DBPurge `json:"dbPurge,omitempty"` + + // +kubebuilder:validation:Optional + // +kubebuilder:default=60 + // +kubebuilder:validation:Minimum=10 + // APITimeout for HAProxy, Apache, and rpc_response_timeout + APITimeout int `json:"apiTimeout"` } // ManilaStatus defines the observed state of Manila diff --git a/api/v1beta1/manila_webhook.go b/api/v1beta1/manila_webhook.go index 459d54fd..0e02fa96 100644 --- a/api/v1beta1/manila_webhook.go +++ b/api/v1beta1/manila_webhook.go @@ -230,3 +230,29 @@ func (r *Manila) 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 +func (spec *ManilaSpecCore) 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 manilaAnno = "api.manila.openstack.org/timeout" + + valManila, okManila := annotations[manilaAnno] + valHAProxy, okHAProxy := annotations[haProxyAnno] + + // Human operator set the HAProxy timeout manually + if (!okManila && okHAProxy) { + return + } + + // Human operator modified the HAProxy timeout manually without removing the Manila flag + if (okManila && okHAProxy && valManila != valHAProxy) { + delete(annotations, manilaAnno) + return + } + + timeout := fmt.Sprintf("%ds", spec.APITimeout) + annotations[manilaAnno] = timeout + annotations[haProxyAnno] = timeout +} diff --git a/config/crd/bases/manila.openstack.org_manilas.yaml b/config/crd/bases/manila.openstack.org_manilas.yaml index a806a2ca..98480c8b 100644 --- a/config/crd/bases/manila.openstack.org_manilas.yaml +++ b/config/crd/bases/manila.openstack.org_manilas.yaml @@ -36,6 +36,10 @@ spec: type: object spec: properties: + apiTimeout: + default: 60 + minimum: 10 + type: integer customServiceConfig: default: '# add your customization here' type: string diff --git a/controllers/manila_controller.go b/controllers/manila_controller.go index eecdc060..8e596386 100644 --- a/controllers/manila_controller.go +++ b/controllers/manila_controller.go @@ -893,6 +893,7 @@ func (r *ManilaReconciler) generateServiceConfig( instance.Status.DatabaseHostname, manila.DatabaseCRName), "MemcachedServersWithInet": memcached.GetMemcachedServerListWithInetString(), + "TimeOut": instance.Spec.APITimeout, } // create httpd vhost template parameters diff --git a/templates/manila/config/00-config.conf b/templates/manila/config/00-config.conf index b75968dd..35045077 100644 --- a/templates/manila/config/00-config.conf +++ b/templates/manila/config/00-config.conf @@ -10,6 +10,9 @@ auth_strategy=keystone control_exchange=openstack api_paste_config=/etc/manila/api-paste.ini +# Keep the RPC call timeout in sync with HAProxy and Apache timeouts +rpc_response_timeout = {{ .TimeOut }} + [cinder] [cors] diff --git a/templates/manila/config/10-manila_wsgi.conf b/templates/manila/config/10-manila_wsgi.conf index 81a4d0a9..3a304576 100644 --- a/templates/manila/config/10-manila_wsgi.conf +++ b/templates/manila/config/10-manila_wsgi.conf @@ -14,6 +14,8 @@ Require all granted + Timeout {{ $.TimeOut }} + ## Logging ErrorLog /dev/stdout ServerSignature Off