Skip to content

Commit

Permalink
Add Gateway and ClusterInfoImport CRDs (#3689)
Browse files Browse the repository at this point in the history
* Add Gateway and ClusterInfoImport CRDs and update corresponding manifests
    - A sample of Gateway is 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
    ```
    - A sample of 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
      gatewayNodeInfos:
      - gatewayIP: 10.10.10.10
        name: k8s-node-1
      serviceCIDR: 10.19.0.0/18
    ```
* Two new fields 'ServiceCIDR' and 'GatewayIPPrecedence' are added in MultiClusterConfig.
    - By default, MC controller will detect ClusterIP range automatically. If admin set the
    ServiceCIDR config manually, MC controller will use the value in the config.
    - By default, MC controller will chose InternalIP of a Node as the GatewayIP, if admin set
    GatewayIPPrecedence config as 'public', it will use ExternalIP as the GatewayIP.

Signed-off-by: Lan Luo <luola@vmware.com>
  • Loading branch information
luolanzone authored Apr 27, 2022
1 parent 00f9d98 commit 2023829
Show file tree
Hide file tree
Showing 44 changed files with 3,834 additions and 59 deletions.
18 changes: 18 additions & 0 deletions multicluster/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,22 @@ resources:
kind: MultiClusterConfig
path: antrea.io/antrea/multicluster/apis/multicluster/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: crd.antrea.io
group: multicluster
kind: ClusterInfoImport
path: antrea.io/antrea/multicluster/apis/multicluster/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: crd.antrea.io
group: multicluster
kind: Gateway
path: antrea.io/antrea/multicluster/apis/multicluster/v1alpha1
version: v1alpha1
version: "3"
50 changes: 50 additions & 0 deletions multicluster/apis/multicluster/v1alpha1/clusterinfoimport_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
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 v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ClusterInfoImportStatus defines the observed state of ClusterInfoImport.
type ClusterInfoImportStatus struct {
Conditions []ResourceCondition `json:"conditions,omitempty"`
}

// +genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

type ClusterInfoImport struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ClusterInfo `json:"spec,omitempty"`
Status ClusterInfoImportStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

type ClusterInfoImportList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ClusterInfoImport `json:"items"`
}

func init() {
SchemeBuilder.Register(&ClusterInfoImport{}, &ClusterInfoImportList{})
}
63 changes: 63 additions & 0 deletions multicluster/apis/multicluster/v1alpha1/gateway_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
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 v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// GatewayInfo includes information of a Gateway.
type GatewayInfo struct {
GatewayIP string `json:"gatewayIP,omitempty"`
}

// +genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Gateway includes information of a Multi-cluster Gateway.
type Gateway struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// Tunnel IP of the Gateway. It might be assigned by user manually
// through a Node annotation.
GatewayIP string `json:"gatewayIP,omitempty"`
// Internal tunnel IP of the Gateway.
InternalIP string `json:"internalIP,omitempty"`
}

type ClusterInfo struct {
// ClusterID of the member cluster.
ClusterID string `json:"clusterID,omitempty"`
// ServiceCIDR is the IP ranges used by Service ClusterIP.
ServiceCIDR string `json:"serviceCIDR,omitempty"`
// GatewayInfos has information of Gateways
GatewayInfos []GatewayInfo `json:"gatewayInfos,omitempty"`
}

//+kubebuilder:object:root=true

type GatewayList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Gateway `json:"items"`
}

func init() {
SchemeBuilder.Register(&Gateway{}, &GatewayList{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,25 @@ 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
type MultiClusterConfig struct {
metav1.TypeMeta `json:",inline"`
// ControllerManagerConfigurationSpec returns the contfigurations for controllers
// ControllerManagerConfigurationSpec returns the contfigurations for controllers.
config.ControllerManagerConfigurationSpec `json:",inline"`
// ServiceCIDR allows user to set the ClusterIP 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 not specified, private IP will be chosen.
GatewayIPPrecedence Precedence `json:"gatewayIPPrecedence,omitempty"`
}

func init() {
Expand Down
11 changes: 5 additions & 6 deletions multicluster/apis/multicluster/v1alpha1/resourceexport_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ type RawResourceExport struct {

// ResourceExportSpec defines the desired state of ResourceExport.
type ResourceExportSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// ClusterID specifies the member cluster this resource exported from.
ClusterID string `json:"clusterID,omitempty"`
// Name of exported resource.
Expand All @@ -60,14 +57,16 @@ type ResourceExportSpec struct {

// If exported resource is Service.
Service *ServiceExport `json:"service,omitempty"`
// If exported resource is EndPoints.
// If exported resource is Endpoints.
Endpoints *EndpointsExport `json:"endpoints,omitempty"`
// If exported resource is ClusterInfo.
ClusterInfo *ClusterInfo `json:"clusterinfo,omitempty"`
// If exported resource is ExternalEntity.
ExternalEntity *ExternalEntityExport `json:"externalentity,omitempty"`
// If exported resource is AntreaClusterNetworkPolicy.
ClusterNetworkPolicy *v1alpha1.ClusterNetworkPolicySpec `json:"clusternetworkpolicy,omitempty"`
// If exported resource Kind is unknown.
Raw RawResourceExport `json:"raw,omitempty"`
// If exported resource kind is unknown.
Raw *RawResourceExport `json:"raw,omitempty"`
}

type ResourceExportConditionType string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type ResourceImportSpec struct {
ServiceImport *mcs.ServiceImport `json:"serviceImport,omitempty"`
// If imported resource is EndPoints.
Endpoints *EndpointsImport `json:"endpoints,omitempty"`
// If imported resource is ClusterInfo.
ClusterInfo *ClusterInfo `json:"clusterinfo,omitempty"`
// If imported resource is ExternalEntity.
ExternalEntity *ExternalEntityImport `json:"externalentity,omitempty"`
// If imported resource is AntreaClusterNetworkPolicy.
Expand All @@ -64,7 +66,7 @@ type ResourceImportSpec struct {
// TODO:
// ANP uses float64 as priority. Type float64 is discouraged by k8s, and is not supported by controller-gen tools.
// NetworkPolicy *v1alpha1.NetworkPolicySpec `json:"networkpolicy,omitempty"`
// If imported resource Kind is unknown.
// If imported resource kind is unknown.
Raw *RawResourceImport `json:"raw,omitempty"`
}

Expand Down
46 changes: 46 additions & 0 deletions multicluster/apis/multicluster/v1alpha1/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
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 v1alpha1

import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type ResourceConditionType string

const (
ResourceReady ResourceConditionType = "Ready"
)

// ResourceCondition indicates the readiness condition of a Resource.
type ResourceCondition struct {
// Type is the type of the condition.
Type ResourceConditionType `json:"type,omitempty"`
// Status of the condition, one of True, False, Unknown.
Status v1.ConditionStatus `json:"status,omitempty"`

// +optional
// Last time the condition transited from one status to another.
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// +optional
// A human readable message indicating details about the transition.
Message string `json:"message,omitempty"`
// +optional
// Unique, one-word, CamelCase reason for the condition's last transition.
Reason string `json:"reason,omitempty"`
}
Loading

0 comments on commit 2023829

Please sign in to comment.