-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
config.go
357 lines (268 loc) · 13.3 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
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
// 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 option
import (
"time"
"github.com/spf13/viper"
)
const (
// EndpointGCIntervalDefault is the default time for the CEP GC
EndpointGCIntervalDefault = 5 * time.Minute
)
const (
// CNPNodeStatusGCInterval is the GC interval for nodes which have been
// removed from the cluster in CiliumNetworkPolicy and
// CiliumClusterwideNetworkPolicy Status.
CNPNodeStatusGCInterval = "cnp-node-status-gc-interval"
// CNPStatusUpdateInterval is the interval between status updates
// being sent to the K8s apiserver for a given CNP.
CNPStatusUpdateInterval = "cnp-status-update-interval"
// EnableMetrics enables prometheus metrics.
EnableMetrics = "enable-metrics"
// EndpointGCInterval is the interval between attempts of the CEP GC
// controller.
// Note that only one node per cluster should run this, and most iterations
// will simply return.
EndpointGCInterval = "cilium-endpoint-gc-interval"
// IdentityGCInterval is the interval in which allocator identities are
// attempted to be expired from the kvstore
IdentityGCInterval = "identity-gc-interval"
// IdentityGCRateInterval is the interval used for rate limiting the GC of
// identities.
IdentityGCRateInterval = "identity-gc-rate-interval"
// IdentityGCRateLimit is the maximum identities used for rate limiting the
// GC of identities.
IdentityGCRateLimit = "identity-gc-rate-limit"
// IdentityHeartbeatTimeout is the timeout used to GC identities from k8s
IdentityHeartbeatTimeout = "identity-heartbeat-timeout"
// NodesGCInterval is the duration for which the nodes are GC in the KVStore.
NodesGCInterval = "nodes-gc-interval"
// OperatorAPIServeAddr IP:Port on which to serve api requests in
// operator (pass ":Port" to bind on all interfaces, "" is off)
OperatorAPIServeAddr = "operator-api-serve-addr"
// OperatorPrometheusServeAddr IP:Port on which to serve prometheus
// metrics (pass ":Port" to bind on all interfaces, "" is off).
OperatorPrometheusServeAddr = "operator-prometheus-serve-addr"
// SyncK8sServices synchronizes k8s services into the kvstore
SyncK8sServices = "synchronize-k8s-services"
// SyncK8sNodes synchronizes k8s nodes into the kvstore
SyncK8sNodes = "synchronize-k8s-nodes"
// UnmanagedPodWatcherInterval is the interval to check for unmanaged kube-dns pods (0 to disable)
UnmanagedPodWatcherInterval = "unmanaged-pod-watcher-interval"
// IPAM options
// IPAMAPIBurst is the burst value allowed when accessing external IPAM APIs
IPAMAPIBurst = "limit-ipam-api-burst"
// IPAMAPIQPSLimit is the queries per second limit when accessing external IPAM APIs
IPAMAPIQPSLimit = "limit-ipam-api-qps"
// IPAMSubnetsIDs are optional subnets IDs used to filter subnets and interfaces listing
IPAMSubnetsIDs = "subnet-ids-filter"
// IPAMSubnetsTags are optional tags used to filter subnets, and interfaces within those subnets
IPAMSubnetsTags = "subnet-tags-filter"
// IPAMOperatorV4CIDR is the cluster IPv4 podCIDR that should be used to
// allocate pods in the node.
IPAMOperatorV4CIDR = "cluster-pool-ipv4-cidr"
// IPAMOperatorV6CIDR is the cluster IPv6 podCIDR that should be used to
// allocate pods in the node.
IPAMOperatorV6CIDR = "cluster-pool-ipv6-cidr"
// NodeCIDRMaskSizeIPv4 is the IPv4 podCIDR mask size that will be used
// per node.
NodeCIDRMaskSizeIPv4 = "cluster-pool-ipv4-mask-size"
// NodeCIDRMaskSizeIPv6 is the IPv6 podCIDR mask size that will be used
// per node.
NodeCIDRMaskSizeIPv6 = "cluster-pool-ipv6-mask-size"
// AWS options
// AWSInstanceLimitMapping allows overwirting AWS instance limits defined in
// pkg/aws/eni/limits.go
// e.g. {"a1.medium": "2,4,4", "a2.custom2": "4,5,6"}
AWSInstanceLimitMapping = "aws-instance-limit-mapping"
// AWSReleaseExcessIPs allows releasing excess free IP addresses from ENI.
// Enabling this option reduces waste of IP addresses but may increase
// the number of API calls to AWS EC2 service.
AWSReleaseExcessIPs = "aws-release-excess-ips"
// ENITags are the tags that will be added to every ENI created by the
// AWS ENI IPAM.
ENITags = "eni-tags"
// ParallelAllocWorkers specifies the number of parallel workers to be used for IPAM allocation
ParallelAllocWorkers = "parallel-alloc-workers"
// UpdateEC2AdapterLimitViaAPI configures the operator to use the EC2
// API to fill out the instancetype to adapter limit mapping.
UpdateEC2AdapterLimitViaAPI = "update-ec2-apdater-limit-via-api"
// EC2APIEndpoint is the custom API endpoint to use for the EC2 AWS service,
// e.g. "ec2-fips.us-west-1.amazonaws.com" to use a FIPS endpoint in the us-west-1 region.
EC2APIEndpoint = "ec2-api-endpoint"
// Azure options
// AzureSubscriptionID is the subscription ID to use when accessing the Azure API
AzureSubscriptionID = "azure-subscription-id"
// AzureResourceGroup is the resource group of the nodes used for the cluster
AzureResourceGroup = "azure-resource-group"
// CRDWaitTimeout it the time after which Cilium CRDs have to be available.
CRDWaitTimeout = "crd-wait-timeout"
// LeaderElectionLeaseDuration is the duration that non-leader candidates will wait to
// force acquire leadership
LeaderElectionLeaseDuration = "leader-election-lease-duration"
// LeaderElectionRenewDeadline is the duration that the current acting master in HA deployment
// will retry refreshing leadership before giving up the lock.
LeaderElectionRenewDeadline = "leader-election-renew-deadline"
// LeaderElectionRetryPeriod is the duration the LeaderElector clients should wait between
// tries of the actions in operator HA deployment.
LeaderElectionRetryPeriod = "leader-election-retry-period"
)
// OperatorConfig is the configuration used by the operator.
type OperatorConfig struct {
// CNPNodeStatusGCInterval is the GC interval for nodes which have been
// removed from the cluster in CiliumNetworkPolicy and
// CiliumClusterwideNetworkPolicy Status.
CNPNodeStatusGCInterval time.Duration
// CNPStatusUpdateInterval is the interval between status updates
// being sent to the K8s apiserver for a given CNP.
CNPStatusUpdateInterval time.Duration
// EnableMetrics enables prometheus metrics.
EnableMetrics bool
// EndpointGCInterval is the interval between attempts of the CEP GC
// controller.
// Note that only one node per cluster should run this, and most iterations
// will simply return.
EndpointGCInterval time.Duration
// IdentityGCInterval is the interval in which allocator identities are
// attempted to be expired from the kvstore
IdentityGCInterval time.Duration
// IdentityGCRateInterval is the interval used for rate limiting the GC of
// identities.
IdentityGCRateInterval time.Duration
// IdentityGCRateLimit is the maximum identities used for rate limiting the
// GC of identities.
IdentityGCRateLimit int64
// IdentityHeartbeatTimeout is the timeout used to GC identities from k8s
IdentityHeartbeatTimeout time.Duration
// NodesGCInterval is the duration for which the nodes are GC in the KVStore.
NodesGCInterval time.Duration
OperatorAPIServeAddr string
OperatorPrometheusServeAddr string
// SyncK8sServices synchronizes k8s services into the kvstore
SyncK8sServices bool
// SyncK8sNodes synchronizes k8s nodes into the kvstore
SyncK8sNodes bool
// UnmanagedPodWatcherInterval is the interval to check for unmanaged kube-dns pods (0 to disable)
UnmanagedPodWatcherInterval int
// IPAM options
// IPAMAPIBurst is the burst value allowed when accessing external IPAM APIs
IPAMAPIBurst int
// IPAMAPIQPSLimit is the queries per second limit when accessing external IPAM APIs
IPAMAPIQPSLimit float64
// IPAMSubnetsIDs are optional subnets IDs used to filter subnets and interfaces listing
IPAMSubnetsIDs []string
// IPAMSubnetsTags are optional tags used to filter subnets, and interfaces within those subnets
IPAMSubnetsTags map[string]string
// IPAM Operator options
// IPAMOperatorV4CIDR is the cluster IPv4 podCIDR that should be used to
// allocate pods in the node.
IPAMOperatorV4CIDR []string
// IPAMOperatorV6CIDR is the cluster IPv6 podCIDR that should be used to
// allocate pods in the node.
IPAMOperatorV6CIDR []string
// NodeCIDRMaskSizeIPv4 is the IPv4 podCIDR mask size that will be used
// per node.
NodeCIDRMaskSizeIPv4 int
// NodeCIDRMaskSizeIPv6 is the IPv6 podCIDR mask size that will be used
// per node.
NodeCIDRMaskSizeIPv6 int
// AWS options
// ENITags are the tags that will be added to every ENI created by the AWS ENI IPAM
ENITags map[string]string
// ParallelAllocWorkers specifies the number of parallel workers to be used in ENI mode.
ParallelAllocWorkers int64
// AWSInstanceLimitMapping allows overwriting AWS instance limits defined in
// pkg/aws/eni/limits.go
// e.g. {"a1.medium": "2,4,4", "a2.custom2": "4,5,6"}
AWSInstanceLimitMapping map[string]string
// AWSReleaseExcessIps allows releasing excess free IP addresses from ENI.
// Enabling this option reduces waste of IP addresses but may increase
// the number of API calls to AWS EC2 service.
AWSReleaseExcessIPs bool
// UpdateEC2AdapterLimitViaAPI configures the operator to use the EC2 API to fill out the
// instancetype to adapter limit mapping.
UpdateEC2AdapterLimitViaAPI bool
// EC2APIEndpoint is the custom API endpoint to use for the EC2 AWS service,
// e.g. "ec2-fips.us-west-1.amazonaws.com" to use a FIPS endpoint in the us-west-1 region.
EC2APIEndpoint string
// Azure options
// AzureSubscriptionID is the subscription ID to use when accessing the Azure API
AzureSubscriptionID string
// AzureResourceGroup is the resource group of the nodes used for the cluster
AzureResourceGroup string
// CRDWaitTimeout it the time after which Cilium CRDs have to be available.
CRDWaitTimeout time.Duration
// LeaderElectionLeaseDuration is the duration that non-leader candidates will wait to
// force acquire leadership in Cilium Operator HA deployment.
LeaderElectionLeaseDuration time.Duration
// LeaderElectionRenewDeadline is the duration that the current acting master in HA deployment
// will retry refreshing leadership in before giving up the lock.
LeaderElectionRenewDeadline time.Duration
// LeaderElectionRetryPeriod is the duration that LeaderElector clients should wait between
// retries of the actions in operator HA deployment.
LeaderElectionRetryPeriod time.Duration
}
// Populate sets all options with the values from viper.
func (c *OperatorConfig) Populate() {
c.CNPNodeStatusGCInterval = viper.GetDuration(CNPNodeStatusGCInterval)
c.CNPStatusUpdateInterval = viper.GetDuration(CNPStatusUpdateInterval)
c.EnableMetrics = viper.GetBool(EnableMetrics)
c.EndpointGCInterval = viper.GetDuration(EndpointGCInterval)
c.IdentityGCInterval = viper.GetDuration(IdentityGCInterval)
c.IdentityGCRateInterval = viper.GetDuration(IdentityGCRateInterval)
c.IdentityGCRateLimit = viper.GetInt64(IdentityGCRateLimit)
c.IdentityHeartbeatTimeout = viper.GetDuration(IdentityHeartbeatTimeout)
c.NodesGCInterval = viper.GetDuration(NodesGCInterval)
c.OperatorAPIServeAddr = viper.GetString(OperatorAPIServeAddr)
c.OperatorPrometheusServeAddr = viper.GetString(OperatorPrometheusServeAddr)
c.SyncK8sServices = viper.GetBool(SyncK8sServices)
c.SyncK8sNodes = viper.GetBool(SyncK8sNodes)
c.UnmanagedPodWatcherInterval = viper.GetInt(UnmanagedPodWatcherInterval)
c.NodeCIDRMaskSizeIPv4 = viper.GetInt(NodeCIDRMaskSizeIPv4)
c.NodeCIDRMaskSizeIPv6 = viper.GetInt(NodeCIDRMaskSizeIPv6)
c.IPAMOperatorV4CIDR = viper.GetStringSlice(IPAMOperatorV4CIDR)
c.IPAMOperatorV6CIDR = viper.GetStringSlice(IPAMOperatorV6CIDR)
c.NodesGCInterval = viper.GetDuration(NodesGCInterval)
c.CRDWaitTimeout = viper.GetDuration(CRDWaitTimeout)
c.LeaderElectionLeaseDuration = viper.GetDuration(LeaderElectionLeaseDuration)
c.LeaderElectionRenewDeadline = viper.GetDuration(LeaderElectionRenewDeadline)
c.LeaderElectionRetryPeriod = viper.GetDuration(LeaderElectionRetryPeriod)
// AWS options
c.AWSReleaseExcessIPs = viper.GetBool(AWSReleaseExcessIPs)
c.UpdateEC2AdapterLimitViaAPI = viper.GetBool(UpdateEC2AdapterLimitViaAPI)
c.EC2APIEndpoint = viper.GetString(EC2APIEndpoint)
// Azure options
c.AzureSubscriptionID = viper.GetString(AzureSubscriptionID)
c.AzureResourceGroup = viper.GetString(AzureResourceGroup)
// Option maps and slices
if m := viper.GetStringSlice(IPAMSubnetsIDs); len(m) != 0 {
c.IPAMSubnetsIDs = m
}
if m := viper.GetStringMapString(IPAMSubnetsTags); len(m) != 0 {
c.IPAMSubnetsTags = m
}
if m := viper.GetStringMapString(AWSInstanceLimitMapping); len(m) != 0 {
c.AWSInstanceLimitMapping = m
}
if m := viper.GetStringMapString(ENITags); len(m) != 0 {
c.ENITags = m
}
}
// Config represents the operator configuration.
var Config = &OperatorConfig{
IPAMSubnetsIDs: make([]string, 0),
IPAMSubnetsTags: make(map[string]string),
AWSInstanceLimitMapping: make(map[string]string),
ENITags: make(map[string]string),
}