@@ -87,6 +87,8 @@ const resyncPeriodDisabled = 0 * time.Minute
87
87
// The devices that should be excluded from NodePort.
88
88
var excludeNodePortDevices = []string {"antrea-egress0" , "antrea-ingress0" , "kube-ipvs0" }
89
89
90
+ var ipv4Localhost = net .ParseIP ("127.0.0.1" )
91
+
90
92
// run starts Antrea agent with the given options and waits for termination signal.
91
93
func run (o * Options ) error {
92
94
klog .Infof ("Starting Antrea agent (version %s)" , version .GetFullVersion ())
@@ -147,7 +149,10 @@ func run(o *Options) error {
147
149
features .DefaultFeatureGate .Enabled (features .Multicluster ),
148
150
)
149
151
150
- _ , serviceCIDRNet , _ := net .ParseCIDR (o .config .ServiceCIDR )
152
+ var serviceCIDRNet * net.IPNet
153
+ if o .nodeType == config .K8sNode {
154
+ _ , serviceCIDRNet , _ = net .ParseCIDR (o .config .ServiceCIDR )
155
+ }
151
156
var serviceCIDRNetv6 * net.IPNet
152
157
if o .config .ServiceCIDRv6 != "" {
153
158
_ , serviceCIDRNetv6 , _ = net .ParseCIDR (o .config .ServiceCIDRv6 )
@@ -234,6 +239,7 @@ func run(o *Options) error {
234
239
serviceConfig ,
235
240
networkReadyCh ,
236
241
stopCh ,
242
+ o .nodeType ,
237
243
features .DefaultFeatureGate .Enabled (features .AntreaProxy ),
238
244
o .config .AntreaProxy .ProxyAll ,
239
245
connectUplinkToBridge )
@@ -250,19 +256,22 @@ func run(o *Options) error {
250
256
ipsecCertController = ipseccertificate .NewIPSecCertificateController (k8sClient , ovsBridgeClient , nodeConfig .Name )
251
257
}
252
258
253
- nodeRouteController := noderoute .NewNodeRouteController (
254
- k8sClient ,
255
- informerFactory ,
256
- ofClient ,
257
- ovsBridgeClient ,
258
- routeClient ,
259
- ifaceStore ,
260
- networkConfig ,
261
- nodeConfig ,
262
- agentInitializer .GetWireGuardClient (),
263
- o .config .AntreaProxy .ProxyAll ,
264
- ipsecCertController ,
265
- )
259
+ var nodeRouteController * noderoute.Controller
260
+ if o .nodeType == config .K8sNode {
261
+ nodeRouteController = noderoute .NewNodeRouteController (
262
+ k8sClient ,
263
+ informerFactory ,
264
+ ofClient ,
265
+ ovsBridgeClient ,
266
+ routeClient ,
267
+ ifaceStore ,
268
+ networkConfig ,
269
+ nodeConfig ,
270
+ agentInitializer .GetWireGuardClient (),
271
+ o .config .AntreaProxy .ProxyAll ,
272
+ ipsecCertController ,
273
+ )
274
+ }
266
275
267
276
var mcRouteController * mcroute.MCRouteController
268
277
var mcInformerFactory mcinformers.SharedInformerFactory
@@ -403,33 +412,36 @@ func run(o *Options) error {
403
412
}
404
413
}
405
414
406
- isChaining := false
407
- if networkConfig .TrafficEncapMode .IsNetworkPolicyOnly () {
408
- isChaining = true
409
- }
410
- cniServer := cniserver .New (
411
- o .config .CNISocket ,
412
- o .config .HostProcPathPrefix ,
413
- nodeConfig ,
414
- k8sClient ,
415
- routeClient ,
416
- isChaining ,
417
- enableBridgingMode ,
418
- enableAntreaIPAM ,
419
- o .config .DisableTXChecksumOffload ,
420
- networkReadyCh )
421
-
415
+ var cniServer * cniserver.CNIServer
422
416
var cniPodInfoStore cnipodcache.CNIPodInfoStore
423
- if features .DefaultFeatureGate .Enabled (features .SecondaryNetwork ) {
424
- cniPodInfoStore = cnipodcache .NewCNIPodInfoStore ()
425
- err = cniServer .Initialize (ovsBridgeClient , ofClient , ifaceStore , podUpdateChannel , cniPodInfoStore )
426
- if err != nil {
427
- return fmt .Errorf ("error initializing CNI server with cniPodInfoStore cache: %v" , err )
417
+ if o .nodeType == config .K8sNode {
418
+ isChaining := false
419
+ if networkConfig .TrafficEncapMode .IsNetworkPolicyOnly () {
420
+ isChaining = true
428
421
}
429
- } else {
430
- err = cniServer .Initialize (ovsBridgeClient , ofClient , ifaceStore , podUpdateChannel , nil )
431
- if err != nil {
432
- return fmt .Errorf ("error initializing CNI server: %v" , err )
422
+ cniServer = cniserver .New (
423
+ o .config .CNISocket ,
424
+ o .config .HostProcPathPrefix ,
425
+ nodeConfig ,
426
+ k8sClient ,
427
+ routeClient ,
428
+ isChaining ,
429
+ enableBridgingMode ,
430
+ enableAntreaIPAM ,
431
+ o .config .DisableTXChecksumOffload ,
432
+ networkReadyCh )
433
+
434
+ if features .DefaultFeatureGate .Enabled (features .SecondaryNetwork ) {
435
+ cniPodInfoStore = cnipodcache .NewCNIPodInfoStore ()
436
+ err = cniServer .Initialize (ovsBridgeClient , ofClient , ifaceStore , podUpdateChannel , cniPodInfoStore )
437
+ if err != nil {
438
+ return fmt .Errorf ("error initializing CNI server with cniPodInfoStore cache: %v" , err )
439
+ }
440
+ } else {
441
+ err = cniServer .Initialize (ovsBridgeClient , ofClient , ifaceStore , podUpdateChannel , nil )
442
+ if err != nil {
443
+ return fmt .Errorf ("error initializing CNI server: %v" , err )
444
+ }
433
445
}
434
446
}
435
447
@@ -519,11 +531,17 @@ func run(o *Options) error {
519
531
520
532
log .StartLogFileNumberMonitor (stopCh )
521
533
522
- go podUpdateChannel .Run (stopCh )
523
-
524
- go routeClient .Run (stopCh )
534
+ if o .nodeType == config .K8sNode {
535
+ go routeClient .Run (stopCh )
536
+ go podUpdateChannel .Run (stopCh )
537
+ go cniServer .Run (stopCh )
538
+ go nodeRouteController .Run (stopCh )
539
+ }
525
540
526
- go cniServer .Run (stopCh )
541
+ if networkConfig .TrafficEncryptionMode == config .TrafficEncryptionModeIPSec &&
542
+ networkConfig .IPsecConfig .AuthenticationMode == config .IPsecAuthenticationModeCert {
543
+ go ipsecCertController .Run (stopCh )
544
+ }
527
545
528
546
go antreaClientProvider .Run (ctx )
529
547
@@ -532,8 +550,6 @@ func run(o *Options) error {
532
550
go ipsecCertController .Run (stopCh )
533
551
}
534
552
535
- go nodeRouteController .Run (stopCh )
536
-
537
553
go networkPolicyController .Run (stopCh )
538
554
// Initialize the NPL agent.
539
555
if enableNodePortLocal {
@@ -691,11 +707,16 @@ func run(o *Options) error {
691
707
if err != nil {
692
708
return fmt .Errorf ("error generating Cipher Suite list: %v" , err )
693
709
}
710
+ bindAddress := net .IPv4zero
711
+ if o .nodeType == config .ExternalNode {
712
+ bindAddress = ipv4Localhost
713
+ }
694
714
apiServer , err := apiserver .New (
695
715
agentQuerier ,
696
716
networkPolicyController ,
697
717
mcastController ,
698
718
externalIPController ,
719
+ bindAddress ,
699
720
o .config .APIPort ,
700
721
* o .config .EnablePrometheusMetrics ,
701
722
o .config .ClientConnection .Kubeconfig ,
0 commit comments