Skip to content

Commit 82d455a

Browse files
a-cordierkamiiiel
authored andcommitted
feat: make APIM HTTP client timeout configurable
see https://gravitee.atlassian.net/browse/GKO-433
1 parent 0ee86a9 commit 82d455a

File tree

6 files changed

+43
-38
lines changed

6 files changed

+43
-38
lines changed

helm/gko/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ This is where you can configure the deployment itself and the way the operator w
6969
| `manager.applyCRDs` | 👎 This feature is deprecated and will be replaced in a future release. If true, the manager will patch Custom Resource Definitions on startup. | `true` |
7070
| `manager.metrics.enabled` | If true, a metrics server will be created so that metrics can be scraped using prometheus. | `true` |
7171
| `manager.httpClient.insecureSkipCertVerify` | If true, the manager HTTP client will not verify the certificate used by the Management API. | `false` |
72+
| `manager.httpClient.timeoutSeconds` | he timeout (in seconds) used when issuing request to the Management API. | `5` |
7273
| `manager.webhook.enabled` | If true, the manager will register a webhook server operating on custom resources. | `true` |
7374
| `manager.webhook.service.name` | The service used to expose the webhook server. | `gko-webhook` |
7475
| `manager.webhook.service.port` | Which port the webhook server will listen to. | `9443` |

helm/gko/templates/manager/config.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ data:
4747
TEMPLATE_404_CONFIG_MAP_NAMESPACE: {{ $template404.namespace }}
4848
{{- end }}
4949
{{- if or .Values.manager.httpClient.insecureSkipCertVerify .Values.httpClient.insecureSkipCertVerify }}
50-
INSECURE_SKIP_CERT_VERIFY: "true"
50+
HTTP_CLIENT_INSECURE_SKIP_CERT_VERIFY: "true"
5151
{{- end }}
52+
HTTP_CLIENT_TIMEOUT_SECONDS: {{ quote .Values.manager.httpClient.timeoutSeconds }}
5253
{{- if .Values.manager.webhook.enabled }}
5354
ENABLE_WEBHOOK: "true"
5455
WEBHOOK_CERT_SECRET_NAME: {{ .Values.manager.webhook.cert.secret.name }}
5556
WEBHOOK_NAMESPACE: {{ .Release.Namespace }}
5657
WEBHOOK_SERVICE_NAME: {{ .Values.manager.webhook.service.name }}
5758
WEBHOOK_SERVICE_PORT: {{ quote .Values.manager.webhook.service.port }}
58-
{{- end }}
59+
{{- end }}

helm/gko/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ manager:
9191
httpClient:
9292
## @param manager.httpClient.insecureSkipCertVerify If true, the manager HTTP client will not verify the certificate used by the Management API.
9393
insecureSkipCertVerify: false
94+
## @param manager.httpClient.timeoutSeconds he timeout (in seconds) used when issuing request to the Management API.
95+
timeoutSeconds: 5
9496
webhook:
9597
## @param manager.webhook.enabled If true, the manager will register a webhook server operating on custom resources.
9698
enabled: true

internal/env/env.go

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,42 @@ import (
2323
)
2424

2525
const (
26-
CMTemplate404Name = "TEMPLATE_404_CONFIG_MAP_NAME"
27-
CMTemplate404NS = "TEMPLATE_404_CONFIG_MAP_NAMESPACE"
28-
Development = "DEV_MODE"
29-
NS = "NAMESPACE"
30-
ApplyCRDs = "APPLY_CRDS"
31-
EnableMetrics = "ENABLE_METRICS"
32-
EnableWebhook = "ENABLE_WEBHOOK"
33-
WebhookNS = "WEBHOOK_NAMESPACE"
34-
WebhookServiceName = "WEBHOOK_SERVICE_NAME"
35-
WebhookPort = "WEBHOOK_SERVICE_PORT"
36-
WebhookCertSecret = "WEBHOOK_CERT_SECRET_NAME" //nolint:gosec // This is not a hardcoded secret
37-
InsecureSkipCertVerify = "INSECURE_SKIP_CERT_VERIFY"
38-
TrueString = "true"
39-
IngressClasses = "INGRESS_CLASSES"
26+
CMTemplate404Name = "TEMPLATE_404_CONFIG_MAP_NAME"
27+
CMTemplate404NS = "TEMPLATE_404_CONFIG_MAP_NAMESPACE"
28+
Development = "DEV_MODE"
29+
NS = "NAMESPACE"
30+
ApplyCRDs = "APPLY_CRDS"
31+
EnableMetrics = "ENABLE_METRICS"
32+
EnableWebhook = "ENABLE_WEBHOOK"
33+
WebhookNS = "WEBHOOK_NAMESPACE"
34+
WebhookServiceName = "WEBHOOK_SERVICE_NAME"
35+
WebhookPort = "WEBHOOK_SERVICE_PORT"
36+
WebhookCertSecret = "WEBHOOK_CERT_SECRET_NAME" //nolint:gosec // This is not a hardcoded secret
37+
HttpCLientInsecureSkipCertVerify = "HTTP_CLIENT_INSECURE_SKIP_CERT_VERIFY"
38+
HttpClientTimeoutSeconds = "HTTP_CLIENT_TIMEOUT_SECONDS"
39+
TrueString = "true"
40+
IngressClasses = "INGRESS_CLASSES"
4041

4142
// This default are applied when running the app locally.
42-
defaultWebhookPort = 9443
43+
defaultWebhookPort = 9443
44+
defaultHttpCLientTimeout = 5
4345
)
4446

