Skip to content

Commit

Permalink
Merge pull request #258 from omersch381/add_httpd_timeout
Browse files Browse the repository at this point in the history
Add configurable httpd timeout
  • Loading branch information
openshift-merge-bot[bot] authored Jan 8, 2025
2 parents d22c227 + 7431e44 commit 5796070
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 17 deletions.
4 changes: 4 additions & 0 deletions api/bases/designate.openstack.org_designateapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ spec:
spec:
description: DesignateAPISpec defines the desired state of DesignateAPI
properties:
apiTimeout:
description: APITimeout for HAProxy and Apache defaults to DesignateSpecCore
APITimeout (seconds)
type: integer
backendMdnsServerProtocol:
description: |-
BackendTypeProtocol - Defines the backend protocol to be used between the designate-worker &
Expand Down
8 changes: 8 additions & 0 deletions api/bases/designate.openstack.org_designates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
spec:
description: DesignateAPISpec defines the desired state of DesignateAPI
properties:
apiTimeout:
default: 120
description: Designate API timeout
type: integer
backendMdnsServerProtocol:
description: |-
BackendTypeProtocol - Defines the backend protocol to be used between the designate-worker &
Expand Down Expand Up @@ -95,6 +99,10 @@ spec:
description: DesignateAPI - Spec definition for the API service of
this Designate deployment
properties:
apiTimeout:
description: APITimeout for HAProxy and Apache defaults to DesignateSpecCore
APITimeout (seconds)
type: integer
backendMdnsServerProtocol:
description: |-
BackendTypeProtocol - Defines the backend protocol to be used between the designate-worker &
Expand Down
17 changes: 0 additions & 17 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package v1beta1

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

Expand Down Expand Up @@ -133,19 +132,3 @@ type PasswordSelector struct {
// Service - Selector to get the designate service password from the Secret
Service string `json:"service"`
}

// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks)
func SetupDefaults() {
// Acquire environmental defaults and initialize Designate defaults with them
designateDefaults := DesignateDefaults{
APIContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_API_IMAGE_URL_DEFAULT", DesignateAPIContainerImage),
CentralContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_CENTRAL_IMAGE_URL_DEFAULT", DesignateCentralContainerImage),
MdnsContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_MDNS_IMAGE_URL_DEFAULT", DesignateMdnsContainerImage),
ProducerContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_PRODUCER_IMAGE_URL_DEFAULT", DesignateProducerContainerImage),
WorkerContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_WORKER_IMAGE_URL_DEFAULT", DesignateWorkerContainerImage),
UnboundContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_UNBOUND_IMAGE_URL_DEFAULT", DesignateUnboundContainerImage),
Backendbind9ContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_BACKENDBIND9_IMAGE_URL_DEFAULT", DesignateBackendbind9ContainerImage),
}

SetupDesignateDefaults(designateDefaults)
}
27 changes: 27 additions & 0 deletions api/v1beta1/designate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1beta1

