Skip to content

Commit

Permalink
[Issue kubernetes#28] Add timeout to the BackendConfig
Browse files Browse the repository at this point in the history
This commits adds a new Connection section to the BackendConfig that
enables setting the timeout.
  • Loading branch information
Alex Van Boxel committed Oct 12, 2018
1 parent d6a9498 commit 1b5527d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/apis/backendconfig/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"`
}
25 changes: 25 additions & 0 deletions pkg/apis/backendconfig/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion pkg/apis/backendconfig/v1beta1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions pkg/backends/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1b5527d

Please sign in to comment.