Skip to content

Commit

Permalink
Add a new config Precedence
Browse files Browse the repository at this point in the history
Add a new config Precedence to allow user to configure
which Node IP should be used as tunnel endpoint IP.

Signed-off-by: Lan Luo <luola@vmware.com>
  • Loading branch information
luolanzone committed Apr 7, 2022
1 parent 67749de commit 5dd5619
Show file tree
Hide file tree
Showing 15 changed files with 335 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ import (
config "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
)

// Precedence defines the precedence of Node IP type.
type Precedence string

const (
PrecedencePrivate = "private"
PrecedencePublic = "public"
)

//+kubebuilder:object:root=true

// MultiClusterConfig is the Schema for the multiclusterconfigs API
Expand All @@ -30,6 +38,9 @@ type MultiClusterConfig struct {
config.ControllerManagerConfigurationSpec `json:",inline"`
// ServiceCIDR allows user to set the Cluster IP range of the cluster manually.
ServiceCIDR string `json:"serviceCIDR,omitempty"`
// The precedence about which IP (private or public one) of Node is preferred to
// be used as tunnel endpoint. If it's empty, private IP will be chose.
Precedence Precedence `json:"precedence,omitempty"`
}

func init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type ResourceExportSpec struct {
// If exported resource is AntreaClusterNetworkPolicy.
ClusterNetworkPolicy *v1alpha1.ClusterNetworkPolicySpec `json:"clusternetworkpolicy,omitempty"`
// If exported resource Kind is unknown.
Raw RawResourceExport `json:"raw,omitempty"`
Raw *RawResourceExport `json:"raw,omitempty"`
}

type ResourceExportConditionType string
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions multicluster/build/yamls/antrea-multicluster-member.yml
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,14 @@ rules:
verbs:
- get
- update
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
Expand Down Expand Up @@ -1027,6 +1035,72 @@ rules:
- get
- patch
- update
- apiGroups:
- multicluster.crd.antrea.io
resources:
- resourceimports/finalizers
verbs:
- update
- apiGroups:
- multicluster.crd.antrea.io
resources:
- resourceimports/status
verbs:
- get
- patch
- update
- apiGroups:
- multicluster.crd.antrea.io
resources:
- tunnelendpointimports
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- multicluster.crd.antrea.io
resources:
- tunnelendpointimports/finalizers
verbs:
- update
- apiGroups:
- multicluster.crd.antrea.io
resources:
- tunnelendpointimports/status
verbs:
- get
- patch
- update
- apiGroups:
- multicluster.crd.antrea.io
resources:
- tunnelendpoints
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- multicluster.crd.antrea.io
resources:
- tunnelendpoints/finalizers
verbs:
- update
- apiGroups:
- multicluster.crd.antrea.io
resources:
- tunnelendpoints/status
verbs:
- get
- patch
- update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down
3 changes: 2 additions & 1 deletion multicluster/cmd/multicluster-controller/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func runMember(o *Options) error {
mgr.GetScheme(),
env.GetPodNamespace(),
&clusterSetReconciler.RemoteCommonAreaManager,
opts.ServiceCIDR)
opts.ServiceCIDR,
opts.Precedence)
if err = gwNodeReconciler.SetupWithManager(mgr); err != nil {
return fmt.Errorf("error creating Gateway Node controller: %v", err)
}
Expand Down
4 changes: 4 additions & 0 deletions multicluster/cmd/multicluster-controller/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type Options struct {
options ctrl.Options
// The Service ClusterIP range used in the member cluster.
ServiceCIDR string
// The precedence about which IP (private or public one) of Node is preferred to
// be used as tunnel endpoint. If it's empty, private IP will be chose.
Precedence mcsv1alpha1.Precedence
}

