11//
22// DISCLAIMER
33//
4- // Copyright 2024 ArangoDB GmbH, Cologne, Germany
4+ // Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
55//
66// Licensed under the Apache License, Version 2.0 (the "License");
77// you may not use this file except in compliance with the License.
2121package v1
2222
2323import (
24+ meta "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
26+ shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
2427 "github.com/arangodb/kube-arangodb/pkg/util"
28+ "github.com/arangodb/kube-arangodb/pkg/util/constants"
29+ "github.com/arangodb/kube-arangodb/pkg/util/errors"
2530)
2631
2732type DeploymentSpecGateway struct {
@@ -37,7 +42,12 @@ type DeploymentSpecGateway struct {
3742
3843 // Image is the image to use for the gateway.
3944 // By default, the image is determined by the operator.
40- Image * string `json:"image"`
45+ Image * string `json:"image,omitempty"`
46+
47+ // Timeout defines default timeout for the upstream actions (if not overridden)
48+ // +doc/type: string
49+ // +doc/default: 1m0s
50+ Timeout * meta.Duration `json:"timeout,omitempty"`
4151}
4252
4353// IsEnabled returns whether the gateway is enabled.
@@ -58,9 +68,33 @@ func (d *DeploymentSpecGateway) IsDynamic() bool {
5868 return * d .Dynamic
5969}
6070
71+ // GetTimeout returns default gateway timeout.
72+ func (d * DeploymentSpecGateway ) GetTimeout () meta.Duration {
73+ if d == nil || d .Timeout == nil {
74+ return meta.Duration {
75+ Duration : constants .DefaultEnvoyUpstreamTimeout ,
76+ }
77+ }
78+
79+ return * d .Timeout
80+ }
81+
6182// Validate the given spec
6283func (d * DeploymentSpecGateway ) Validate () error {
63- return nil
84+ if d == nil {
85+ d = & DeploymentSpecGateway {}
86+ }
87+
88+ return shared .WithErrors (
89+ shared .PrefixResourceErrorFunc ("timeout" , func () error {
90+ if t := d .GetTimeout (); t .Duration < constants .MinEnvoyUpstreamTimeout {
91+ return errors .Errorf ("Timeout lower than %s not allowed" , constants .MinEnvoyUpstreamTimeout .String ())
92+ } else if t .Duration > constants .MaxEnvoyUpstreamTimeout {
93+ return errors .Errorf ("Timeout greater than %s not allowed" , constants .MaxEnvoyUpstreamTimeout .String ())
94+ }
95+ return nil
96+ }),
97+ )
6498}
6599
66100// GetImage returns the image to use for the gateway.
0 commit comments