Skip to content

Commit

Permalink
ingress: control default timeout for ingress listners
Browse files Browse the repository at this point in the history
Signed-off-by: a5r0n <a5r0n@users.noreply.github.com>
  • Loading branch information
a5r0n authored and youngnick committed May 7, 2024
1 parent 3d1efae commit ed65b5d
Show file tree
Hide file tree
Showing 23 changed files with 355 additions and 36 deletions.
1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator-alibabacloud.md

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

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator-alibabacloud_hive.md

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

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

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator-aws.md

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

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator-aws_hive.md

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

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator-aws_hive_dot-graph.md

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

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator-azure.md

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

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator-azure_hive.md

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

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

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator-generic.md

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

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator-generic_hive.md

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

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

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator.md

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

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator_hive.md

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

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator_hive_dot-graph.md

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

18 changes: 18 additions & 0 deletions operator/pkg/ingress/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
package annotations

import (
"fmt"
"strconv"
"time"

corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
Expand All @@ -21,6 +23,7 @@ const (
HostListenerPortAnnotation = annotation.IngressPrefix + "/host-listener-port"
TLSPassthroughAnnotation = annotation.IngressPrefix + "/tls-passthrough"
ForceHTTPSAnnotation = annotation.IngressPrefix + "/force-https"
RequestTimeoutAnnotation = annotation.IngressPrefix + "/request-timeout"

LBModeAnnotationAlias = annotation.Prefix + ".ingress" + "/loadbalancer-mode"
ServiceTypeAnnotationAlias = annotation.Prefix + ".ingress" + "/service-type"
Expand Down Expand Up @@ -60,6 +63,21 @@ func GetAnnotationServiceType(ingress *networkingv1.Ingress) string {
return val
}

// GetAnnotationRequestTimeout retrieves the RequestTimeout annotation's value.
func GetAnnotationRequestTimeout(ingress *networkingv1.Ingress) (*time.Duration, error) {
val, exists := annotation.Get(ingress, RequestTimeoutAnnotation)
if !exists {
return nil, nil
}

d, err := time.ParseDuration(val)
if err != nil {
return nil, fmt.Errorf("failed to parse duration %q: %w", val, err)
}

return &d, nil
}

// GetAnnotationSecureNodePort returns the secure node port for the ingress if possible.
func GetAnnotationSecureNodePort(ingress *networkingv1.Ingress) (*uint32, error) {
val, exists := annotation.Get(ingress, SecureNodePortAnnotation, SecureNodePortAnnotationAlias)
Expand Down
63 changes: 63 additions & 0 deletions operator/pkg/ingress/annotations/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package annotations
import (
"reflect"
"testing"
"time"

networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -65,6 +66,68 @@ func TestGetAnnotationServiceType(t *testing.T) {
}
}

func TestGetAnnotationRequestTimeout(t *testing.T) {
type args struct {
ingress *networkingv1.Ingress
}

tests := []struct {
name string
args args
want *time.Duration
wantErr bool
}{
{
name: "no request timeout annotation",
args: args{
ingress: &networkingv1.Ingress{},
},
want: nil,
},
{
name: "request timeout annotation with valid value",
args: args{
ingress: &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
RequestTimeoutAnnotation: "10s",
},
},
},
},
want: model.AddressOf(time.Second * 10),
},
{
name: "request timeout annotation with invalid value",
args: args{
ingress: &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
RequestTimeoutAnnotation: "invalid",
},
},
},
},
want: nil,
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := GetAnnotationRequestTimeout(tt.args.ingress)
if (err != nil) != tt.wantErr {
t.Errorf("GetAnnotationRequestTimeout() error = %v, wantErr %v", err, tt.wantErr)
return
}

if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetAnnotationRequestTimeout() got = %v, want %v", got, tt.want)
}
})
}
}

func TestGetAnnotationSecureNodePort(t *testing.T) {
type args struct {
ingress *networkingv1.Ingress
Expand Down

0 comments on commit ed65b5d

Please sign in to comment.