Skip to content

Commit 7431e44

Browse files
committed
Add configurable httpd timeout
This patch adds an apiTimeout field to the DesignateSpecCore to DesignateSpec, to allow a configuration of the timeouts for HAProxy and Apache. Inherit from the controller in case it is not specified by the user. Jira: https://issues.redhat.com/browse/OSPRH-10963
1 parent 21fa99a commit 7431e44

11 files changed

+92
-17
lines changed

api/bases/designate.openstack.org_designateapis.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ spec:
4848
spec:
4949
description: DesignateAPISpec defines the desired state of DesignateAPI
5050
properties:
51+
apiTimeout:
52+
description: APITimeout for HAProxy and Apache defaults to DesignateSpecCore
53+
APITimeout (seconds)
54+
type: integer
5155
backendMdnsServerProtocol:
5256
description: 'BackendTypeProtocol - Defines the backend protocol to
5357
be used between the designate-worker & designate_mdns to/from the

api/bases/designate.openstack.org_designates.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ spec:
4444
spec:
4545
description: DesignateAPISpec defines the desired state of DesignateAPI
4646
properties:
47+
apiTimeout:
48+
default: 120
49+
description: Designate API timeout
50+
type: integer
4751
backendMdnsServerProtocol:
4852
description: 'BackendTypeProtocol - Defines the backend protocol to
4953
be used between the designate-worker & designate_mdns to/from the
@@ -91,6 +95,10 @@ spec:
9195
description: DesignateAPI - Spec definition for the API service of
9296
this Designate deployment
9397
properties:
98+
apiTimeout:
99+
description: APITimeout for HAProxy and Apache defaults to DesignateSpecCore
100+
APITimeout (seconds)
101+
type: integer
94102
backendMdnsServerProtocol:
95103
description: 'BackendTypeProtocol - Defines the backend protocol
96104
to be used between the designate-worker & designate_mdns to/from

api/v1beta1/common_types.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20-
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
2120
corev1 "k8s.io/api/core/v1"
2221
)
2322

@@ -133,19 +132,3 @@ type PasswordSelector struct {
133132
// Service - Selector to get the designate service password from the Secret
134133
Service string `json:"service"`
135134
}
136-
137-
// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks)
138-
func SetupDefaults() {
139-
// Acquire environmental defaults and initialize Designate defaults with them
140-
designateDefaults := DesignateDefaults{
141-
APIContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_API_IMAGE_URL_DEFAULT", DesignateAPIContainerImage),
142-
CentralContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_CENTRAL_IMAGE_URL_DEFAULT", DesignateCentralContainerImage),
143-
MdnsContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_MDNS_IMAGE_URL_DEFAULT", DesignateMdnsContainerImage),
144-
ProducerContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_PRODUCER_IMAGE_URL_DEFAULT", DesignateProducerContainerImage),
145-
WorkerContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_WORKER_IMAGE_URL_DEFAULT", DesignateWorkerContainerImage),
146-
UnboundContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_UNBOUND_IMAGE_URL_DEFAULT", DesignateUnboundContainerImage),
147-
Backendbind9ContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_BACKENDBIND9_IMAGE_URL_DEFAULT", DesignateBackendbind9ContainerImage),
148-
}
149-
150-
SetupDesignateDefaults(designateDefaults)
151-
}

api/v1beta1/designate_types.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package v1beta1
1818

