-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
flags.go
330 lines (255 loc) · 15.2 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
// 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 (
"fmt"
"time"
operatorMetrics "github.com/cilium/cilium/operator/metrics"
operatorOption "github.com/cilium/cilium/operator/option"
"github.com/cilium/cilium/pkg/defaults"
ipamOption "github.com/cilium/cilium/pkg/ipam/option"
"github.com/cilium/cilium/pkg/option"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func init() {
cobra.OnInitialize(option.InitConfig("Cilium-Operator", "cilium-operators"))
flags := rootCmd.Flags()
flags.Int(operatorOption.AWSClientBurstDeprecated, defaults.IPAMAPIBurst, "")
flags.MarkDeprecated(operatorOption.AWSClientBurstDeprecated, fmt.Sprintf("please use --%s", operatorOption.IPAMAPIBurst))
flags.Int(operatorOption.IPAMAPIBurst, defaults.IPAMAPIBurst, "Upper burst limit when accessing external APIs")
option.BindEnv(operatorOption.IPAMAPIBurst)
flags.Float64(operatorOption.AWSClientQPSLimitDeprecated, defaults.IPAMAPIQPSLimit, "")
flags.MarkDeprecated(operatorOption.AWSClientQPSLimitDeprecated, fmt.Sprintf("please use --%s", operatorOption.IPAMAPIQPSLimit))
flags.Float64(operatorOption.IPAMAPIQPSLimit, defaults.IPAMAPIQPSLimit, "Queries per second limit when accessing external IPAM APIs")
option.BindEnv(operatorOption.IPAMAPIQPSLimit)
flags.StringToStringVar(&operatorOption.Config.IPAMSubnetsTags, operatorOption.IPAMSubnetsTags, operatorOption.Config.IPAMSubnetsTags,
"Subnets tags in the form of k1=v1,k2=v2 (multiple k/v pairs can also be passed by repeating the CLI flag")
option.BindEnv(operatorOption.IPAMSubnetsTags)
flags.StringSliceVar(&operatorOption.Config.IPAMSubnetsIDs, operatorOption.IPAMSubnetsIDs, operatorOption.Config.IPAMSubnetsIDs,
"Subnets IDs (separated by commas)")
option.BindEnv(operatorOption.IPAMSubnetsIDs)
flags.Int64(operatorOption.ENIParallelWorkersDeprecated, defaults.ParallelAllocWorkers, "")
flags.MarkDeprecated(operatorOption.ENIParallelWorkersDeprecated, fmt.Sprintf("please use --%s", operatorOption.ParallelAllocWorkers))
option.BindEnv(operatorOption.ENIParallelWorkersDeprecated)
flags.Int64(operatorOption.ParallelAllocWorkers, defaults.ParallelAllocWorkers, "Maximum number of parallel IPAM workers")
option.BindEnv(operatorOption.ParallelAllocWorkers)
flags.Bool(operatorOption.UpdateEC2AdapterLimitViaAPI, false, "Use the EC2 API to update the instance type to adapter limits")
option.BindEnv(operatorOption.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.String(option.ConfigFile, "", `Configuration file (default "$HOME/ciliumd.yaml")`)
option.BindEnv(option.ConfigFile)
flags.String(option.ConfigDir, "", `Configuration directory that contains a file for each option`)
option.BindEnv(option.ConfigDir)
// Deprecated, remove in 1.9
flags.Bool(operatorOption.EnableCCNPNodeStatusGC, true, "Enable CiliumClusterwideNetworkPolicy Status garbage collection for nodes which have been removed from the cluster")
option.BindEnv(operatorOption.EnableCCNPNodeStatusGC)
flags.MarkDeprecated(operatorOption.EnableCCNPNodeStatusGC, fmt.Sprintf("Please use %s=0 to disable CCNP Status GC", operatorOption.CNPNodeStatusGCInterval))
// Deprecated, remove in 1.9
flags.Bool(operatorOption.EnableCNPNodeStatusGC, true, "Enable CiliumNetworkPolicy Status garbage collection for nodes which have been removed from the cluster")
option.BindEnv(operatorOption.EnableCNPNodeStatusGC)
flags.MarkDeprecated(operatorOption.EnableCNPNodeStatusGC, fmt.Sprintf("Please use %s=0 to disable CNP Status GC", operatorOption.CNPNodeStatusGCInterval))
flags.Bool(option.DisableCNPStatusUpdates, false, `Do not send CNP NodeStatus updates to the Kubernetes api-server (recommended to run with "cnp-node-status-gc-interval=0" in cilium-operator)`)
flags.MarkHidden(option.DisableCNPStatusUpdates)
option.BindEnv(option.DisableCNPStatusUpdates)
flags.Bool(option.K8sEventHandover, defaults.K8sEventHandover, "Enable k8s event handover to kvstore for improved scalability")
option.BindEnv(option.K8sEventHandover)
flags.Duration(operatorOption.CNPNodeStatusGCInterval, 2*time.Minute, "GC interval for nodes which have been removed from the cluster in CiliumNetworkPolicy Status")
option.BindEnv(operatorOption.CNPNodeStatusGCInterval)
flags.Duration(operatorOption.CNPStatusUpdateInterval, 1*time.Second, "Interval between CNP status updates sent to the k8s-apiserver per-CNP")
option.BindEnv(operatorOption.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)
// Deprecated, remove in 1.9
flags.Bool(operatorOption.EnableCEPGC, true, "Enable CiliumEndpoint garbage collector")
option.BindEnv(operatorOption.EnableCEPGC)
flags.MarkDeprecated(operatorOption.EnableCEPGC, fmt.Sprintf("Please use %s=0 to disable CEP GC", operatorOption.EndpointGCInterval))
flags.Duration(operatorOption.EndpointGCInterval, operatorOption.EndpointGCIntervalDefault, "GC interval for cilium endpoints")
option.BindEnv(operatorOption.EndpointGCInterval)
flags.Bool(operatorOption.EnableMetrics, false, "Enable Prometheus metrics")
option.BindEnv(operatorOption.EnableMetrics)
// Logging flags
flags.StringSlice(option.LogDriver, []string{}, "Logging endpoints to use for example syslog")
option.BindEnv(option.LogDriver)
flags.Var(option.NewNamedMapOptions(option.LogOpt, &option.Config.LogOpt, nil),
option.LogOpt, "Log driver options for cilium-operator")
option.BindEnv(option.LogOpt)
var defaultIPAM string
switch binaryName {
case "cilium-operator":
defaultIPAM = ipamOption.IPAMHostScopeLegacy
case "cilium-operator-aws":
defaultIPAM = ipamOption.IPAMENI
case "cilium-operator-azure":
defaultIPAM = ipamOption.IPAMAzure
case "cilium-operator-generic":
// Default to Legacy for upgrade paths; new users should
// explicitly override the IPAM flag.
defaultIPAM = ipamOption.IPAMHostScopeLegacy
}
flags.String(option.IPAM, defaultIPAM, "Backend to use for IPAM")
option.BindEnv(option.IPAM)
rootCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
ipamFlag := cmd.Flag(option.IPAM)
if !ipamFlag.Changed {
return nil
}
ipamFlagValue := ipamFlag.Value.String()
recommendInstead := func() string {
switch ipamFlagValue {
case ipamOption.IPAMENI:
return "cilium-operator-aws"
case ipamOption.IPAMAzure:
return "cilium-operator-azure"
case ipamOption.IPAMKubernetes, ipamOption.IPAMClusterPool, ipamOption.IPAMCRD:
return "cilium-operator-generic"
default:
return ""
}
}
unsupporterErr := func() error {
errMsg := fmt.Sprintf("%s doesn't support --%s=%s", binaryName, option.IPAM, ipamFlagValue)
if recommendation := recommendInstead(); recommendation != "" {
return fmt.Errorf("%s (use %s)", errMsg, recommendation)
}
return fmt.Errorf(errMsg)
}
switch binaryName {
case "cilium-operator":
if recommendation := recommendInstead(); recommendation != "" {
log.Warnf("cilium-operator will be deprecated in the future, for --%s=%s use %s as it has lower memory footprint", option.IPAM, ipamFlagValue, recommendation)
}
case "cilium-operator-aws":
if ipamFlagValue != ipamOption.IPAMENI {
return unsupporterErr()
}
case "cilium-operator-azure":
if ipamFlagValue != ipamOption.IPAMAzure {
return unsupporterErr()
}
case "cilium-operator-generic":
switch ipamFlagValue {
case ipamOption.IPAMENI, ipamOption.IPAMAzure:
return unsupporterErr()
case ipamOption.IPAMHostScopeLegacy:
return fmt.Errorf("%s, as it is deprecated, but it is still supported by legacy cilium-operator binary)", unsupporterErr().Error())
}
}
return nil
}
flags.Duration(operatorOption.IdentityHeartbeatTimeout, 2*defaults.KVstoreLeaseTTL, "Timeout after which identity expires on lack of heartbeat")
option.BindEnv(operatorOption.IdentityHeartbeatTimeout)
flags.Bool(option.EnableIPv4Name, defaults.EnableIPv4, "Enable IPv4 support")
option.BindEnv(option.EnableIPv4Name)
flags.String(operatorOption.ClusterPoolIPv4CIDR, "",
fmt.Sprintf("IPv4 CIDR Range for Pods in cluster. Requires '%s=%s' and '%s=%s'",
option.IPAM, ipamOption.IPAMClusterPool,
option.EnableIPv4Name, "true"))
option.BindEnv(operatorOption.ClusterPoolIPv4CIDR)
flags.Int(operatorOption.NodeCIDRMaskSizeIPv4, 24,
fmt.Sprintf("Mask size for each IPv4 podCIDR per node. Requires '%s=%s' and '%s=%s'",
option.IPAM, ipamOption.IPAMClusterPool,
option.EnableIPv4Name, "true"))
option.BindEnv(operatorOption.NodeCIDRMaskSizeIPv4)
flags.Bool(option.EnableIPv6Name, defaults.EnableIPv6, "Enable IPv6 support")
option.BindEnv(option.EnableIPv6Name)
flags.String(operatorOption.ClusterPoolIPv6CIDR, "",
fmt.Sprintf("IPv6 CIDR Range for Pods in cluster. Requires '%s=%s' and '%s=%s'",
option.IPAM, ipamOption.IPAMClusterPool,
option.EnableIPv6Name, "true"))
option.BindEnv(operatorOption.ClusterPoolIPv6CIDR)
flags.Int(operatorOption.NodeCIDRMaskSizeIPv6, 112,
fmt.Sprintf("Mask size for each IPv6 podCIDR per node. Requires '%s=%s' and '%s=%s'",
option.IPAM, ipamOption.IPAMClusterPool,
option.EnableIPv6Name, "true"))
option.BindEnv(operatorOption.NodeCIDRMaskSizeIPv6)
flags.String(option.IdentityAllocationMode, option.IdentityAllocationModeKVstore, "Method to use for identity allocation")
option.BindEnv(option.IdentityAllocationMode)
flags.Duration(operatorOption.IdentityGCInterval, defaults.KVstoreLeaseTTL, "GC interval for security identities")
option.BindEnv(operatorOption.IdentityGCInterval)
flags.Duration(operatorOption.IdentityGCRateInterval, time.Minute,
"Interval used for rate limiting the GC of security identities")
option.BindEnv(operatorOption.IdentityGCRateInterval)
flags.Int(operatorOption.IdentityGCRateLimit, 250,
fmt.Sprintf("Maximum number of security identities that will be deleted within the %s", operatorOption.IdentityGCRateInterval))
option.BindEnv(operatorOption.IdentityGCRateLimit)
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, "Enables k8s EndpointSlice feature into Cilium-Operator if the k8s cluster supports it")
option.BindEnv(option.K8sEnableEndpointSlice)
flags.Bool(option.K8sEnableAPIDiscovery, defaults.K8sEnableAPIDiscovery, "Enable discovery of Kubernetes API groups and resources with the discovery API")
option.BindEnv(option.K8sEnableAPIDiscovery)
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(operatorOption.NodesGCInterval, 2*time.Minute, "GC interval for nodes store in the kvstore")
option.BindEnv(operatorOption.NodesGCInterval)
flags.String(operatorOption.OperatorPrometheusServeAddr, ":6942", "Address to serve Prometheus metrics")
option.BindEnv(operatorOption.OperatorPrometheusServeAddr)
flags.String(operatorOption.OperatorAPIServeAddr, "localhost:9234", "Address to serve API requests")
option.BindEnv(operatorOption.OperatorAPIServeAddr)
flags.Bool(operatorOption.SyncK8sServices, true, "Synchronize Kubernetes services to kvstore")
option.BindEnv(operatorOption.SyncK8sServices)
flags.Bool(operatorOption.SyncK8sNodes, true, "Synchronize Kubernetes nodes to kvstore and perform CNP GC")
option.BindEnv(operatorOption.SyncK8sNodes)
flags.Int(operatorOption.UnmanagedPodWatcherInterval, 15, "Interval to check for unmanaged kube-dns pods (0 to disable)")
option.BindEnv(operatorOption.UnmanagedPodWatcherInterval)
flags.Bool(option.Version, false, "Print version information")
option.BindEnv(option.Version)
// Deprecated, remove in 1.9
flags.Uint16Var(&apiServerPort, "api-server-port", 9234, "Port on which the operator should serve API requests")
flags.MarkDeprecated("api-server-port", fmt.Sprintf("Please use %s instead", operatorOption.OperatorAPIServeAddr))
// Deprecated, remove in 1.9
flags.StringVar(&operatorMetrics.Address, "metrics-address", ":6942", "Address to serve Prometheus metrics")
flags.MarkDeprecated("metrics-address", fmt.Sprintf("Please use %s instead", operatorOption.OperatorPrometheusServeAddr))
flags.String(option.CMDRef, "", "Path to cmdref output directory")
flags.MarkHidden(option.CMDRef)
option.BindEnv(option.CMDRef)
flags.Duration(option.K8sHeartbeatTimeout, 30*time.Second, "Configures the timeout for api-server heartbeat, set to 0 to disable")
option.BindEnv(option.K8sHeartbeatTimeout)
flags.Duration(operatorOption.CRDWaitTimeout, 5*time.Minute, "Operator will exit if CRDs are not available within this duration upon startup")
option.BindEnv(operatorOption.CRDWaitTimeout)
flags.Duration(operatorOption.LeaderElectionLeaseDuration, 15*time.Second,
"Duration that non-leader operator candidates will wait before forcing to acquire leadership")
option.BindEnv(operatorOption.LeaderElectionLeaseDuration)
flags.Duration(operatorOption.LeaderElectionRenewDeadline, 10*time.Second,
"Duration that current acting master will retry refreshing leadership in before giving up the lock")
option.BindEnv(operatorOption.LeaderElectionRenewDeadline)
flags.Duration(operatorOption.LeaderElectionRetryPeriod, 2*time.Second,
"Duration that LeaderElector clients should wait between retries of the actions")
option.BindEnv(operatorOption.LeaderElectionRetryPeriod)
flags.String(option.K8sServiceProxyName, "", "Value of K8s service-proxy-name label for which Cilium handles the services (empty = all services without service.kubernetes.io/service-proxy-name label)")
option.BindEnv(option.K8sServiceProxyName)
viper.BindPFlags(flags)
}