-
Notifications
You must be signed in to change notification settings - Fork 444
/
rest_config.go
67 lines (55 loc) · 1.64 KB
/
rest_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package kubeutils
import (
"os"
"strconv"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)
const (
K8sClientQpsEnv = "K8S_CLIENT_QPS"
K8sClientQpsDefault = 50 // 10x the k8s-recommended default; gloo gets busy writing status updates
K8sClientBurstEnv = "K8S_CLIENT_BURST"
K8sClientBurstDefault = 100 // 10x the k8s-recommended default; gloo gets busy writing status updates
)
// GetRestConfigWithKubeContext provides the rest.Config object for a given Kubernetes context
// This is a wrapper on the controller-runtime implementation, and allows overriding certain
// client properties via environment variables
func GetRestConfigWithKubeContext(kubeContext string) (*rest.Config, error) {
restConfig, err := config.GetConfigWithContext(kubeContext)
if err != nil {
return nil, err
}
if err = setClientQpsOrError(restConfig); err != nil {
return nil, err
}
if err = setClientBurstOrError(restConfig); err != nil {
return nil, err
}
return restConfig, nil
}
func setClientQpsOrError(restConfig *rest.Config) error {
restConfig.QPS = K8sClientQpsDefault
clientQpsOverride := os.Getenv(K8sClientQpsEnv)
if clientQpsOverride == "" {
return nil
}
qps, err := strconv.ParseFloat(clientQpsOverride, 32)
if err != nil {
return err
}
restConfig.QPS = float32(qps)
return nil
}
func setClientBurstOrError(restConfig *rest.Config) error {
restConfig.Burst = K8sClientBurstDefault
clientBurstOverride := os.Getenv(K8sClientBurstEnv)
if clientBurstOverride == "" {
return nil
}
burst, err := strconv.Atoi(clientBurstOverride)
if err != nil {
return err
}
restConfig.Burst = burst
return nil
}