Skip to content

Commit be2955d

Browse files
wenyingdmengdie-song
authored andcommittedAug 8, 2022
[ExternalNode] Support role configuration on antrea agent (antrea-io#3542)
1. Add feature gate for ExternalNode which enables running Agent on a VM or BM. 2. Support Agent running APIServer only on localhost if it is not running on cluster worker Node. 3. CNIServer is loaded only when Agent is running on cluster worker Node. 4. Use a seperate build directory to generate agent configrations for ExternalNode. Signed-off-by: wenyingd <wenyingd@vmware.com>
1 parent 286b0be commit be2955d

File tree

19 files changed

+660
-409
lines changed

19 files changed

+660
-409
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# FeatureGates is a map of feature names to bools that enable or disable experimental features.
2+
featureGates:
3+
# Enable running agent on an unmanaged VM/BM.
4+
ExternalNode: true
5+
6+
# Enable Antrea ClusterNetworkPolicy feature to complement K8s NetworkPolicy for cluster admins
7+
# to define security policies which apply to the entire cluster, and Antrea NetworkPolicy
8+
# feature that supports priorities, rule actions and externalEntities in the future.
9+
AntreaPolicy: true
10+
11+
# Enable collecting and exposing NetworkPolicy statistics.
12+
NetworkPolicyStats: true
13+
14+
# Name of the OpenVSwitch bridge antrea-agent will create and use.
15+
# Make sure it doesn't conflict with your existing OpenVSwitch bridges.
16+
#ovsBridge: br-int
17+
18+
# Datapath type to use for the OpenVSwitch bridge created by Antrea. Supported values are:
19+
# - system
20+
# - netdev
21+
# 'system' is the default value and corresponds to the kernel datapath. Use 'netdev' to run
22+
# OVS in userspace mode (not fully supported yet). Userspace mode requires the tun device driver to
23+
# be available.
24+
#ovsDatapathType: system
25+
26+
# The port for the antrea-agent APIServer to serve on.
27+
# Note that if it's set to another value, the `containerPort` of the `api` port of the
28+
# `antrea-agent` container must be set to the same value.
29+
#apiPort: 10350
30+
31+
# NodeType is type of the Node where Antrea Agent is running.
32+
# Defaults to "k8sNode". Valid values include "k8sNode", and "externalNode".
33+
nodeType: externalNode
34+
35+
# The path to access the kubeconfig file used in the connection to K8s APIServer. The file contains the K8s
36+
# APIServer endpoint and the token of ServiceAccount required in the connection.
37+
clientConnection:
38+
kubeconfig: antrea-agent.kubeconfig
39+
40+
# The path to access the kubeconfig file used in the connection to Antrea Controller. The file contains the
41+
# antrea-controller APIServer endpoint and the token of ServiceAccount required in the connection.
42+
antreaClientConnection:
43+
kubeconfig: antrea-agent.antrea.kubeconfig

‎cmd/antrea-agent/agent.go

+66-45
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ const resyncPeriodDisabled = 0 * time.Minute
8787
// The devices that should be excluded from NodePort.
8888
var excludeNodePortDevices = []string{"antrea-egress0", "antrea-ingress0", "kube-ipvs0"}
8989

90+
var ipv4Localhost = net.ParseIP("127.0.0.1")
91+
9092
// run starts Antrea agent with the given options and waits for termination signal.
9193
func run(o *Options) error {
9294
klog.Infof("Starting Antrea agent (version %s)", version.GetFullVersion())
@@ -147,7 +149,10 @@ func run(o *Options) error {
147149
features.DefaultFeatureGate.Enabled(features.Multicluster),
148150
)
149151

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+
}
151156
var serviceCIDRNetv6 *net.IPNet
152157
if o.config.ServiceCIDRv6 != "" {
153158
_, serviceCIDRNetv6, _ = net.ParseCIDR(o.config.ServiceCIDRv6)
@@ -234,6 +239,7 @@ func run(o *Options) error {
234239
serviceConfig,
235240
networkReadyCh,
236241
stopCh,
242+
o.nodeType,
237243
features.DefaultFeatureGate.Enabled(features.AntreaProxy),
238244
o.config.AntreaProxy.ProxyAll,
239245
connectUplinkToBridge)
@@ -250,19 +256,22 @@ func run(o *Options) error {
250256
ipsecCertController = ipseccertificate.NewIPSecCertificateController(k8sClient, ovsBridgeClient, nodeConfig.Name)
251257
}
252258

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+
}
266275

267276
var mcRouteController *mcroute.MCRouteController
268277
var mcInformerFactory mcinformers.SharedInformerFactory
@@ -403,33 +412,36 @@ func run(o *Options) error {
403412
}
404413
}
405414

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
422416
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
428421
}
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+
}
433445
}
434446
}
435447

@@ -519,11 +531,17 @@ func run(o *Options) error {
519531

520532
log.StartLogFileNumberMonitor(stopCh)
521533

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+
}
525540

526-
go cniServer.Run(stopCh)
541+
if networkConfig.TrafficEncryptionMode == config.TrafficEncryptionModeIPSec &&
542+
networkConfig.IPsecConfig.AuthenticationMode == config.IPsecAuthenticationModeCert {
543+
go ipsecCertController.Run(stopCh)
544+
}
527545

528546
go antreaClientProvider.Run(ctx)
529547

@@ -532,8 +550,6 @@ func run(o *Options) error {
532550
go ipsecCertController.Run(stopCh)
533551
}
534552

535-
go nodeRouteController.Run(stopCh)
536-
537553
go networkPolicyController.Run(stopCh)
538554
// Initialize the NPL agent.
539555
if enableNodePortLocal {
@@ -691,11 +707,16 @@ func run(o *Options) error {
691707
if err != nil {
692708
return fmt.Errorf("error generating Cipher Suite list: %v", err)
693709
}
710+
bindAddress := net.IPv4zero
711+
if o.nodeType == config.ExternalNode {
712+
bindAddress = ipv4Localhost
713+
}
694714
apiServer, err := apiserver.New(
695715
agentQuerier,
696716
networkPolicyController,
697717
mcastController,
698718
externalIPController,
719+
bindAddress,
699720
o.config.APIPort,
700721
*o.config.EnablePrometheusMetrics,
701722
o.config.ClientConnection.Kubeconfig,

0 commit comments

Comments
 (0)
Please sign in to comment.