1919
import (
2020
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
21+
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
2122
"github.com/openstack-k8s-operators/lib-common/modules/storage"
2223
corev1 "k8s.io/api/core/v1"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -29,6 +30,9 @@ const (
2930

3031
// DeploymentHash hash used to detect changes
3132
DeploymentHash = "deployment"
33+
34+
// Designate API timeout
35+
APITimeout = 120
3236
)
3337

3438
// DesignateAPISpecCore - this version has no containerImage for use with the OpenStackControlplane
@@ -186,6 +190,11 @@ type DesignateSpecBase struct {
186190
// +kubebuilder:default="designate-redis"
187191
// RedisServiceName is the name of the Redis instance to be used (must be in the same namespace as designate)
188192
RedisServiceName string `json:"redisServiceName"`
193+
194+
// +kubebuilder:validation:Optional
195+
// +kubebuilder:default=120
196+
// Designate API timeout
197+
APITimeout int `json:"apiTimeout"`
189198
}
190199

191200
// DesignateStatus defines the observed state of Designate
@@ -277,6 +286,24 @@ func (instance Designate) IsReady() bool {
277286
unboundReady
278287
}
279288

289+
// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks)
290+
func SetupDefaults() {
291+
// Acquire environmental defaults and initialize Designate defaults with them
292+
designateDefaults := DesignateDefaults{
293+
APIContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_API_IMAGE_URL_DEFAULT", DesignateAPIContainerImage),
294+
CentralContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_CENTRAL_IMAGE_URL_DEFAULT", DesignateCentralContainerImage),
295+
MdnsContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_MDNS_IMAGE_URL_DEFAULT", DesignateMdnsContainerImage),
296+
ProducerContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_PRODUCER_IMAGE_URL_DEFAULT", DesignateProducerContainerImage),
297+
WorkerContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_WORKER_IMAGE_URL_DEFAULT", DesignateWorkerContainerImage),
298+
UnboundContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_UNBOUND_IMAGE_URL_DEFAULT", DesignateUnboundContainerImage),
299+
Backendbind9ContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_BACKENDBIND9_IMAGE_URL_DEFAULT", DesignateBackendbind9ContainerImage),
300+
DesignateAPIRouteTimeout: APITimeout,
301+
}
302+
303+
SetupDesignateDefaults(designateDefaults)
304+
}
305+
306+
280307
// DesignateExtraVolMounts exposes additional parameters processed by the designate-operator
281308
// and defines the common VolMounts structure provided by the main storage module
282309
type DesignateExtraVolMounts struct {

api/v1beta1/designate_webhook.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type DesignateDefaults struct {
4444
WorkerContainerImageURL string
4545
Backendbind9ContainerImageURL string
4646
UnboundContainerImageURL string
47+
DesignateAPIRouteTimeout int
4748
}
4849

4950
var designateDefaults DesignateDefaults
@@ -207,3 +208,35 @@ func (r *Designate) ValidateDelete() (admission.Warnings, error) {
207208
// TODO(user): fill in your validation logic upon object deletion.
208209
return nil, nil
209210
}
211+
212+
func (spec *DesignateSpecCore) GetDefaultRouteAnnotations() (annotations map[string]string) {
213+
return map[string]string{
214+
"haproxy.router.openshift.io/timeout": fmt.Sprintf("%ds", designateDefaults.DesignateAPIRouteTimeout),
215+
}
216+
}
217+
218+
// SetDefaultRouteAnnotations sets HAProxy timeout values of the route
219+
func (spec *DesignateSpecCore) SetDefaultRouteAnnotations(annotations map[string]string) {
220+
const haProxyAnno = "haproxy.router.openshift.io/timeout"
221+
// Use a custom annotation to flag when the operator has set the default HAProxy timeout
222+
// With the annotation func determines when to overwrite existing HAProxy timeout with the APITimeout
223+
const designateAnno = "api.designate.openstack.org/timeout"
224+
225+
valDesignate, okDesignate := annotations[designateAnno]
226+
valHAProxy, okHAProxy := annotations[haProxyAnno]
227+
228+
// Human operator set the HAProxy timeout manually
229+
if !okDesignate && okHAProxy {
230+
return
231+
}
232+
233+
// Human operator modified the HAProxy timeout manually without removing the Designate flag
234+
if okDesignate && okHAProxy && valDesignate != valHAProxy {
235+
delete(annotations, designateAnno)
236+
return
237+
}
238+
239+
timeout := fmt.Sprintf("%ds", spec.APITimeout)
240+
annotations[designateAnno] = timeout
241+
annotations[haProxyAnno] = timeout
242+
}

api/v1beta1/designateapi_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ type DesignateAPISpecBase struct {
7878
// +operator-sdk:csv:customresourcedefinitions:type=spec
7979
// TLS - Parameters related to the TLS
8080
TLS tls.API `json:"tls,omitempty"`
81+
82+
// +kubebuilder:validation:Optional
83+
// APITimeout for HAProxy and Apache defaults to DesignateSpecCore APITimeout (seconds)
84+
APITimeout int `json:"apiTimeout"`
8185
}
8286

8387
// APIOverrideSpec to override the generated manifest of several child resources.

config/crd/bases/designate.openstack.org_designateapis.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ spec:
4848
spec:
4949
description: DesignateAPISpec defines the desired state of DesignateAPI
5050
properties:
51+
apiTimeout:
52+
description: APITimeout for HAProxy and Apache defaults to DesignateSpecCore
53+
APITimeout (seconds)
54+
type: integer
5155
backendMdnsServerProtocol:
5256
description: 'BackendTypeProtocol - Defines the backend protocol to
5357
be used between the designate-worker & designate_mdns to/from the

config/crd/bases/designate.openstack.org_designates.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ spec:
4444
spec:
4545
description: DesignateAPISpec defines the desired state of DesignateAPI
4646
properties:
47+
apiTimeout:
48+
default: 120
49+
description: Designate API timeout
50+
type: integer
4751
backendMdnsServerProtocol:
4852
description: 'BackendTypeProtocol - Defines the backend protocol to
4953
be used between the designate-worker & designate_mdns to/from the
@@ -91,6 +95,10 @@ spec:
9195
description: DesignateAPI - Spec definition for the API service of
9296
this Designate deployment
9397
properties:
98+
apiTimeout:
99+
description: APITimeout for HAProxy and Apache defaults to DesignateSpecCore
100+
APITimeout (seconds)
101+
type: integer
94102
backendMdnsServerProtocol:
95103
description: 'BackendTypeProtocol - Defines the backend protocol
96104
to be used between the designate-worker & designate_mdns to/from

controllers/designate_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,7 @@ func (r *DesignateReconciler) apiDeploymentCreateOrUpdate(ctx context.Context, i
14881488
deployment.Spec.TLS = instance.Spec.DesignateAPI.TLS
14891489
deployment.Spec.TransportURLSecret = instance.Status.TransportURLSecret
14901490
deployment.Spec.NodeSelector = instance.Spec.DesignateAPI.NodeSelector
1491+
deployment.Spec.APITimeout = instance.Spec.APITimeout
14911492

14921493
err := controllerutil.SetControllerReference(instance, deployment, r.Scheme)
14931494
if err != nil {

controllers/designateapi_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,7 @@ func (r *DesignateAPIReconciler) generateServiceConfigMaps(
11031103
templateParameters["ServiceUser"] = instance.Spec.ServiceUser
11041104
templateParameters["KeystoneInternalURL"] = keystoneInternalURL
11051105
templateParameters["KeystonePublicURL"] = keystonePublicURL
1106+
templateParameters["TimeOut"] = instance.Spec.APITimeout
11061107

11071108
// create httpd vhost template parameters
11081109
httpdVhostConfig := map[string]interface{}{}

0 commit comments

Comments
 (0)