4547
var Config = struct {
46-
NS string
47-
ApplyCRDs bool
48-
EnableMetrics bool
49-
EnableWebhook bool
50-
WebhookNS string
51-
WebhookService string
52-
WebhookPort int
53-
WebhookCertSecret string
54-
Development bool
55-
CMTemplate404Name string
56-
CMTemplate404NS string
57-
InsecureSkipVerify bool
58-
IngressClasses []string
48+
NS string
49+
ApplyCRDs bool
50+
EnableMetrics bool
51+
EnableWebhook bool
52+
WebhookNS string
53+
WebhookService string
54+
WebhookPort int
55+
WebhookCertSecret string
56+
Development bool
57+
CMTemplate404Name string
58+
CMTemplate404NS string
59+
HTTPClientInsecureSkipVerify bool
60+
HTTPClientTimeoutSeconds int
61+
IngressClasses []string
5962
}{}
6063

6164
func init() {
@@ -64,7 +67,8 @@ func init() {
6467
Config.Development = os.Getenv(Development) == TrueString
6568
Config.CMTemplate404Name = os.Getenv(CMTemplate404Name)
6669
Config.CMTemplate404NS = os.Getenv(CMTemplate404NS)
67-
Config.InsecureSkipVerify = os.Getenv(InsecureSkipCertVerify) == TrueString
70+
Config.HTTPClientInsecureSkipVerify = os.Getenv(HttpCLientInsecureSkipCertVerify) == TrueString
71+
Config.HTTPClientTimeoutSeconds = parseInt(HttpClientTimeoutSeconds, defaultHttpCLientTimeout)
6872
Config.EnableMetrics = os.Getenv(EnableMetrics) == TrueString
6973
Config.EnableWebhook = os.Getenv(EnableWebhook) == TrueString
7074
Config.WebhookNS = os.Getenv(WebhookNS)

internal/http/http.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ import (
2525
"github.com/gravitee-io/gravitee-kubernetes-operator/internal/errors"
2626
)
2727

28-
const (
29-
requestTimeoutSeconds = 5
30-
)
31-
3228
type Client struct {
3329
ctx context.Context
3430
http http.Client
@@ -197,10 +193,11 @@ func NewClient(ctx context.Context, auth *Auth) *Client {
197193
transport := http.DefaultTransport.(*http.Transport).Clone()
198194
transport.TLSClientConfig = &tls.Config{
199195
// #nosec G402
200-
InsecureSkipVerify: env.Config.InsecureSkipVerify,
196+
InsecureSkipVerify: env.Config.HTTPClientInsecureSkipVerify,
201197
}
202198

203-
httpClient := http.Client{Timeout: requestTimeoutSeconds * time.Second, Transport: transport}
199+
timeout := time.Duration(env.Config.HTTPClientTimeoutSeconds) * time.Second
200+
httpClient := http.Client{Timeout: timeout, Transport: transport}
204201

205202
if auth != nil {
206203
authRoundTripper := NewAuthenticatedRoundTripper(auth, transport)

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func main() {
120120
metricsAddr = "0" // disables metrics
121121
}
122122

123-
if env.Config.InsecureSkipVerify {
123+
if env.Config.HTTPClientInsecureSkipVerify {
124124
setupLog.Info("TLS verification is skipped for APIM HTTP client")
125125
}
126126

0 commit comments

Comments
 (0)