Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/reference/load_balancer_annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This page contains all annotations, which can be specified at a Service of type

- Read-only annotations are set by the Cloud Controller Manager.
- Enums are depicted in the `Type` column and possible options are separated via the pipe symbol `|`.
- The `duration` type is a Go duration string, i.e. a sequence of decimal numbers each with a unit suffix such as `300ms`, `30s`, `5m` or `1h` (see [`time.ParseDuration`](https://pkg.go.dev/time#ParseDuration)).

| Name | Type | Default | Read-only | Description |
| --- | --- | --- | --- | --- |
Expand All @@ -28,6 +29,7 @@ This page contains all annotations, which can be specified at a Service of type
| `load-balancer.hetzner.cloud/uses-proxyprotocol` | `bool` | `false` | `No` | Specifies if the Load Balancer services should use the proxy protocol. |
| `load-balancer.hetzner.cloud/http-cookie-name` | `string` | `-` | `No` | Specifies the cookie name when using HTTP or HTTPS as protocol. |
| `load-balancer.hetzner.cloud/http-cookie-lifetime` | `int` | `-` | `No` | Specifies the lifetime of the HTTP cookie. |
| `load-balancer.hetzner.cloud/http-timeout-idle` | `duration` | `-` | `No` | Specifies the idle timeout for the client and server side. |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we document the allowed range for this value?

| `load-balancer.hetzner.cloud/certificate-type` | `uploaded \| managed` | `uploaded` | `No` | Defines the type of certificate the Load Balancer should use. |
| `load-balancer.hetzner.cloud/http-certificates` | `string` | `-` | `No` | A comma separated list of IDs or Names of Certificates assigned to the service. |
| `load-balancer.hetzner.cloud/http-managed-certificate-name` | `string` | `-` | `No` | Contains the name of the managed certificate to create by the Cloud Controller manager. Ignored if `load-balancer.hetzner.cloud/certificate-type` is missing or set to "uploaded". |
Expand Down
6 changes: 6 additions & 0 deletions internal/annotation/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ const (
// Type: int
LBSvcHTTPCookieLifetime Name = "load-balancer.hetzner.cloud/http-cookie-lifetime"

// LBSvcHTTPTimeoutIdle specifies the idle timeout for the client and
// server side.
//
// Type: duration
LBSvcHTTPTimeoutIdle Name = "load-balancer.hetzner.cloud/http-timeout-idle"

// LBSvcHTTPCertificateType defines the type of certificate the Load
// Balancer should use.
//
Expand Down
16 changes: 16 additions & 0 deletions internal/hcops/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ type hclbServiceOptsBuilder struct {
Certificates []*hcloud.Certificate
RedirectHTTP *bool
StickySessions *bool
TimeoutIdle *time.Duration
}
addHTTP bool
healthCheckOpts struct {
Expand Down Expand Up @@ -1115,6 +1116,19 @@ func (b *hclbServiceOptsBuilder) extract() {
return nil
})

b.do(func() error {
timeout, err := annotation.LBSvcHTTPTimeoutIdle.DurationFromService(b.Service)
if errors.Is(err, annotation.ErrNotSet) {
return nil
}
if err != nil {
return fmt.Errorf("%s: %w", op, err)
}
b.httpOpts.TimeoutIdle = &timeout
b.addHTTP = true
return nil
})

b.do(func() error {
certtyp, ok := annotation.LBSvcHTTPCertificateType.StringFromService(b.Service)
if ok && certtyp == string(hcloud.CertificateTypeManaged) {
Expand Down Expand Up @@ -1367,6 +1381,7 @@ func (b *hclbServiceOptsBuilder) buildAddServiceOpts() (hcloud.LoadBalancerAddSe
Certificates: b.httpOpts.Certificates,
RedirectHTTP: b.httpOpts.RedirectHTTP,
StickySessions: b.httpOpts.StickySessions,
TimeoutIdle: b.httpOpts.TimeoutIdle,
}
}
if b.addHealthCheck {
Expand Down Expand Up @@ -1421,6 +1436,7 @@ func (b *hclbServiceOptsBuilder) buildUpdateServiceOpts() (hcloud.LoadBalancerUp
RedirectHTTP: b.httpOpts.RedirectHTTP,
Certificates: b.httpOpts.Certificates,
StickySessions: b.httpOpts.StickySessions,
TimeoutIdle: b.httpOpts.TimeoutIdle,
}
}
if b.addHealthCheck {
Expand Down
3 changes: 3 additions & 0 deletions internal/hcops/load_balancer_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func TestHCLBServiceOptsBuilder(t *testing.T) {
annotation.LBSvcHTTPCertificates: "1,3",
annotation.LBSvcRedirectHTTP: "true",
annotation.LBSvcHTTPStickySessions: "true",
annotation.LBSvcHTTPTimeoutIdle: "30s",
},
expectedAddOpts: hcloud.LoadBalancerAddServiceOpts{
ListenPort: new(82),
Expand All @@ -131,6 +132,7 @@ func TestHCLBServiceOptsBuilder(t *testing.T) {
Certificates: []*hcloud.Certificate{{ID: 1}, {ID: 3}},
RedirectHTTP: new(true),
StickySessions: new(true),
TimeoutIdle: hcloud.Ptr(30 * time.Second),
},
HealthCheck: &hcloud.LoadBalancerAddServiceOptsHealthCheck{
Protocol: hcloud.LoadBalancerServiceProtocolTCP,
Expand All @@ -146,6 +148,7 @@ func TestHCLBServiceOptsBuilder(t *testing.T) {
Certificates: []*hcloud.Certificate{{ID: 1}, {ID: 3}},
RedirectHTTP: new(true),
StickySessions: new(true),
TimeoutIdle: hcloud.Ptr(30 * time.Second),
},
HealthCheck: &hcloud.LoadBalancerUpdateServiceOptsHealthCheck{
Protocol: hcloud.LoadBalancerServiceProtocolTCP,
Expand Down
1 change: 1 addition & 0 deletions tools/load_balancer_annotations.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ This page contains all annotations, which can be specified at a Service of type

- Read-only annotations are set by the Cloud Controller Manager.
- Enums are depicted in the `Type` column and possible options are separated via the pipe symbol `|`.
- The `duration` type is a Go duration string, i.e. a sequence of decimal numbers each with a unit suffix such as `300ms`, `30s`, `5m` or `1h` (see [`time.ParseDuration`](https://pkg.go.dev/time#ParseDuration)).

{{.ConstTable}}
Loading