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 395fe155..9ed445f7 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 e96b17f6..7d2ddf3e 100644 --- a/controllers/heat_controller.go +++ b/controllers/heat_controller.go @@ -1356,6 +1356,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 }}