Skip to content

Commit

Permalink
Add controller to antrea-agent for implementing Egress (#2026)
Browse files Browse the repository at this point in the history
The controller watches Egress and EgressGroup API and calls openflow
client and route client to enforce an Egress.

Co-authored-by: ceclinux <ceclinux@users.noreply.github.com>
  • Loading branch information
tnqn and ceclinux authored Apr 7, 2021
1 parent b73ab99 commit e36c4f2
Show file tree
Hide file tree
Showing 17 changed files with 2,197 additions and 9 deletions.
52 changes: 52 additions & 0 deletions build/yamls/antrea-aks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,58 @@ spec:
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
labels:
app: antrea
name: egresses.crd.antrea.io
spec:
group: crd.antrea.io
names:
kind: Egress
plural: egresses
shortNames:
- eg
singular: egress
scope: Cluster
versions:
- additionalPrinterColumns:
- description: Specifies the SNAT IP address for the selected workloads.
jsonPath: .spec.egressIP
name: EgressIP
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha2
schema:
openAPIV3Schema:
properties:
spec:
properties:
appliedTo:
properties:
namespaceSelector:
x-kubernetes-preserve-unknown-fields: true
podSelector:
x-kubernetes-preserve-unknown-fields: true
type: object
egressIP:
oneOf:
- format: ipv4
- format: ipv6
type: string
required:
- appliedTo
- egressIP
type: object
required:
- spec
type: object
served: true
storage: true
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
labels:
app: antrea
Expand Down
52 changes: 52 additions & 0 deletions build/yamls/antrea-eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,58 @@ spec:
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
labels:
app: antrea
name: egresses.crd.antrea.io
spec:
group: crd.antrea.io
names:
kind: Egress
plural: egresses
shortNames:
- eg
singular: egress
scope: Cluster
versions:
- additionalPrinterColumns:
- description: Specifies the SNAT IP address for the selected workloads.
jsonPath: .spec.egressIP
name: EgressIP
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha2
schema:
openAPIV3Schema:
properties:
spec:
properties:
appliedTo:
properties:
namespaceSelector:
x-kubernetes-preserve-unknown-fields: true
podSelector:
x-kubernetes-preserve-unknown-fields: true
type: object
egressIP:
oneOf:
- format: ipv4
- format: ipv6
type: string
required:
- appliedTo
- egressIP
type: object
required:
- spec
type: object
served: true
storage: true
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
labels:
app: antrea
Expand Down
52 changes: 52 additions & 0 deletions build/yamls/antrea-gke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,58 @@ spec:
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
labels:
app: antrea
name: egresses.crd.antrea.io
spec:
group: crd.antrea.io
names:
kind: Egress
plural: egresses
shortNames:
- eg
singular: egress
scope: Cluster
versions:
- additionalPrinterColumns:
- description: Specifies the SNAT IP address for the selected workloads.
jsonPath: .spec.egressIP
name: EgressIP
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha2
schema:
openAPIV3Schema:
properties:
spec:
properties:
appliedTo:
properties:
namespaceSelector:
x-kubernetes-preserve-unknown-fields: true
podSelector:
x-kubernetes-preserve-unknown-fields: true
type: object
egressIP:
oneOf:
- format: ipv4
- format: ipv6
type: string
required:
- appliedTo
- egressIP
type: object
required:
- spec
type: object
served: true
storage: true
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
labels:
app: antrea
Expand Down
52 changes: 52 additions & 0 deletions build/yamls/antrea-ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,58 @@ spec:
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
labels:
app: antrea
name: egresses.crd.antrea.io
spec:
group: crd.antrea.io
names:
kind: Egress
plural: egresses
shortNames:
- eg
singular: egress
scope: Cluster
versions:
- additionalPrinterColumns:
- description: Specifies the SNAT IP address for the selected workloads.
jsonPath: .spec.egressIP
name: EgressIP
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha2
schema:
openAPIV3Schema:
properties:
spec:
properties:
appliedTo:
properties:
namespaceSelector:
x-kubernetes-preserve-unknown-fields: true
podSelector:
x-kubernetes-preserve-unknown-fields: true
type: object
egressIP:
oneOf:
- format: ipv4
- format: ipv6
type: string
required:
- appliedTo
- egressIP
type: object
required:
- spec
type: object
served: true
storage: true
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
labels:
app: antrea
Expand Down
52 changes: 52 additions & 0 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,58 @@ spec:
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
labels:
app: antrea
name: egresses.crd.antrea.io
spec:
group: crd.antrea.io
names:
kind: Egress
plural: egresses
shortNames:
- eg
singular: egress
scope: Cluster
versions:
- additionalPrinterColumns:
- description: Specifies the SNAT IP address for the selected workloads.
jsonPath: .spec.egressIP
name: EgressIP
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha2
schema:
openAPIV3Schema:
properties:
spec:
properties:
appliedTo:
properties:
namespaceSelector:
x-kubernetes-preserve-unknown-fields: true
podSelector:
x-kubernetes-preserve-unknown-fields: true
type: object
egressIP:
oneOf:
- format: ipv4
- format: ipv6
type: string
required:
- appliedTo
- egressIP
type: object
required:
- spec
type: object
served: true
storage: true
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
labels:
app: antrea
Expand Down
50 changes: 50 additions & 0 deletions build/yamls/base/crds.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,56 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: egresses.crd.antrea.io
spec:
group: crd.antrea.io
versions:
- name: v1alpha2
served: true
storage: true
schema:
openAPIV3Schema:
type: object
required:
- spec
properties:
spec:
type: object
required:
- appliedTo
- egressIP
properties:
appliedTo:
type: object
properties:
podSelector:
x-kubernetes-preserve-unknown-fields: true
namespaceSelector:
x-kubernetes-preserve-unknown-fields: true
egressIP:
type: string
oneOf:
- format: ipv4
- format: ipv6
additionalPrinterColumns:
- description: Specifies the SNAT IP address for the selected workloads.
jsonPath: .spec.egressIP
name: EgressIP
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
scope: Cluster
names:
plural: egresses
singular: egress
kind: Egress
shortNames:
- eg
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: antreacontrollerinfos.crd.antrea.io
spec:
Expand Down
13 changes: 12 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 @@ -75,6 +76,7 @@ func run(o *Options) error {
informerFactory := informers.NewSharedInformerFactory(k8sClient, informerDefaultResync)
crdInformerFactory := crdinformers.NewSharedInformerFactory(crdClient, informerDefaultResync)
traceflowInformer := crdInformerFactory.Crd().V1alpha1().Traceflows()
egressInformer := crdInformerFactory.Crd().V1alpha2().Egresses()

// Create Antrea Clientset for the given config.
antreaClientProvider := agent.NewAntreaClientProvider(o.config.AntreaClientConnection, k8sClient)
Expand All @@ -99,7 +101,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 @@ -191,6 +193,11 @@ func run(o *Options) error {
statsCollector = stats.NewCollector(antreaClientProvider, ofClient, networkPolicyController)
}

var egressController *egress.EgressController
if features.DefaultFeatureGate.Enabled(features.Egress) {
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 @@ -282,6 +289,10 @@ func run(o *Options) error {

go networkPolicyController.Run(stopCh)

if features.DefaultFeatureGate.Enabled(features.Egress) {
go egressController.Run(stopCh)
}

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

0 comments on commit e36c4f2

Please sign in to comment.