From 1b5527d9ee85cffba3ff72ef06f3e590204ebc38 Mon Sep 17 00:00:00 2001 From: Alex Van Boxel Date: Fri, 12 Oct 2018 17:40:22 +0200 Subject: [PATCH] [Issue #28] Add timeout to the BackendConfig This commits adds a new Connection section to the BackendConfig that enables setting the timeout. --- pkg/apis/backendconfig/v1beta1/types.go | 6 +++++ .../v1beta1/zz_generated.deepcopy.go | 25 +++++++++++++++++++ .../v1beta1/zz_generated.openapi.go | 7 +++++- pkg/backends/syncer.go | 13 ++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/pkg/apis/backendconfig/v1beta1/types.go b/pkg/apis/backendconfig/v1beta1/types.go index b65a291cd4..c36da45145 100644 --- a/pkg/apis/backendconfig/v1beta1/types.go +++ b/pkg/apis/backendconfig/v1beta1/types.go @@ -39,6 +39,7 @@ type BackendConfigSpec struct { Iap *IAPConfig `json:"iap,omitempty"` Cdn *CDNConfig `json:"cdn,omitempty"` SecurityPolicy *SecurityPolicyConfig `json:"securityPolicy,omitempty"` + Connection *ConnectionConfig `json:"connection,omitempty"` } // BackendConfigStatus is the status for a BackendConfig resource @@ -107,3 +108,8 @@ type SecurityPolicyConfig struct { // Name of the security policy that should be associated. Name string `json:"name"` } + +// ConnectionConfig contains configuration the timeout for the backends. +type ConnectionConfig struct { + Timeout int64 `json:"timeout,omitempty"` +} diff --git a/pkg/apis/backendconfig/v1beta1/zz_generated.deepcopy.go b/pkg/apis/backendconfig/v1beta1/zz_generated.deepcopy.go index a441f963cb..07ccf1415d 100644 --- a/pkg/apis/backendconfig/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/backendconfig/v1beta1/zz_generated.deepcopy.go @@ -115,6 +115,15 @@ func (in *BackendConfigSpec) DeepCopyInto(out *BackendConfigSpec) { **out = **in } } + if in.Connection != nil { + in, out := &in.Connection, &out.Connection + if *in == nil { + *out = nil + } else { + *out = new(ConnectionConfig) + **out = **in + } + } return } @@ -195,6 +204,22 @@ func (in *CacheKeyPolicy) DeepCopy() *CacheKeyPolicy { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ConnectionConfig) DeepCopyInto(out *ConnectionConfig) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConnectionConfig. +func (in *ConnectionConfig) DeepCopy() *ConnectionConfig { + if in == nil { + return nil + } + out := new(ConnectionConfig) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *IAPConfig) DeepCopyInto(out *IAPConfig) { *out = *in diff --git a/pkg/apis/backendconfig/v1beta1/zz_generated.openapi.go b/pkg/apis/backendconfig/v1beta1/zz_generated.openapi.go index 5b47bacbe4..9a567d9416 100644 --- a/pkg/apis/backendconfig/v1beta1/zz_generated.openapi.go +++ b/pkg/apis/backendconfig/v1beta1/zz_generated.openapi.go @@ -88,11 +88,16 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA Ref: ref("k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1.SecurityPolicyConfig"), }, }, + "connection": { + SchemaProps: spec.SchemaProps{ + Ref: ref("k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1.ConnectionConfig"), + }, + }, }, }, }, Dependencies: []string{ - "k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1.CDNConfig", "k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1.IAPConfig", "k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1.SecurityPolicyConfig"}, + "k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1.CDNConfig", "k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1.ConnectionConfig", "k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1.IAPConfig", "k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1.SecurityPolicyConfig"}, }, "k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1.CDNConfig": { Schema: spec.Schema{ diff --git a/pkg/backends/syncer.go b/pkg/backends/syncer.go index d94841e469..04a19da9de 100644 --- a/pkg/backends/syncer.go +++ b/pkg/backends/syncer.go @@ -107,6 +107,7 @@ func (s *backendSyncer) ensureBackendService(sp utils.ServicePort) error { } needUpdate := ensureProtocol(be, sp) + needUpdate = ensureTimeout(be, sp) needUpdate = ensureHealthCheckLink(be, hcLink) || needUpdate needUpdate = ensureDescription(be, &sp) || needUpdate if s.backendConfigEnabled && sp.BackendConfig != nil { @@ -203,6 +204,18 @@ func ensureProtocol(be *composite.BackendService, p utils.ServicePort) (needsUpd return true } +// ensureProtocol updates the BackendService Timeout with the expected value +func ensureTimeout(be *composite.BackendService, p utils.ServicePort) (needsUpdate bool) { + if p.BackendConfig.Spec.Connection == nil { + return false + } + if be.TimeoutSec == p.BackendConfig.Spec.Connection.Timeout { + return false + } + be.TimeoutSec = p.BackendConfig.Spec.Connection.Timeout + return true +} + // ensureHealthCheckLink updates the BackendService HealthCheck with the expected value func ensureHealthCheckLink(be *composite.BackendService, hcLink string) (needsUpdate bool) { existingHCLink := getHealthCheckLink(be)