Skip to content

Commit

Permalink
Support Pod to Pod connectivity
Browse files Browse the repository at this point in the history
Signed-off-by: hujiajing <[email protected]>
  • Loading branch information
hjiajing committed Sep 27, 2022
1 parent 0f77529 commit 552e8c8
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 3 deletions.
2 changes: 2 additions & 0 deletions multicluster/apis/multicluster/v1alpha1/gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type ClusterInfo struct {
ServiceCIDR string `json:"serviceCIDR,omitempty"`
// GatewayInfos has information of Gateways
GatewayInfos []GatewayInfo `json:"gatewayInfos,omitempty"`
// PodCIDRs is the Pod IP address CIDRs.
PodCIDRs []string `json:"podCIDRs,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type MultiClusterConfig struct {
config.ControllerManagerConfigurationSpec `json:",inline"`
// ServiceCIDR allows user to set the ClusterIP range of the cluster manually.
ServiceCIDR string `json:"serviceCIDR,omitempty"`
// PodCIDRs is the Pod IP address CIDRs.
PodCIDRs []string `json:"podCIDRs,omitempty"`
// The precedence about which IP address (internal or external IP) of Node is preferred to
// be used as the cross-cluster tunnel endpoint. if not specified, internal IP will be chosen.
GatewayIPPrecedence Precedence `json:"gatewayIPPrecedence,omitempty"`
Expand Down
10 changes: 10 additions & 0 deletions multicluster/build/yamls/antrea-multicluster-leader-global.yml
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ spec:
type: string
type: object
type: array
podCIDRs:
description: PodCIDRs is the Pod IP address CIDRs.
items:
type: string
type: array
serviceCIDR:
description: ServiceCIDR is the IP ranges used by Service ClusterIP.
type: string
Expand Down Expand Up @@ -3268,6 +3273,11 @@ spec:
type: string
type: object
type: array
podCIDRs:
description: PodCIDRs is the Pod IP address CIDRs.
items:
type: string
type: array
serviceCIDR:
description: ServiceCIDR is the IP ranges used by Service ClusterIP.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ data:
leaderElection:
leaderElect: false
serviceCIDR: ""
podCIDRs:
- ""
gatewayIPPrecedence: "private"
endpointIPType: "ClusterIP"
kind: ConfigMap
Expand Down
7 changes: 7 additions & 0 deletions multicluster/build/yamls/antrea-multicluster-member.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ spec:
type: string
type: object
type: array
podCIDRs:
description: PodCIDRs is the Pod IP address CIDRs.
items:
type: string
type: array
serviceCIDR:
description: ServiceCIDR is the IP ranges used by Service ClusterIP.
type: string
Expand Down Expand Up @@ -946,6 +951,8 @@ data:
leaderElection:
leaderElect: false
serviceCIDR: ""
podCIDRs:
- ""
gatewayIPPrecedence: "private"
endpointIPType: "ClusterIP"
kind: ConfigMap
Expand Down
1 change: 1 addition & 0 deletions multicluster/cmd/multicluster-controller/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func runMember(o *Options) error {
mgr.GetScheme(),
env.GetPodNamespace(),
opts.ServiceCIDR,
opts.PodCIDRs,
commonAreaGetter)
if err = gwReconciler.SetupWithManager(mgr); err != nil {
return fmt.Errorf("error creating Gateway controller: %v", err)
Expand Down
12 changes: 12 additions & 0 deletions multicluster/cmd/multicluster-controller/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type Options struct {
options ctrl.Options
// The Service ClusterIP range used in the member cluster.
ServiceCIDR string
// PodCIDRs is the Pod IP address CIDRs of the member cluster.
PodCIDRs []string
// The precedence about which IP (private or public one) of Node is preferred to
// be used as tunnel endpoint. If not specified, private IP will be chosen.
GatewayIPPrecedence mcsv1alpha1.Precedence
Expand Down Expand Up @@ -64,7 +66,17 @@ func (o *Options) complete(args []string) error {
return fmt.Errorf("failed to parse serviceCIDR, invalid CIDR string %s", ctrlConfig.ServiceCIDR)
}
}
cidrs := []string{}
for _, cidr := range ctrlConfig.PodCIDRs {
if _, _, err := net.ParseCIDR(cidr); err != nil && cidr != "" {
return fmt.Errorf("failed to parse podCIDRs, invalid CIDR string %s", cidr)
}
if cidr != "" {
cidrs = append(cidrs, cidr)
}
}
o.ServiceCIDR = ctrlConfig.ServiceCIDR
o.PodCIDRs = cidrs
o.GatewayIPPrecedence = ctrlConfig.GatewayIPPrecedence
if ctrlConfig.EndpointIPType == "" {
o.EndpointIPType = "ClusterIP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ spec:
type: string
type: object
type: array
podCIDRs:
description: PodCIDRs is the Pod IP address CIDRs.
items:
type: string
type: array
serviceCIDR:
description: ServiceCIDR is the IP ranges used by Service ClusterIP.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ spec:
type: string
type: object
type: array
podCIDRs:
description: PodCIDRs is the Pod IP address CIDRs.
items:
type: string
type: array
serviceCIDR:
description: ServiceCIDR is the IP ranges used by Service ClusterIP.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ spec:
type: string
type: object
type: array
podCIDRs:
description: PodCIDRs is the Pod IP address CIDRs.
items:
type: string
type: array
serviceCIDR:
description: ServiceCIDR is the IP ranges used by Service ClusterIP.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ webhook:
leaderElection:
leaderElect: false
serviceCIDR: ""
podCIDRs:
- ""
gatewayIPPrecedence: "private"
endpointIPType: "ClusterIP"
5 changes: 5 additions & 0 deletions multicluster/controllers/multicluster/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type (
namespace string
localClusterID string
serviceCIDR string
podCIDRs []string
leaderNamespace string
}
)
Expand All @@ -55,12 +56,14 @@ func NewGatewayReconciler(
scheme *runtime.Scheme,
namespace string,
serviceCIDR string,
podCIDRs []string,
commonAreaGetter RemoteCommonAreaGetter) *GatewayReconciler {
reconciler := &GatewayReconciler{
Client: client,
Scheme: scheme,
namespace: namespace,
serviceCIDR: serviceCIDR,
podCIDRs: podCIDRs,
commonAreaGetter: commonAreaGetter,
}
return reconciler
Expand Down Expand Up @@ -144,6 +147,7 @@ func (r *GatewayReconciler) updateResourceExport(ctx context.Context, req ctrl.R
resExportSpec.ClusterInfo = &mcsv1alpha1.ClusterInfo{
ClusterID: r.localClusterID,
ServiceCIDR: r.serviceCIDR,
PodCIDRs: r.podCIDRs,
GatewayInfos: []mcsv1alpha1.GatewayInfo{*gwInfo},
}
if reflect.DeepEqual(existingResExport.Spec, resExportSpec) {
Expand Down Expand Up @@ -171,6 +175,7 @@ func (r *GatewayReconciler) createResourceExport(ctx context.Context, req ctrl.R
resExportSpec.ClusterInfo = &mcsv1alpha1.ClusterInfo{
ClusterID: r.localClusterID,
ServiceCIDR: r.serviceCIDR,
PodCIDRs: r.podCIDRs,
GatewayInfos: []mcsv1alpha1.GatewayInfo{
{
GatewayIP: gatewayIP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestGatewayReconciler(t *testing.T) {
mcReconciler := NewMemberClusterSetReconciler(fakeClient, scheme, "default")
mcReconciler.SetRemoteCommonArea(commonArea)
commonAreaGatter := mcReconciler
r := NewGatewayReconciler(fakeClient, scheme, "default", "10.96.0.0/12", commonAreaGatter)
r := NewGatewayReconciler(fakeClient, scheme, "default", "10.96.0.0/12", []string{"10.200.1.1/16"}, commonAreaGatter)
t.Run(tt.name, func(t *testing.T) {
req := ctrl.Request{NamespacedName: tt.namespacedName}
if _, err := r.Reconcile(ctx, req); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/agent/multicluster/mc_route_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,16 @@ func (c *MCRouteController) addMCFlowsForSingleCIImp(activeGW *mcv1alpha1.Gatewa

if installedCIImp != nil {
oldTunnelPeerIPToRemoteGW := getPeerGatewayIP(installedCIImp.Spec)
if oldTunnelPeerIPToRemoteGW.Equal(tunnelPeerIPToRemoteGW) && installedCIImp.Spec.ServiceCIDR == ciImport.Spec.ServiceCIDR {
if oldTunnelPeerIPToRemoteGW.Equal(tunnelPeerIPToRemoteGW) && installedCIImp.Spec.ServiceCIDR == ciImport.Spec.ServiceCIDR &&
sets.NewString(installedCIImp.Spec.PodCIDRs...).Equal(sets.NewString(ciImport.Spec.PodCIDRs...)) {
klog.V(2).InfoS("No difference between new and installed ClusterInfoImports, skip updating", "clusterinfoimport", ciImport.Name)
return nil
}
}

klog.InfoS("Adding/updating remote Gateway Node flows for Multi-cluster", "gateway", klog.KObj(activeGW),
"node", c.nodeConfig.Name, "peer", tunnelPeerIPToRemoteGW)
allCIDRs := []string{ciImport.Spec.ServiceCIDR}
allCIDRs := append([]string{ciImport.Spec.ServiceCIDR}, ciImport.Spec.PodCIDRs...)
peerConfigs, err := generatePeerConfigs(allCIDRs, tunnelPeerIPToRemoteGW)
if err != nil {
klog.ErrorS(err, "Parse error for serviceCIDR from remote cluster", "clusterinfoimport", ciImport.Name, "gateway", activeGW.Name)
Expand Down

0 comments on commit 552e8c8

Please sign in to comment.