/
flags.go
173 lines (127 loc) · 7.55 KB
/
flags.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright 2020 Authors of Cilium
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"flag"
"fmt"
"time"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"k8s.io/klog"
"github.com/cilium/cilium/pkg/defaults"
"github.com/cilium/cilium/pkg/option"
)
func init() {
cobra.OnInitialize(initConfig)
flags := rootCmd.Flags()
// AWS dedicated flags
flags.Int(option.AWSClientBurst, defaults.AWSClientBurst, "Burst value allowed for the AWS client used by the AWS ENI IPAM")
option.BindEnv(option.AWSClientBurst)
flags.Float64(option.AWSClientQPSLimit, defaults.AWSClientQPSLimit, "Queries per second limit for the AWS client used by the AWS ENI IPAM")
option.BindEnv(option.AWSClientQPSLimit)
flags.Var(option.NewNamedMapOptions(option.AwsInstanceLimitMapping, &option.Config.AwsInstanceLimitMapping, nil),
option.AwsInstanceLimitMapping,
`Add or overwrite mappings of AWS instance limit in the form of `+
`{"AWS instance type": "Maximum Network Interfaces","IPv4 Addresses `+
`per Interface","IPv6 Addresses per Interface"}. cli example: `+
`--aws-instance-limit-mapping=a1.medium=2,4,4 `+
`--aws-instance-limit-mapping=a2.somecustomflavor=4,5,6 `+
`configmap example: {"a1.medium": "2,4,4", "a2.somecustomflavor": "4,5,6"}`)
option.BindEnv(option.AwsInstanceLimitMapping)
flags.Bool(option.AwsReleaseExcessIps, false, "Enable releasing excess free IP addresses from AWS ENI.")
option.BindEnv(option.AwsReleaseExcessIps)
flags.Var(option.NewNamedMapOptions(option.ENITags, &option.Config.ENITags, nil),
option.ENITags, "ENI tags in the form of k1=v1 (multiple k/v pairs can be passed by repeating the CLI flag)")
option.BindEnv(option.ENITags)
flags.Int64(option.ENIParallelWorkers, defaults.ENIParallelWorkers, "Maximum number of parallel workers used by ENI allocator")
option.BindEnv(option.ENIParallelWorkers)
flags.Bool(option.UpdateEC2AdapterLimitViaAPI, false, "Use the EC2 API to update the instance type to adapter limits")
option.BindEnv(option.UpdateEC2AdapterLimitViaAPI)
// Clustermesh dedicated flags
flags.Int(option.ClusterIDName, 0, "Unique identifier of the cluster")
option.BindEnv(option.ClusterIDName)
flags.String(option.ClusterName, defaults.ClusterName, "Name of the cluster")
option.BindEnv(option.ClusterName)
// Operator-specific flags
flags.Bool(option.EnableCCNPNodeStatusGC, true, "Enable CiliumClusterwideNetworkPolicy Status garbage collection for nodes which have been removed from the cluster")
option.BindEnv(option.EnableCCNPNodeStatusGC)
flags.Bool(option.EnableCNPNodeStatusGC, true, "Enable CiliumNetworkPolicy Status garbage collection for nodes which have been removed from the cluster")
option.BindEnv(option.EnableCNPNodeStatusGC)
flags.Duration(option.CNPNodeStatusGCInterval, 2*time.Minute, "GC interval for nodes which have been removed from the cluster in CiliumNetworkPolicy Status")
option.BindEnv(option.CNPNodeStatusGCInterval)
flags.Duration(option.CNPStatusUpdateInterval, 1*time.Second, "interval between CNP status updates sent to the k8s-apiserver per-CNP")
option.BindEnv(option.CNPStatusUpdateInterval)
flags.BoolP(option.DebugArg, "D", false, "Enable debugging mode")
option.BindEnv(option.DebugArg)
// We need to obtain from Cilium ConfigMap if the CiliumEndpointCRD option
// is enabled or disabled. This option is marked as hidden because the
// Cilium Endpoint CRD controller is not in this program and by having it
// being printed by operator --help could confuse users.
flags.Bool(option.DisableCiliumEndpointCRDName, false, "")
flags.MarkHidden(option.DisableCiliumEndpointCRDName)
option.BindEnv(option.DisableCiliumEndpointCRDName)
flags.Bool(option.EnableCEPGC, true, "Enable CiliumEndpoint garbage collector")
option.BindEnv(option.EnableCEPGC)
flags.Duration(option.EndpointGCInterval, 30*time.Minute, "GC interval for cilium endpoints")
option.BindEnv(option.EndpointGCInterval)
flags.Bool(option.EnableMetrics, false, "Enable Prometheus metrics")
option.BindEnv(option.EnableMetrics)
flags.String(option.IPAM, "", "Backend to use for IPAM")
option.BindEnv(option.IPAM)
flags.Duration(option.IdentityHeartbeatTimeout, 15*time.Minute, "Timeout after which identity expires on lack of heartbeat")
option.BindEnv(option.IdentityHeartbeatTimeout)
flags.String(option.IdentityAllocationMode, option.IdentityAllocationModeKVstore, "Method to use for identity allocation")
option.BindEnv(option.IdentityAllocationMode)
flags.Duration(option.IdentityGCInterval, defaults.KVstoreLeaseTTL, "GC interval for security identities")
option.BindEnv(option.IdentityGCInterval)
flags.String(option.KVStore, "", "Key-value store type")
option.BindEnv(option.KVStore)
flags.Var(option.NewNamedMapOptions(option.KVStoreOpt, &option.Config.KVStoreOpt, nil),
option.KVStoreOpt, "Key-value store options")
option.BindEnv(option.KVStoreOpt)
flags.String(option.K8sAPIServer, "", "Kubernetes API server URL")
option.BindEnv(option.K8sAPIServer)
flags.Float32(option.K8sClientQPSLimit, defaults.K8sClientQPSLimit, "Queries per second limit for the K8s client")
flags.Int(option.K8sClientBurst, defaults.K8sClientBurst, "Burst value allowed for the K8s client")
flags.Bool(option.K8sEnableEndpointSlice, defaults.K8sEnableEndpointSlice, fmt.Sprintf("Enables k8s EndpointSlice feature into Cilium-Operator if the k8s cluster supports it"))
option.BindEnv(option.K8sEnableEndpointSlice)
flags.String(option.K8sNamespaceName, "", "Name of the Kubernetes namespace in which Cilium Operator is deployed in")
option.BindEnv(option.K8sNamespaceName)
flags.String(option.K8sKubeConfigPath, "", "Absolute path of the kubernetes kubeconfig file")
option.BindEnv(option.K8sKubeConfigPath)
flags.Duration(option.NodesGCInterval, 2*time.Minute, "GC interval for nodes store in the kvstore")
option.BindEnv(option.NodesGCInterval)
flags.Bool(option.SyncK8sServices, true, "Synchronize Kubernetes services to kvstore")
option.BindEnv(option.SyncK8sServices)
flags.Bool(option.SyncK8sNodes, true, "Synchronize Kubernetes nodes to kvstore and perform CNP GC")
option.BindEnv(option.SyncK8sNodes)
flags.Int(option.UnmanagedPodWatcherInterval, 15, "Interval to check for unmanaged kube-dns pods (0 to disable)")
option.BindEnv(option.UnmanagedPodWatcherInterval)
flags.Bool(option.Version, false, "Print version information")
option.BindEnv(option.Version)
// TODO: Urgent fix
flags.Uint16Var(&apiServerPort, "api-server-port", 9234, "Port on which the operator should serve API requests")
flags.StringVar(&metricsAddress, "metrics-address", ":6942", "Address to serve Prometheus metrics")
flags.String(option.CMDRef, "", "Path to cmdref output directory")
flags.MarkHidden(option.CMDRef)
option.BindEnv(option.CMDRef)
viper.BindPFlags(flags)
// Make sure that klog logging variables are initialized so that we can
// update them from this file.
klog.InitFlags(nil)
// Make sure klog (used by the client-go dependency) logs to stderr, as it
// will try to log to directories that may not exist in the cilium-operator
// container (/tmp) and cause the cilium-operator to exit.
flag.Set("logtostderr", "true")
}