Skip to content

Commit 7873da0

Browse files
Merge pull request #381 from cschwede/apitimeout
Add configurable API Timeouts
2 parents 8f86f5f + 021ddf6 commit 7873da0

File tree

10 files changed

+68
-0
lines changed

10 files changed

+68
-0
lines changed

api/bases/swift.openstack.org_swiftproxies.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ spec:
5252
spec:
5353
description: SwiftProxySpec defines the desired state of SwiftProxy
5454
properties:
55+
apiTimeout:
56+
default: 60
57+
description: Default APITimeout for HAProxy and Apache, defaults to
58+
60 seconds
59+
minimum: 1
60+
type: integer
5561
ceilometerEnabled:
5662
default: false
5763
description: Enables ceilometer in the swift proxy and creates required

api/bases/swift.openstack.org_swifts.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ spec:
8686
description: SwiftProxy - Spec definition for the Proxy service of
8787
this Swift deployment
8888
properties:
89+
apiTimeout:
90+
default: 60
91+
description: Default APITimeout for HAProxy and Apache, defaults
92+
to 60 seconds
93+
minimum: 1
94+
type: integer
8995
ceilometerEnabled:
9096
default: false
9197
description: Enables ceilometer in the swift proxy and creates

api/v1beta1/swift_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const (
2929
ContainerImageContainer = "quay.io/podified-antelope-centos9/openstack-swift-container:current-podified"
3030
ContainerImageObject = "quay.io/podified-antelope-centos9/openstack-swift-object:current-podified"
3131
ContainerImageProxy = "quay.io/podified-antelope-centos9/openstack-swift-proxy-server:current-podified"
32+
33+
// ProxyAPITimeoutDefault - Default timeout in seconds for HAProxy and Apache
34+
ProxyAPITimeout = 60
3235
)
3336

3437
// SwiftSpec defines the desired state of Swift

api/v1beta1/swift_webhook.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type SwiftDefaults struct {
3737
ContainerContainerImageURL string
3838
ObjectContainerImageURL string
3939
ProxyContainerImageURL string
40+
ProxyAPITimeout int
4041
}
4142

4243
var swiftDefaults SwiftDefaults
@@ -100,6 +101,10 @@ func (spec *SwiftSpec) Default() {
100101
if spec.SwiftProxy.ContainerImageProxy == "" {
101102
spec.SwiftProxy.ContainerImageProxy = swiftDefaults.ProxyContainerImageURL
102103
}
104+
105+
if spec.SwiftProxy.APITimeout == 0 {
106+
spec.SwiftProxy.APITimeout = swiftDefaults.ProxyAPITimeout
107+
}
103108
}
104109

105110
// Default - set defaults for this Swift core spec (this version is used by OpenStackControlplane webhooks)
@@ -312,3 +317,29 @@ func (spec *SwiftSpec) ValidateSwiftTopology(basePath *field.Path, namespace str
312317

313318
return allErrs
314319
}
320+
321+
// SetDefaultRouteAnnotations sets HAProxy timeout values of the route
322+
func (spec *SwiftSpecCore) SetDefaultRouteAnnotations(annotations map[string]string) {
323+
const haProxyAnno = "haproxy.router.openshift.io/timeout"
324+
// Use a custom annotation to flag when the operator has set the default HAProxy timeout
325+
// With the annotation func determines when to overwrite existing HAProxy timeout with the APITimeout
326+
const swiftAnno = "api.swift.openstack.org/timeout"
327+
328+
valSwift, okSwift := annotations[swiftAnno]
329+
valHAProxy, okHAProxy := annotations[haProxyAnno]
330+
331+
// Human operator set the HAProxy timeout manually
332+
if !okSwift && okHAProxy {
333+
return
334+
}
335+
336+
// Human operator modified the HAProxy timeout manually without removing the Swift flag
337+
if okSwift && okHAProxy && valSwift != valHAProxy {
338+
delete(annotations, swiftAnno)
339+
return
340+
}
341+
342+
timeout := fmt.Sprintf("%ds", spec.SwiftProxy.APITimeout)
343+
annotations[swiftAnno] = timeout
344+
annotations[haProxyAnno] = timeout
345+
}

api/v1beta1/swiftproxy_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ type SwiftProxySpecCore struct {
113113
// by name
114114
TopologyRef *topologyv1.TopoRef `json:"topologyRef,omitempty"`
115115

116+
// +kubebuilder:default=60
117+
// +kubebuilder:validation:Minimum=1
118+
// Default APITimeout for HAProxy and Apache, defaults to 60 seconds
119+
APITimeout int `json:"apiTimeout,omitempty"`
120+
116121
// +kubebuilder:validation:Optional
117122
// +kubebuilder:default={swift-ring-files}
118123
// +listType=atomic

config/crd/bases/swift.openstack.org_swiftproxies.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ spec:
5252
spec:
5353
description: SwiftProxySpec defines the desired state of SwiftProxy
5454
properties:
55+
apiTimeout:
56+
default: 60
57+
description: Default APITimeout for HAProxy and Apache, defaults to
58+
60 seconds
59+
minimum: 1
60+
type: integer
5561
ceilometerEnabled:
5662
default: false
5763
description: Enables ceilometer in the swift proxy and creates required

config/crd/bases/swift.openstack.org_swifts.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ spec:
8686
description: SwiftProxy - Spec definition for the Proxy service of
8787
this Swift deployment
8888
properties:
89+
apiTimeout:
90+
default: 60
91+
description: Default APITimeout for HAProxy and Apache, defaults
92+
to 60 seconds
93+
minimum: 1
94+
type: integer
8995
ceilometerEnabled:
9096
default: false
9197
description: Enables ceilometer in the swift proxy and creates

controllers/swiftproxy_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ func (r *SwiftProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
582582
secretRef,
583583
os.GetRegion(),
584584
transportURLString,
585+
instance.Spec.APITimeout,
585586
)
586587
err = secret.EnsureSecrets(ctx, helper, instance, tpl, &envVars)
587588
if err != nil {

pkg/swiftproxy/templates.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func SecretTemplates(
3838
secretRef string,
3939
keystoneRegion string,
4040
transportURL string,
41+
apiTimeout int,
4142
) []util.Template {
4243
templateParameters := make(map[string]interface{})
4344
templateParameters["ServiceUser"] = instance.Spec.ServiceUser
@@ -50,6 +51,7 @@ func SecretTemplates(
5051
templateParameters["SecretRef"] = secretRef
5152
templateParameters["KeystoneRegion"] = keystoneRegion
5253
templateParameters["TransportURL"] = transportURL
54+
templateParameters["APITimeout"] = apiTimeout
5355

5456
// MTLS params
5557
if mc.Status.MTLSCert != "" {

templates/swiftproxy/config/httpd.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
2222
CustomLog /dev/stdout combined env=!forwarded
2323
CustomLog /dev/stdout proxy env=forwarded
2424

25+
TimeOut {{ .APITimeout }}
26+
2527
{{ range $endpt, $vhost := .VHosts }}
2628
# {{ $endpt }} vhost {{ $vhost.ServerName }} configuration
2729
<VirtualHost *:8080>

0 commit comments

Comments
 (0)