Skip to content

Commit

Permalink
Add controller to antrea-agent for implementing Egress
Browse files Browse the repository at this point in the history
  • Loading branch information
tnqn committed Apr 2, 2021
1 parent 27747ee commit 989c51d
Show file tree
Hide file tree
Showing 13 changed files with 987 additions and 26 deletions.
5 changes: 3 additions & 2 deletions build/yamls/antrea-aks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ spec:
- --alsologtostderr
- --log_file_max_size=100
- --log_file_max_num=4
- --v=0
- --v=5
command:
- antrea-controller
env:
Expand Down Expand Up @@ -1694,6 +1694,7 @@ spec:
name: host-var-log-antrea
hostNetwork: true
nodeSelector:
kubernetes.io/hostname: k8s01
kubernetes.io/os: linux
priorityClassName: system-cluster-critical
serviceAccountName: antrea-controller
Expand Down Expand Up @@ -1819,7 +1820,7 @@ spec:
- --alsologtostderr
- --log_file_max_size=100
- --log_file_max_num=4
- --v=0
- --v=5
command:
- antrea-agent
env:
Expand Down
5 changes: 3 additions & 2 deletions build/yamls/antrea-eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ spec:
- --alsologtostderr
- --log_file_max_size=100
- --log_file_max_num=4
- --v=0
- --v=5
command:
- antrea-controller
env:
Expand Down Expand Up @@ -1694,6 +1694,7 @@ spec:
name: host-var-log-antrea
hostNetwork: true
nodeSelector:
kubernetes.io/hostname: k8s01
kubernetes.io/os: linux
priorityClassName: system-cluster-critical
serviceAccountName: antrea-controller
Expand Down Expand Up @@ -1819,7 +1820,7 @@ spec:
- --alsologtostderr
- --log_file_max_size=100
- --log_file_max_num=4
- --v=0
- --v=5
command:
- antrea-agent
env:
Expand Down
5 changes: 3 additions & 2 deletions build/yamls/antrea-gke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ spec:
- --alsologtostderr
- --log_file_max_size=100
- --log_file_max_num=4
- --v=0
- --v=5
command:
- antrea-controller
env:
Expand Down Expand Up @@ -1694,6 +1694,7 @@ spec:
name: host-var-log-antrea
hostNetwork: true
nodeSelector:
kubernetes.io/hostname: k8s01
kubernetes.io/os: linux
priorityClassName: system-cluster-critical
serviceAccountName: antrea-controller
Expand Down Expand Up @@ -1819,7 +1820,7 @@ spec:
- --alsologtostderr
- --log_file_max_size=100
- --log_file_max_num=4
- --v=0
- --v=5
command:
- antrea-agent
env:
Expand Down
5 changes: 3 additions & 2 deletions build/yamls/antrea-ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ spec:
- --alsologtostderr
- --log_file_max_size=100
- --log_file_max_num=4
- --v=0
- --v=5
command:
- antrea-controller
env:
Expand Down Expand Up @@ -1708,6 +1708,7 @@ spec:
name: host-var-log-antrea
hostNetwork: true
nodeSelector:
kubernetes.io/hostname: k8s01
kubernetes.io/os: linux
priorityClassName: system-cluster-critical
serviceAccountName: antrea-controller
Expand Down Expand Up @@ -1863,7 +1864,7 @@ spec:
- --alsologtostderr
- --log_file_max_size=100
- --log_file_max_num=4
- --v=0
- --v=5
command:
- antrea-agent
env:
Expand Down
9 changes: 5 additions & 4 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ data:
# NetworkPolicyStats: false
# Enable controlling SNAT IPs of Pod egress traffic.
# Egress: false
Egress: true
# Name of the OpenVSwitch bridge antrea-agent will create and use.
# Make sure it doesn't conflict with your existing OpenVSwitch bridges.
Expand Down Expand Up @@ -1557,7 +1557,7 @@ data:
# NetworkPolicyStats: false
# Enable controlling SNAT IPs of Pod egress traffic.
# Egress: false
Egress: true
# The port for the antrea-controller APIServer to serve on.
# Note that if it's set to another value, the `containerPort` of the `api` port of the
Expand Down Expand Up @@ -1639,7 +1639,7 @@ spec:
- --alsologtostderr
- --log_file_max_size=100
- --log_file_max_num=4
- --v=0
- --v=5
command:
- antrea-controller
env:
Expand Down Expand Up @@ -1699,6 +1699,7 @@ spec:
name: host-var-log-antrea
hostNetwork: true
nodeSelector:
kubernetes.io/hostname: k8s01
kubernetes.io/os: linux
priorityClassName: system-cluster-critical
serviceAccountName: antrea-controller
Expand Down Expand Up @@ -1824,7 +1825,7 @@ spec:
- --alsologtostderr
- --log_file_max_size=100
- --log_file_max_num=4
- --v=0
- --v=5
command:
- antrea-agent
env:
Expand Down
2 changes: 1 addition & 1 deletion build/yamls/base/agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ spec:
cpu: "200m"
command: ["antrea-agent"]
# Log to both "/var/log/antrea/" and stderr (so "kubectl logs" can work).
args: ["--config", "/etc/antrea/antrea-agent.conf", "--logtostderr=false", "--log_dir=/var/log/antrea", "--alsologtostderr", "--log_file_max_size=100", "--log_file_max_num=4", "--v=0"]
args: ["--config", "/etc/antrea/antrea-agent.conf", "--logtostderr=false", "--log_dir=/var/log/antrea", "--alsologtostderr", "--log_file_max_size=100", "--log_file_max_num=4", "--v=5"]
env:
# Provide pod and node information for clusterinformation CRD.
- name: POD_NAME
Expand Down
3 changes: 2 additions & 1 deletion build/yamls/base/controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ spec:
spec:
nodeSelector:
kubernetes.io/os: linux
kubernetes.io/hostname: k8s01
hostNetwork: true
priorityClassName: system-cluster-critical
tolerations:
Expand All @@ -217,7 +218,7 @@ spec:
cpu: "200m"
command: ["antrea-controller"]
# Log to both "/var/log/antrea/" and stderr (so "kubectl logs" can work).
args: ["--config", "/etc/antrea/antrea-controller.conf", "--logtostderr=false", "--log_dir=/var/log/antrea", "--alsologtostderr", "--log_file_max_size=100", "--log_file_max_num=4", "--v=0"]
args: ["--config", "/etc/antrea/antrea-controller.conf", "--logtostderr=false", "--log_dir=/var/log/antrea", "--alsologtostderr", "--log_file_max_size=100", "--log_file_max_num=4", "--v=5"]
env:
# Provide pod and node information for clusterinformation CRD.
- name: POD_NAME
Expand Down
8 changes: 7 additions & 1 deletion cmd/antrea-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/vmware-tanzu/antrea/pkg/agent/cniserver"
_ "github.com/vmware-tanzu/antrea/pkg/agent/cniserver/ipam"
"github.com/vmware-tanzu/antrea/pkg/agent/config"
"github.com/vmware-tanzu/antrea/pkg/agent/controller/egress"
"github.com/vmware-tanzu/antrea/pkg/agent/controller/networkpolicy"
"github.com/vmware-tanzu/antrea/pkg/agent/controller/noderoute"
"github.com/vmware-tanzu/antrea/pkg/agent/controller/traceflow"
Expand Down Expand Up @@ -70,6 +71,7 @@ func run(o *Options) error {
informerFactory := informers.NewSharedInformerFactory(k8sClient, informerDefaultResync)
crdInformerFactory := crdinformers.NewSharedInformerFactory(crdClient, informerDefaultResync)
traceflowInformer := crdInformerFactory.Ops().V1alpha1().Traceflows()
egressInformer := crdInformerFactory.Egress().V1alpha1().Egresses()

// Create Antrea Clientset for the given config.
antreaClientProvider := agent.NewAntreaClientProvider(o.config.AntreaClientConnection, k8sClient)
Expand All @@ -94,7 +96,7 @@ func run(o *Options) error {
ofClient := openflow.NewClient(o.config.OVSBridge, ovsBridgeMgmtAddr, ovsDatapathType,
features.DefaultFeatureGate.Enabled(features.AntreaProxy),
features.DefaultFeatureGate.Enabled(features.AntreaPolicy),
false)
features.DefaultFeatureGate.Enabled(features.Egress))

_, serviceCIDRNet, _ := net.ParseCIDR(o.config.ServiceCIDR)
var serviceCIDRNetv6 *net.IPNet
Expand Down Expand Up @@ -186,6 +188,8 @@ func run(o *Options) error {
statsCollector = stats.NewCollector(antreaClientProvider, ofClient, networkPolicyController)
}

egressController := egress.NewEgressController(ofClient, egressInformer, antreaClientProvider, ifaceStore, routeClient, nodeConfig.Name)

var proxier proxy.Proxier
if features.DefaultFeatureGate.Enabled(features.AntreaProxy) {
v4Enabled := config.IsIPv4Enabled(nodeConfig, networkConfig.TrafficEncapMode)
Expand Down Expand Up @@ -277,6 +281,8 @@ func run(o *Options) error {

go networkPolicyController.Run(stopCh)

go egressController.Run(stopCh)

if features.DefaultFeatureGate.Enabled(features.NetworkPolicyStats) {
go statsCollector.Run(stopCh)
}
Expand Down
Loading

0 comments on commit 989c51d

Please sign in to comment.