Skip to content

Commit 4954293

Browse files
committed
Parse flow exporter config if featuregate is enabled
Signed-off-by: Andrew Su <[email protected]>
1 parent 8bc56ff commit 4954293

File tree

1 file changed

+46
-44
lines changed

1 file changed

+46
-44
lines changed

cmd/antrea-agent/options.go

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -279,59 +279,61 @@ func (o *Options) validateAntreaProxyConfig(encapMode config.TrafficEncapModeTyp
279279
}
280280

281281
func (o *Options) validateFlowExporterConfig() error {
282-
if features.DefaultFeatureGate.Enabled(features.FlowExporter) && o.config.FlowExporter.Enable {
283-
if features.DefaultFeatureGate.Enabled(features.AntreaIPAM) {
284-
klog.InfoS("The FlowExporter feature does not support AntreaIPAM Pods")
285-
}
286-
host, port, proto, err := flowexport.ParseFlowCollectorAddr(o.config.FlowExporter.FlowCollectorAddr, defaultFlowCollectorPort, defaultFlowCollectorTransport)
282+
if !features.DefaultFeatureGate.Enabled(features.FlowExporter) {
283+
klog.InfoS("Feature gate `FlowExporter` is disabled")
284+
return nil
285+
}
286+
287+
if features.DefaultFeatureGate.Enabled(features.AntreaIPAM) {
288+
klog.InfoS("The FlowExporter feature does not support AntreaIPAM Pods")
289+
}
290+
host, port, proto, err := flowexport.ParseFlowCollectorAddr(o.config.FlowExporter.FlowCollectorAddr, defaultFlowCollectorPort, defaultFlowCollectorTransport)
291+
if err != nil {
292+
return err
293+
}
294+
o.flowCollectorAddr = net.JoinHostPort(host, port)
295+
o.flowCollectorProto = proto
296+
297+
// Parse the given flowPollInterval config
298+
if o.config.FlowExporter.FlowPollInterval != "" {
299+
flowPollInterval, err := flowexport.ParseFlowIntervalString(o.config.FlowExporter.FlowPollInterval)
287300
if err != nil {
288301
return err
289302
}
290-
o.flowCollectorAddr = net.JoinHostPort(host, port)
291-
o.flowCollectorProto = proto
292-
293-
// Parse the given flowPollInterval config
294-
if o.config.FlowExporter.FlowPollInterval != "" {
295-
flowPollInterval, err := flowexport.ParseFlowIntervalString(o.config.FlowExporter.FlowPollInterval)
296-
if err != nil {
297-
return err
298-
}
299-
o.pollInterval = flowPollInterval
303+
o.pollInterval = flowPollInterval
304+
}
305+
// Parse the given activeFlowExportTimeout config
306+
if o.config.FlowExporter.ActiveFlowExportTimeout != "" {
307+
o.activeFlowTimeout, err = time.ParseDuration(o.config.FlowExporter.ActiveFlowExportTimeout)
308+
if err != nil {
309+
return fmt.Errorf("ActiveFlowExportTimeout is not provided in right format")
300310
}
301-
// Parse the given activeFlowExportTimeout config
302-
if o.config.FlowExporter.ActiveFlowExportTimeout != "" {
303-
o.activeFlowTimeout, err = time.ParseDuration(o.config.FlowExporter.ActiveFlowExportTimeout)
304-
if err != nil {
305-
return fmt.Errorf("ActiveFlowExportTimeout is not provided in right format")
306-
}
307-
if o.activeFlowTimeout < o.pollInterval {
308-
o.activeFlowTimeout = o.pollInterval
309-
klog.Warningf("ActiveFlowExportTimeout must be greater than or equal to FlowPollInterval")
310-
}
311+
if o.activeFlowTimeout < o.pollInterval {
312+
o.activeFlowTimeout = o.pollInterval
313+
klog.Warningf("ActiveFlowExportTimeout must be greater than or equal to FlowPollInterval")
311314
}
312-
// Parse the given inactiveFlowExportTimeout config
313-
if o.config.FlowExporter.IdleFlowExportTimeout != "" {
314-
o.idleFlowTimeout, err = time.ParseDuration(o.config.FlowExporter.IdleFlowExportTimeout)
315-
if err != nil {
316-
return fmt.Errorf("IdleFlowExportTimeout is not provided in right format")
317-
}
318-
if o.idleFlowTimeout < o.pollInterval {
319-
o.idleFlowTimeout = o.pollInterval
320-
klog.Warningf("IdleFlowExportTimeout must be greater than or equal to FlowPollInterval")
321-
}
315+
}
316+
// Parse the given inactiveFlowExportTimeout config
317+
if o.config.FlowExporter.IdleFlowExportTimeout != "" {
318+
o.idleFlowTimeout, err = time.ParseDuration(o.config.FlowExporter.IdleFlowExportTimeout)
319+
if err != nil {
320+
return fmt.Errorf("IdleFlowExportTimeout is not provided in right format")
322321
}
323-
if (o.activeFlowTimeout > defaultStaleConnectionTimeout) || (o.idleFlowTimeout > defaultStaleConnectionTimeout) {
324-
if o.activeFlowTimeout > o.idleFlowTimeout {
325-
o.staleConnectionTimeout = 2 * o.activeFlowTimeout
326-
} else {
327-
o.staleConnectionTimeout = 2 * o.idleFlowTimeout
328-
}
322+
if o.idleFlowTimeout < o.pollInterval {
323+
o.idleFlowTimeout = o.pollInterval
324+
klog.Warningf("IdleFlowExportTimeout must be greater than or equal to FlowPollInterval")
325+
}
326+
}
327+
if (o.activeFlowTimeout > defaultStaleConnectionTimeout) || (o.idleFlowTimeout > defaultStaleConnectionTimeout) {
328+
if o.activeFlowTimeout > o.idleFlowTimeout {
329+
o.staleConnectionTimeout = 2 * o.activeFlowTimeout
329330
} else {
330-
o.staleConnectionTimeout = defaultStaleConnectionTimeout
331+
o.staleConnectionTimeout = 2 * o.idleFlowTimeout
331332
}
332-
} else if o.config.FlowExporter.Enable {
333-
klog.InfoS("The FlowExporter.enable config option is set to true, but it will be ignored because the FlowExporter feature gate is disabled")
333+
} else {
334+
o.staleConnectionTimeout = defaultStaleConnectionTimeout
334335
}
336+
335337
return nil
336338
}
337339

0 commit comments

Comments
 (0)