-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Gateway, ClusterInfo exchange controllers
* Add a Node controller to watch Node changes in member cluster. It will do following things: * When the Node is annotated with `multicluster.antrea.io/gateway=true`, it will create a new Gateway CR like below: ```yaml apiVersion: multicluster.crd.antrea.io/v1alpha1 kind: Gateway metadata: name: k8s-node-1 namespace: kube-system gatewayIP: 172.16.27.224 internalIP: 172.16.27.224 ``` * When the Node is annotated with both `multicluster.antrea.io/gateway=true` and `multicluster.antrea.io/gateway-ip="10.10.10.10"` ('10.10.10.10' is an IP example), the existing Gateway CR's gatewayIP will be updated like below: ```yaml apiVersion: multicluster.crd.antrea.io/v1alpha1 kind: Gateway metadata: name: k8s-node-1 namespace: kube-system gatewayIP: 10.10.10.10 internalIP: 172.16.27.224 ``` * When the Node's annotation `multicluster.antrea.io/gateway=true` is removed, the corresponding Gateway will be deleted. * Add a Gateway controller to watch Gateway events in member cluster. It will do following things: * When a Gateway is created, a new ClusterInfo type of ResourceExport will be created in leader cluster, a sample yaml is like below: ```yaml apiVersion: multicluster.crd.antrea.io/v1alpha1 kind: ResourceExport metadata: name: test-cluster-west-kube-system-clusterinfo namespace: antrea-mcs-ns spec: clusterID: test-cluster-west clusterinfo: clusterID: test-cluster-west gatewayInfos: - gatewayIP: 10.10.10.10 serviceCIDR: 10.19.0.0/18 kind: ClusterInfo name: test-cluster-west namespace: kube-system ``` * When a Gateway is updated or one of many Gateways are deleted, the corresponding ResourceExport will be updated in leader cluster. Please note, we support one Gateway only for now, so the last created Gateway will be wrapped into ResourceExport if there are multiple Gateways. * When the last Gateway is deleted, the corresponding ResourceExport will be deleted in leader cluster. * There are two new fields `serviceCIDR` and `gatewayIPPrecedence` are added in `MultiClusterConfig`. - By default, MC controller will detect ClusterIP range automatically. If admin sets the `serviceCIDR` config manually, it will use the value of `serviceCIDR` in the config. - By default, MC controller will choose InternalIP of a Node as the GatewayIP, if admin sets `gatewayIPPrecedence` config as `public`, it will use ExternalIP as GatewayIP. * Add a new ClusterInfo kind handler to convert any new or updated ClusterInfo kind of ResourceExports into ResourceImports. * Add a new ClusterInfo importer to watch any new or updated ClusterInfo kind of ResourceImport events. It will create or update a ClusterInfoImport locally. A sample ClusterInfoImport is like below: ```yaml apiVersion: multicluster.crd.antrea.io/v1alpha1 kind: ClusterInfoImport metadata: name: test-cluster-west-kube-system-clusterinfo namespace: kube-system spec: clusterID: test-cluster-west gatewayInfos: - gatewayIP: 10.10.10.10 serviceCIDR: 10.19.0.0/18 ``` Signed-off-by: Lan Luo <luola@vmware.com>
- Loading branch information
1 parent
65134a6
commit bb915c5
Showing
36 changed files
with
2,037 additions
and
436 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
multicluster/config/crd/bases/multicluster.crd.antrea.io_gateway.yaml
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
multicluster/config/crd/patches/webhook_in_gatewaynodes.yaml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
multicluster/controllers/multicluster/clusterinfoexport_handler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
Copyright 2022 Antrea Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package multicluster | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
|
||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/klog/v2" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
mcsv1alpha1 "antrea.io/antrea/multicluster/apis/multicluster/v1alpha1" | ||
"antrea.io/antrea/multicluster/controllers/multicluster/common" | ||
) | ||
|
||
func (r *ResourceExportReconciler) handleClusterInfo(ctx context.Context, req ctrl.Request, resExport mcsv1alpha1.ResourceExport) (ctrl.Result, error) { | ||
resImport := &mcsv1alpha1.ResourceImport{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: req.Name, | ||
Namespace: req.Namespace, | ||
}, | ||
} | ||
|
||
if !resExport.DeletionTimestamp.IsZero() { | ||
if common.StringExistsInSlice(resExport.Finalizers, common.ResourceExportFinalizer) { | ||
err := r.Client.Delete(ctx, resImport, &client.DeleteOptions{}) | ||
if err == nil || apierrors.IsNotFound(err) { | ||
return r.deleteResourceExport(&resExport) | ||
} | ||
return ctrl.Result{}, err | ||
} | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
resImport.Spec = mcsv1alpha1.ResourceImportSpec{ | ||
Kind: common.ClusterInfoKind, | ||
Name: resExport.Name, | ||
Namespace: resExport.Namespace, | ||
} | ||
resImportName := types.NamespacedName{ | ||
Name: req.Name, | ||
Namespace: req.Namespace, | ||
} | ||
|
||
var err error | ||
if err = r.Client.Get(ctx, resImportName, resImport); err != nil { | ||
if !apierrors.IsNotFound(err) { | ||
return ctrl.Result{}, err | ||
} | ||
// Create a new ClusterInfo of ResourceImport | ||
resImport.Spec.ClusterInfo = resExport.Spec.ClusterInfo | ||
if err = r.Client.Create(ctx, resImport, &client.CreateOptions{}); err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
return ctrl.Result{}, nil | ||
} | ||
if reflect.DeepEqual(resImport.Spec.ClusterInfo, resExport.Spec.ClusterInfo) { | ||
klog.V(2).InfoS("No data change from ResourceExport, skip reconciling", "resourceexport", klog.KObj(&resExport)) | ||
return ctrl.Result{}, nil | ||
} | ||
// Update an existing ClusterInfo of ResourceImport | ||
resImport.Spec.ClusterInfo = resExport.Spec.ClusterInfo | ||
klog.InfoS("Updating ResourceImport", "resourceimport", klog.KObj(&resExport)) | ||
if err = r.Client.Update(ctx, resImport, &client.UpdateOptions{}); err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
return ctrl.Result{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.