-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
config.go
69 lines (55 loc) · 2.46 KB
/
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
68
69
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package client
import (
"os"
"time"
"github.com/spf13/pflag"
"github.com/cilium/cilium/pkg/defaults"
"github.com/cilium/cilium/pkg/option"
)
type Config struct {
// EnableK8s is a flag that, when set to false, forcibly disables the clientset, to let cilium
// operates with CNI-compatible orchestrators other than Kubernetes. Default to true.
EnableK8s bool
// K8sAPIServer is the kubernetes api address server (for https use --k8s-kubeconfig-path instead)
K8sAPIServer string
// K8sKubeConfigPath is the absolute path of the kubernetes kubeconfig file
K8sKubeConfigPath string
// K8sClientQPS is the queries per second limit for the K8s client. Defaults to k8s client defaults.
K8sClientQPS float32
// K8sClientBurst is the burst value allowed for the K8s client. Defaults to k8s client defaults.
K8sClientBurst int
// K8sHeartbeatTimeout configures the timeout for apiserver heartbeat
K8sHeartbeatTimeout time.Duration
// K8sEnableAPIDiscovery enables Kubernetes API discovery
EnableK8sAPIDiscovery bool
}
var defaultConfig = Config{
EnableK8s: true,
K8sAPIServer: "",
K8sKubeConfigPath: "",
K8sClientQPS: defaults.K8sClientQPSLimit,
K8sClientBurst: defaults.K8sClientBurst,
K8sHeartbeatTimeout: 30 * time.Second,
EnableK8sAPIDiscovery: defaults.K8sEnableAPIDiscovery,
}
func (def Config) Flags(flags *pflag.FlagSet) {
flags.Bool(option.EnableK8s, def.EnableK8s, "Enable the k8s clientset")
flags.String(option.K8sAPIServer, def.K8sAPIServer, "Kubernetes API server URL")
flags.String(option.K8sKubeConfigPath, def.K8sKubeConfigPath, "Absolute path of the kubernetes kubeconfig file")
flags.Float32(option.K8sClientQPSLimit, def.K8sClientQPS, "Queries per second limit for the K8s client")
flags.Int(option.K8sClientBurst, def.K8sClientBurst, "Burst value allowed for the K8s client")
flags.Duration(option.K8sHeartbeatTimeout, def.K8sHeartbeatTimeout, "Configures the timeout for api-server heartbeat, set to 0 to disable")
flags.Bool(option.K8sEnableAPIDiscovery, def.EnableK8sAPIDiscovery, "Enable discovery of Kubernetes API groups and resources with the discovery API")
}
func (cfg Config) isEnabled() bool {
if !cfg.EnableK8s {
return false
}
return cfg.K8sAPIServer != "" ||
cfg.K8sKubeConfigPath != "" ||
(os.Getenv("KUBERNETES_SERVICE_HOST") != "" &&
os.Getenv("KUBERNETES_SERVICE_PORT") != "") ||
os.Getenv("K8S_NODE_NAME") != ""
}