import (
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
"github.com/openstack-k8s-operators/lib-common/modules/storage"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -29,6 +30,9 @@ const (

// DeploymentHash hash used to detect changes
DeploymentHash = "deployment"

// Designate API timeout
APITimeout = 120
)

// DesignateAPISpecCore - this version has no containerImage for use with the OpenStackControlplane
Expand Down Expand Up @@ -186,6 +190,11 @@ type DesignateSpecBase struct {
// +kubebuilder:default="designate-redis"
// RedisServiceName is the name of the Redis instance to be used (must be in the same namespace as designate)
RedisServiceName string `json:"redisServiceName"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=120
// Designate API timeout
APITimeout int `json:"apiTimeout"`
}

// DesignateStatus defines the observed state of Designate
Expand Down Expand Up @@ -277,6 +286,24 @@ func (instance Designate) IsReady() bool {
unboundReady
}

// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks)
func SetupDefaults() {
// Acquire environmental defaults and initialize Designate defaults with them
designateDefaults := DesignateDefaults{
APIContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_API_IMAGE_URL_DEFAULT", DesignateAPIContainerImage),
CentralContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_CENTRAL_IMAGE_URL_DEFAULT", DesignateCentralContainerImage),
MdnsContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_MDNS_IMAGE_URL_DEFAULT", DesignateMdnsContainerImage),
ProducerContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_PRODUCER_IMAGE_URL_DEFAULT", DesignateProducerContainerImage),
WorkerContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_WORKER_IMAGE_URL_DEFAULT", DesignateWorkerContainerImage),
UnboundContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_UNBOUND_IMAGE_URL_DEFAULT", DesignateUnboundContainerImage),
Backendbind9ContainerImageURL: util.GetEnvVar("RELATED_IMAGE_DESIGNATE_BACKENDBIND9_IMAGE_URL_DEFAULT", DesignateBackendbind9ContainerImage),
DesignateAPIRouteTimeout: APITimeout,
}

SetupDesignateDefaults(designateDefaults)
}


// DesignateExtraVolMounts exposes additional parameters processed by the designate-operator
// and defines the common VolMounts structure provided by the main storage module
type DesignateExtraVolMounts struct {
Expand Down
33 changes: 33 additions & 0 deletions api/v1beta1/designate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type DesignateDefaults struct {
WorkerContainerImageURL string
Backendbind9ContainerImageURL string
UnboundContainerImageURL string
DesignateAPIRouteTimeout int
}

var designateDefaults DesignateDefaults
Expand Down Expand Up @@ -207,3 +208,35 @@ func (r *Designate) ValidateDelete() (admission.Warnings, error) {
// TODO(user): fill in your validation logic upon object deletion.
return nil, nil
}

func (spec *DesignateSpecCore) GetDefaultRouteAnnotations() (annotations map[string]string) {
return map[string]string{
"haproxy.router.openshift.io/timeout": fmt.Sprintf("%ds", designateDefaults.DesignateAPIRouteTimeout),
}
}

// SetDefaultRouteAnnotations sets HAProxy timeout values of the route
func (spec *DesignateSpecCore) 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 designateAnno = "api.designate.openstack.org/timeout"

valDesignate, okDesignate := annotations[designateAnno]
valHAProxy, okHAProxy := annotations[haProxyAnno]

// Human operator set the HAProxy timeout manually
if !okDesignate && okHAProxy {
return
}

// Human operator modified the HAProxy timeout manually without removing the Designate flag
if okDesignate && okHAProxy && valDesignate != valHAProxy {
delete(annotations, designateAnno)
return
}

timeout := fmt.Sprintf("%ds", spec.APITimeout)
annotations[designateAnno] = timeout
annotations[haProxyAnno] = timeout
}
4 changes: 4 additions & 0 deletions api/v1beta1/designateapi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ type DesignateAPISpecBase struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec
// TLS - Parameters related to the TLS
TLS tls.API `json:"tls,omitempty"`

// +kubebuilder:validation:Optional
// APITimeout for HAProxy and Apache defaults to DesignateSpecCore APITimeout (seconds)
APITimeout int `json:"apiTimeout"`
}

// APIOverrideSpec to override the generated manifest of several child resources.
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/designate.openstack.org_designateapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ spec:
spec:
description: DesignateAPISpec defines the desired state of DesignateAPI
properties:
apiTimeout:
description: APITimeout for HAProxy and Apache defaults to DesignateSpecCore
APITimeout (seconds)
type: integer
backendMdnsServerProtocol:
description: |-
BackendTypeProtocol - Defines the backend protocol to be used between the designate-worker &
Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/designate.openstack.org_designates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
spec:
description: DesignateAPISpec defines the desired state of DesignateAPI
properties:
apiTimeout:
default: 120
description: Designate API timeout
type: integer
backendMdnsServerProtocol:
description: |-
BackendTypeProtocol - Defines the backend protocol to be used between the designate-worker &
Expand Down Expand Up @@ -95,6 +99,10 @@ spec:
description: DesignateAPI - Spec definition for the API service of
this Designate deployment
properties:
apiTimeout:
description: APITimeout for HAProxy and Apache defaults to DesignateSpecCore
APITimeout (seconds)
type: integer
backendMdnsServerProtocol:
description: |-
BackendTypeProtocol - Defines the backend protocol to be used between the designate-worker &
Expand Down
1 change: 1 addition & 0 deletions controllers/designate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,7 @@ func (r *DesignateReconciler) apiDeploymentCreateOrUpdate(ctx context.Context, i
deployment.Spec.TLS = instance.Spec.DesignateAPI.TLS
deployment.Spec.TransportURLSecret = instance.Status.TransportURLSecret
deployment.Spec.NodeSelector = instance.Spec.DesignateAPI.NodeSelector
deployment.Spec.APITimeout = instance.Spec.APITimeout

err := controllerutil.SetControllerReference(instance, deployment, r.Scheme)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions controllers/designateapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ func (r *DesignateAPIReconciler) generateServiceConfigMaps(
templateParameters["ServiceUser"] = instance.Spec.ServiceUser
templateParameters["KeystoneInternalURL"] = keystoneInternalURL
templateParameters["KeystonePublicURL"] = keystonePublicURL
templateParameters["TimeOut"] = instance.Spec.APITimeout

// create httpd vhost template parameters
httpdVhostConfig := map[string]interface{}{}
Expand Down
2 changes: 2 additions & 0 deletions templates/designateapi/config/httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
CustomLog /dev/stdout combined env=!forwarded
CustomLog /dev/stdout proxy env=forwarded

TimeOut {{ $.TimeOut }}

{{ range $endpt, $vhost := .VHosts }}
# {{ $endpt }} vhost {{ $vhost.ServerName }} configuration
<VirtualHost *:9001>
Expand Down

0 comments on commit 5796070

Please sign in to comment.