From 492ef254d968fe76c052f7a8ec645b75b7cace4b Mon Sep 17 00:00:00 2001 From: Kamil Sambor Date: Mon, 25 Nov 2024 15:25:41 +0100 Subject: [PATCH] Added a parameter 'apiTimeout' to allow customization to the Apache timeout. The default is set to 60s which we do set for HAProxy timeouts currently. 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.placement.openstack.org/timeout" with the value that was initially set, this way flags it as being set by the placement-operator. Timeout is global for both api and metadata and they are set from placement lvl There will be follow up patch in openstack-operator to utilize the method 'SetDefaultRouteAnnotations' to set these default route annotations in openstack-operator --- ...placement.openstack.org_placementapis.yaml | 5 +++++ api/v1beta1/placementapi_types.go | 6 +++++ api/v1beta1/placementapi_webhook.go | 22 +++++++++++++++++++ ...placement.openstack.org_placementapis.yaml | 5 +++++ controllers/placementapi_controller.go | 1 + templates/placementapi/config/httpd.conf | 1 + .../placementapi_controller_test.go | 3 +++ 7 files changed, 43 insertions(+) diff --git a/api/bases/placement.openstack.org_placementapis.yaml b/api/bases/placement.openstack.org_placementapis.yaml index 97a02555..263ef2da 100644 --- a/api/bases/placement.openstack.org_placementapis.yaml +++ b/api/bases/placement.openstack.org_placementapis.yaml @@ -48,6 +48,11 @@ spec: spec: description: PlacementAPISpec defines the desired state of PlacementAPI properties: + apiTimeout: + default: 60 + description: APITimeout for HAProxy, Apache + minimum: 10 + type: integer containerImage: description: PlacementAPI Container Image URL (will be set to environmental default if empty) diff --git a/api/v1beta1/placementapi_types.go b/api/v1beta1/placementapi_types.go index fe1fbc07..24694a1c 100644 --- a/api/v1beta1/placementapi_types.go +++ b/api/v1beta1/placementapi_types.go @@ -50,6 +50,12 @@ type PlacementAPISpec struct { // PlacementAPISpecCore - type PlacementAPISpecCore struct { + // +kubebuilder:validation:Optional + // +kubebuilder:default=60 + // +kubebuilder:validation:Minimum=10 + // APITimeout for HAProxy, Apache + APITimeout int `json:"apiTimeout"` + // +kubebuilder:validation:Optional // +kubebuilder:default=placement // ServiceUser - optional username used for this service to register in keystone diff --git a/api/v1beta1/placementapi_webhook.go b/api/v1beta1/placementapi_webhook.go index 7ddf75c8..83f29ce7 100644 --- a/api/v1beta1/placementapi_webhook.go +++ b/api/v1beta1/placementapi_webhook.go @@ -175,3 +175,25 @@ func ValidateDefaultConfigOverwrite( } return errors } + +// SetDefaultRouteAnnotations sets HAProxy timeout values of the route +func (spec *PlacementAPISpecCore) 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 placementAnno = "api.placement.openstack.org/timeout" + valNeutronAPI, okNeutronAPI := annotations[placementAnno] + valHAProxy, okHAProxy := annotations[haProxyAnno] + // Human operator set the HAProxy timeout manually + if !okNeutronAPI && okHAProxy { + return + } + // Human operator modified the HAProxy timeout manually without removing the NeutronAPI flag + if okNeutronAPI && okHAProxy && valNeutronAPI != valHAProxy { + delete(annotations, placementAnno) + return + } + timeout := fmt.Sprintf("%ds", spec.APITimeout) + annotations[placementAnno] = timeout + annotations[haProxyAnno] = timeout +} diff --git a/config/crd/bases/placement.openstack.org_placementapis.yaml b/config/crd/bases/placement.openstack.org_placementapis.yaml index 97a02555..263ef2da 100644 --- a/config/crd/bases/placement.openstack.org_placementapis.yaml +++ b/config/crd/bases/placement.openstack.org_placementapis.yaml @@ -48,6 +48,11 @@ spec: spec: description: PlacementAPISpec defines the desired state of PlacementAPI properties: + apiTimeout: + default: 60 + description: APITimeout for HAProxy, Apache + minimum: 10 + type: integer containerImage: description: PlacementAPI Container Image URL (will be set to environmental default if empty) diff --git a/controllers/placementapi_controller.go b/controllers/placementapi_controller.go index 82ce21a2..c51175b9 100644 --- a/controllers/placementapi_controller.go +++ b/controllers/placementapi_controller.go @@ -1259,6 +1259,7 @@ func (r *PlacementAPIReconciler) generateServiceConfigMaps( httpdVhostConfig[endpt.String()] = endptConfig } templateParameters["VHosts"] = httpdVhostConfig + templateParameters["TimeOut"] = instance.Spec.APITimeout extraTemplates := map[string]string{ "placement.conf": "placementapi/config/placement.conf", diff --git a/templates/placementapi/config/httpd.conf b/templates/placementapi/config/httpd.conf index f114b9bf..7c53ffd7 100644 --- a/templates/placementapi/config/httpd.conf +++ b/templates/placementapi/config/httpd.conf @@ -35,6 +35,7 @@ CustomLog /dev/stdout proxy env=forwarded ErrorLogFormat "%M" ServerName {{ $vhost.ServerName }} + TimeOut {{ $.TimeOut }} ## Vhost docroot ErrorLog /dev/stdout diff --git a/tests/functional/placementapi_controller_test.go b/tests/functional/placementapi_controller_test.go index 74d9d88f..19f41675 100644 --- a/tests/functional/placementapi_controller_test.go +++ b/tests/functional/placementapi_controller_test.go @@ -344,6 +344,9 @@ var _ = Describe("PlacementAPI controller", func() { myCnf := cm.Data["my.cnf"] Expect(myCnf).To( ContainSubstring("[client]\nssl=0")) + configData := cm.Data["httpd.conf"] + Expect(configData).Should( + ContainSubstring("TimeOut 60")) }) It("creates service account, role and rolebindig", func() {