func newOptions() *Options {
Expand All @@ -54,6 +57,7 @@ func (o *Options) complete(args []string) error {
}
o.options = options
o.ServiceCIDR = ctrlConfig.ServiceCIDR
o.Precedence = ctrlConfig.Precedence
klog.InfoS("Using config from file", "config", o.options)
} else {
klog.InfoS("Using default config", "config", o.options)
Expand Down
74 changes: 74 additions & 0 deletions multicluster/config/overlays/member/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ metadata:
creationTimestamp: null
name: controller-role
rules:
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
Expand Down Expand Up @@ -180,3 +188,69 @@ rules:
- get
- patch
- update
- apiGroups:
- multicluster.crd.antrea.io
resources:
- resourceimports/finalizers
verbs:
- update
- apiGroups:
- multicluster.crd.antrea.io
resources:
- resourceimports/status
verbs:
- get
- patch
- update
- apiGroups:
- multicluster.crd.antrea.io
resources:
- tunnelendpointimports
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- multicluster.crd.antrea.io
resources:
- tunnelendpointimports/finalizers
verbs:
- update
- apiGroups:
- multicluster.crd.antrea.io
resources:
- tunnelendpointimports/status
verbs:
- get
- patch
- update
- apiGroups:
- multicluster.crd.antrea.io
resources:
- tunnelendpoints
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- multicluster.crd.antrea.io
resources:
- tunnelendpoints/finalizers
verbs:
- update
- apiGroups:
- multicluster.crd.antrea.io
resources:
- tunnelendpoints/status
verbs:
- get
- patch
- update
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ func (r *remoteCommonAreaManager) setElectedLeader(cluster RemoteCommonArea) {
}
r.electedLeaderCluster = cluster
if cluster != nil {
cluster.StartWatching()
if err := cluster.StartWatching(); err != nil {
klog.ErrorS(err, "Failed to start watching events")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func NewRemoteCommonArea(clusterID common.ClusterID, clusterSetID common.Cluster
if e != nil {
return nil, e
}

remote := &remoteCommonArea{
Client: remoteClient,
ClusterManager: mgr,
Expand Down Expand Up @@ -410,6 +409,17 @@ func (r *remoteCommonArea) StopWatching() {
}
r.managerStopFunc()
r.managerStopFunc = nil

// Reset ClusterManager so this common area can be started again when it's reconnected.
mgr, err := ctrl.NewManager(r.config, ctrl.Options{
Scheme: r.scheme,
MetricsBindAddress: "0",
Namespace: r.Namespace,
})
if err != nil {
klog.ErrorS(err, "Error to reset manager for RemoteCommonArea", "Cluster", r.ClusterID)
}
r.ClusterManager = mgr
}

func (r *remoteCommonArea) GetStatus() []multiclusterv1alpha1.ClusterCondition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ func (r *ResourceImportReconciler) handleResImpUpdateForService(ctx context.Cont
klog.ErrorS(err, "Failed to update imported Service", "service", svcName.String())
return ctrl.Result{}, err
}
r.installedResImports.Update(*resImp)
}

if !apiequality.Semantic.DeepEqual(svcImp.Spec, svcImpObj.Spec) {
Expand All @@ -229,8 +228,8 @@ func (r *ResourceImportReconciler) handleResImpUpdateForService(ctx context.Cont
klog.ErrorS(err, "Failed to update ServiceImport", "serviceimport", svcImpName.String())
return ctrl.Result{}, err
}
r.installedResImports.Update(*resImp)
}
r.installedResImports.Update(*resImp)
return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -332,8 +331,8 @@ func (r *ResourceImportReconciler) handleResImpUpdateForEndpoints(ctx context.Co
klog.ErrorS(err, "Failed to update MCS Endpoints", "endpoints", epNamespaced.String())
return ctrl.Result{}, err
}
r.installedResImports.Update(*resImp)
}
r.installedResImports.Update(*resImp)
return ctrl.Result{}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (r *ResourceImportReconciler) handleResImpForTunnelEndpoint(ctx context.Con
if reflect.DeepEqual(teImport.Spec, teSpec) {
klog.InfoS("No change on TunnelEndpointImport spec, skip reconciling", "tunnelendpointimport", teImportNamespaced.String(),
"resourceimport", req.NamespacedName.String())
r.installedResImports.Update(*resImp)
return ctrl.Result{}, nil
}
teImport.Spec = teSpec
Expand Down
Loading

0 comments on commit 5dd5619

Please sign in to comment.