Skip to content

Commit

Permalink
Rearrange code
Browse files Browse the repository at this point in the history
  • Loading branch information
heanlan committed Oct 6, 2021
1 parent 49a812a commit b7c2691
Showing 1 changed file with 53 additions and 45 deletions.
98 changes: 53 additions & 45 deletions cmd/antrea-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"antrea.io/antrea/pkg/agent/interfacestore"
"antrea.io/antrea/pkg/agent/metrics"
npl "antrea.io/antrea/pkg/agent/nodeportlocal"
nplk8s "antrea.io/antrea/pkg/agent/nodeportlocal/k8s"
"antrea.io/antrea/pkg/agent/openflow"
"antrea.io/antrea/pkg/agent/proxy"
"antrea.io/antrea/pkg/agent/querier"
Expand Down Expand Up @@ -313,6 +314,57 @@ func run(o *Options) error {
return err
}

// Start the NPL agent.
var nplController *nplk8s.NPLController
if features.DefaultFeatureGate.Enabled(features.NodePortLocal) {
nplController, err = npl.InitializeNPLAgent(
k8sClient,
informerFactory,
o.config.NPLPortRange,
nodeConfig.Name)
if err != nil {
return fmt.Errorf("failed to start NPL agent: %v", err)
}
}

agentQuerier := querier.NewAgentQuerier(
nodeConfig,
networkConfig,
ifaceStore,
k8sClient,
ofClient,
ovsBridgeClient,
proxier,
networkPolicyController,
o.config.APIPort)

agentMonitor := monitor.NewAgentMonitor(crdClient, legacyCRDClient, agentQuerier)

cipherSuites, err := cipher.GenerateCipherSuitesList(o.config.TLSCipherSuites)
if err != nil {
return fmt.Errorf("error generating Cipher Suite list: %v", err)
}
apiServer, err := apiserver.New(
agentQuerier,
networkPolicyController,
o.config.APIPort,
o.config.EnablePrometheusMetrics,
o.config.ClientConnection.Kubeconfig,
cipherSuites,
cipher.TLSVersionMap[o.config.TLSMinVersion])
if err != nil {
return fmt.Errorf("error when creating agent API server: %v", err)
}

// Start PacketIn for features and specify their own reason.
var packetInReasons []uint8
if features.DefaultFeatureGate.Enabled(features.Traceflow) {
packetInReasons = append(packetInReasons, uint8(openflow.PacketInReasonTF))
}
if features.DefaultFeatureGate.Enabled(features.AntreaPolicy) {
packetInReasons = append(packetInReasons, uint8(openflow.PacketInReasonNP))
}

// Initialize denyConnStore, conntrackConnStore, flowExporter.
var denyConnStore *connections.DenyConnectionStore
var conntrackConnStore *connections.ConntrackConnectionStore
Expand Down Expand Up @@ -358,16 +410,8 @@ func run(o *Options) error {
}
}

// Start the NPL agent.
// Start all the goroutines.
if features.DefaultFeatureGate.Enabled(features.NodePortLocal) {
nplController, err := npl.InitializeNPLAgent(
k8sClient,
informerFactory,
o.config.NPLPortRange,
nodeConfig.Name)
if err != nil {
return fmt.Errorf("failed to start NPL agent: %v", err)
}
go nplController.Run(stopCh)
}

Expand Down Expand Up @@ -402,46 +446,10 @@ func run(o *Options) error {
go proxier.GetProxyProvider().Run(stopCh)
}

agentQuerier := querier.NewAgentQuerier(
nodeConfig,
networkConfig,
ifaceStore,
k8sClient,
ofClient,
ovsBridgeClient,
proxier,
networkPolicyController,
o.config.APIPort)

agentMonitor := monitor.NewAgentMonitor(crdClient, legacyCRDClient, agentQuerier)

go agentMonitor.Run(stopCh)

cipherSuites, err := cipher.GenerateCipherSuitesList(o.config.TLSCipherSuites)
if err != nil {
return fmt.Errorf("error generating Cipher Suite list: %v", err)
}
apiServer, err := apiserver.New(
agentQuerier,
networkPolicyController,
o.config.APIPort,
o.config.EnablePrometheusMetrics,
o.config.ClientConnection.Kubeconfig,
cipherSuites,
cipher.TLSVersionMap[o.config.TLSMinVersion])
if err != nil {
return fmt.Errorf("error when creating agent API server: %v", err)
}
go apiServer.Run(stopCh)

// Start PacketIn for features and specify their own reason.
var packetInReasons []uint8
if features.DefaultFeatureGate.Enabled(features.Traceflow) {
packetInReasons = append(packetInReasons, uint8(openflow.PacketInReasonTF))
}
if features.DefaultFeatureGate.Enabled(features.AntreaPolicy) {
packetInReasons = append(packetInReasons, uint8(openflow.PacketInReasonNP))
}
if len(packetInReasons) > 0 {
go ofClient.StartPacketInHandler(packetInReasons, stopCh)
}
Expand Down

0 comments on commit b7c2691

Please sign in to comment.