From 35c113b4233c73053bba9464f132118f91cb28d4 Mon Sep 17 00:00:00 2001 From: Mengdie Song Date: Mon, 21 Aug 2023 15:31:22 +0800 Subject: [PATCH] Fix VM Agent RBAC warnings (#5391) Recent changes for K8s Node cause VM Agent RBAC warnings regarding service and node. These warnings will flood VM Agent logs. This change fixes the issue by only initializing the related components for K8s Node case. Signed-off-by: Mengdie Song --- cmd/antrea-agent/agent.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/antrea-agent/agent.go b/cmd/antrea-agent/agent.go index 196eb8a417e..4025f849d20 100644 --- a/cmd/antrea-agent/agent.go +++ b/cmd/antrea-agent/agent.go @@ -140,8 +140,10 @@ func run(o *Options) error { enableMulticlusterGW := features.DefaultFeatureGate.Enabled(features.Multicluster) && o.config.Multicluster.EnableGateway enableMulticlusterNP := features.DefaultFeatureGate.Enabled(features.Multicluster) && o.config.Multicluster.EnableStretchedNetworkPolicy enableFLowExporter := features.DefaultFeatureGate.Enabled(features.FlowExporter) && o.config.FlowExporter.Enable - - nodeIPTracker := nodeip.NewTracker(nodeInformer) + var nodeIPTracker *nodeip.Tracker + if o.nodeType == config.K8sNode { + nodeIPTracker = nodeip.NewTracker(nodeInformer) + } // Bridging mode will connect the uplink interface to the OVS bridge. connectUplinkToBridge := enableBridgingMode ovsDatapathType := ovsconfig.OVSDatapathType(o.config.OVSDatapathType) @@ -169,14 +171,15 @@ func run(o *Options) error { ) var serviceCIDRNet *net.IPNet + var serviceCIDRProvider *servicecidr.Discoverer if o.nodeType == config.K8sNode { _, serviceCIDRNet, _ = net.ParseCIDR(o.config.ServiceCIDR) + serviceCIDRProvider = servicecidr.NewServiceCIDRDiscoverer(serviceInformer) } var serviceCIDRNetv6 *net.IPNet if o.config.ServiceCIDRv6 != "" { _, serviceCIDRNetv6, _ = net.ParseCIDR(o.config.ServiceCIDRv6) } - serviceCIDRProvider := servicecidr.NewServiceCIDRDiscoverer(serviceInformer) _, encapMode := config.GetTrafficEncapModeFromStr(o.config.TrafficEncapMode) _, encryptionMode := config.GetTrafficEncryptionModeFromStr(o.config.TrafficEncryptionMode) @@ -232,8 +235,10 @@ func run(o *Options) error { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - // Must start after registering all event handlers. - go serviceCIDRProvider.Run(stopCh) + if o.nodeType == config.K8sNode { + // Must start after registering all event handlers. + go serviceCIDRProvider.Run(stopCh) + } // Get all available NodePort addresses. var nodePortAddressesIPv4, nodePortAddressesIPv6 []net.IP