Skip to content

Commit

Permalink
Added a parameter 'apiTimeout' to allow customization
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mrkisaolamb authored and openshift-merge-bot[bot] committed Dec 23, 2024
1 parent df31b23 commit 5c39b09
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/bases/placement.openstack.org_placementapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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)
Expand Down
6 changes: 6 additions & 0 deletions api/v1beta1/placementapi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions api/v1beta1/placementapi_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,26 @@ 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"
valPlacementAPI, okPlacementAPI := annotations[placementAnno]
valHAProxy, okHAProxy := annotations[haProxyAnno]
// Human operator set the HAProxy timeout manually
if !okPlacementAPI && okHAProxy {
return
}
// Human operator modified the HAProxy timeout manually without removing the Placemen flag
if okPlacementAPI && okHAProxy && valPlacementAPI != valHAProxy {
delete(annotations, placementAnno)
placementapilog.Info("Human operator modified the HAProxy timeout manually without removing the Placement flag. Deleting the Placement flag to ensure proper configuration.")
return
}
timeout := fmt.Sprintf("%ds", spec.APITimeout)
annotations[placementAnno] = timeout
annotations[haProxyAnno] = timeout
}
5 changes: 5 additions & 0 deletions config/crd/bases/placement.openstack.org_placementapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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)
Expand Down
1 change: 1 addition & 0 deletions controllers/placementapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,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",
Expand Down
1 change: 1 addition & 0 deletions templates/placementapi/config/httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ CustomLog /dev/stdout proxy env=forwarded
ErrorLogFormat "%M"
</IfVersion>
ServerName {{ $vhost.ServerName }}
TimeOut {{ $.TimeOut }}

## Vhost docroot
ErrorLog /dev/stdout
Expand Down
3 changes: 3 additions & 0 deletions tests/functional/placementapi_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 5c39b09

Please sign in to comment.