Skip to content

Commit 7c6d621

Browse files
committed
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. There will be follow up patch in openstack-operator to utilize the method 'SetDefaultRouteAnnotations' to set these default route annotations in openstack-operator
1 parent a531fbe commit 7c6d621

File tree

7 files changed

+44
-0
lines changed

7 files changed

+44
-0
lines changed

api/bases/placement.openstack.org_placementapis.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ spec:
4848
spec:
4949
description: PlacementAPISpec defines the desired state of PlacementAPI
5050
properties:
51+
apiTimeout:
52+
default: 60
53+
description: APITimeout for HAProxy, Apache
54+
minimum: 10
55+
type: integer
5156
containerImage:
5257
description: PlacementAPI Container Image URL (will be set to environmental
5358
default if empty)

api/v1beta1/placementapi_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ type PlacementAPISpec struct {
5050

5151
// PlacementAPISpecCore -
5252
type PlacementAPISpecCore struct {
53+
// +kubebuilder:validation:Optional
54+
// +kubebuilder:default=60
55+
// +kubebuilder:validation:Minimum=10
56+
// APITimeout for HAProxy, Apache
57+
APITimeout int `json:"apiTimeout"`
58+
5359
// +kubebuilder:validation:Optional
5460
// +kubebuilder:default=placement
5561
// ServiceUser - optional username used for this service to register in keystone

api/v1beta1/placementapi_webhook.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,26 @@ func ValidateDefaultConfigOverwrite(
175175
}
176176
return errors
177177
}
178+
179+
// SetDefaultRouteAnnotations sets HAProxy timeout values of the route
180+
func (spec *PlacementAPISpecCore) SetDefaultRouteAnnotations(annotations map[string]string) {
181+
const haProxyAnno = "haproxy.router.openshift.io/timeout"
182+
// Use a custom annotation to flag when the operator has set the default HAProxy timeout
183+
// With the annotation func determines when to overwrite existing HAProxy timeout with the APITimeout
184+
const placementAnno = "api.placement.openstack.org/timeout"
185+
valPlacementAPI, okPlacementAPI := annotations[placementAnno]
186+
valHAProxy, okHAProxy := annotations[haProxyAnno]
187+
// Human operator set the HAProxy timeout manually
188+
if !okPlacementAPI && okHAProxy {
189+
return
190+
}
191+
// Human operator modified the HAProxy timeout manually without removing the Placemen flag
192+
if okPlacementAPI && okHAProxy && valPlacementAPI != valHAProxy {
193+
delete(annotations, placementAnno)
194+
placementapilog.Info("Human operator modified the HAProxy timeout manually without removing the Placement flag. Deleting the Placement flag to ensure proper configuration.")
195+
return
196+
}
197+
timeout := fmt.Sprintf("%ds", spec.APITimeout)
198+
annotations[placementAnno] = timeout
199+
annotations[haProxyAnno] = timeout
200+
}

config/crd/bases/placement.openstack.org_placementapis.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ spec:
4848
spec:
4949
description: PlacementAPISpec defines the desired state of PlacementAPI
5050
properties:
51+
apiTimeout:
52+
default: 60
53+
description: APITimeout for HAProxy, Apache
54+
minimum: 10
55+
type: integer
5156
containerImage:
5257
description: PlacementAPI Container Image URL (will be set to environmental
5358
default if empty)

controllers/placementapi_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,7 @@ func (r *PlacementAPIReconciler) generateServiceConfigMaps(
12651265
httpdVhostConfig[endpt.String()] = endptConfig
12661266
}
12671267
templateParameters["VHosts"] = httpdVhostConfig
1268+
templateParameters["TimeOut"] = instance.Spec.APITimeout
12681269

12691270
extraTemplates := map[string]string{
12701271
"placement.conf": "placementapi/config/placement.conf",

templates/placementapi/config/httpd.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ CustomLog /dev/stdout proxy env=forwarded
3535
ErrorLogFormat "%M"
3636
</IfVersion>
3737
ServerName {{ $vhost.ServerName }}
38+
TimeOut {{ $.TimeOut }}
3839

3940
## Vhost docroot
4041
ErrorLog /dev/stdout

tests/functional/placementapi_controller_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ var _ = Describe("PlacementAPI controller", func() {
344344
myCnf := cm.Data["my.cnf"]
345345
Expect(myCnf).To(
346346
ContainSubstring("[client]\nssl=0"))
347+
configData := cm.Data["httpd.conf"]
348+
Expect(configData).Should(
349+
ContainSubstring("TimeOut 60"))
347350
})
348351

349352
It("creates service account, role and rolebindig", func() {

0 commit comments

Comments
 (0)