From 1443224bbcd7ac0424a0f8d3e61b462e5c6dbee9 Mon Sep 17 00:00:00 2001 From: ONE7live Date: Wed, 1 Nov 2023 10:08:36 +0800 Subject: [PATCH] fix: crd reference issues Signed-off-by: wangyizhi1 --- deploy/crds/kosmos.io_clusters.yaml | 151 +++++----- deploy/crds/kosmos.io_knodes.yaml | 3 + pkg/apis/kosmos/v1alpha1/cluster_types.go | 31 +- pkg/apis/kosmos/v1alpha1/knode_types.go | 4 - .../kosmos/v1alpha1/zz_generated.deepcopy.go | 103 +++++-- .../calicoippool/calicoippool_controller.go | 10 +- .../controllers/cluster/cluster_controller.go | 10 +- .../controllers/node/node_controller.go | 2 +- .../nodecidr/nodecidr_controller.go | 2 +- .../network-manager/handlers/globalmap.go | 4 +- .../network-manager/handlers/host_network.go | 8 +- .../network-manager/handlers/pod_routes.go | 6 +- .../network-manager/handlers/svc_routes.go | 4 +- .../handlers/vxbridge_network.go | 8 +- .../handlers/vxlocal_network.go | 8 +- .../network-manager/helpers/filter.go | 4 +- pkg/clusterlink/network/adapter.go | 2 +- .../operator/addons/option/option.go | 2 +- pkg/generated/openapi/zz_generated.openapi.go | 265 +++++++++++------- 19 files changed, 391 insertions(+), 236 deletions(-) diff --git a/deploy/crds/kosmos.io_clusters.yaml b/deploy/crds/kosmos.io_clusters.yaml index 2666514ba..eed6b21ce 100644 --- a/deploy/crds/kosmos.io_clusters.yaml +++ b/deploy/crds/kosmos.io_clusters.yaml @@ -16,10 +16,10 @@ spec: scope: Cluster versions: - additionalPrinterColumns: - - jsonPath: .spec.networkType + - jsonPath: .spec.clusterLinkOptions.networkType name: NETWORK_TYPE type: string - - jsonPath: .spec.ipFamily + - jsonPath: .spec.clusterLinkOptions.ipFamily name: IP_FAMILY type: string name: v1alpha1 @@ -41,88 +41,103 @@ spec: spec: description: Spec is the specification for the behaviour of the cluster. properties: - bridgeCIDRs: - default: - ip: 220.0.0.0/8 - ip6: 9470::/16 + clusterLinkOptions: properties: - ip: + bridgeCIDRs: + default: + ip: 220.0.0.0/8 + ip6: 9470::/16 + properties: + ip: + type: string + ip6: + type: string + required: + - ip + - ip6 + type: object + cni: + default: calico + type: string + defaultNICName: + default: '*' type: string - ip6: + enable: + default: true + type: boolean + globalCIDRsMap: + additionalProperties: + type: string + type: object + ipFamily: + default: all type: string - required: - - ip - - ip6 + localCIDRs: + default: + ip: 210.0.0.0/8 + ip6: 9480::/16 + properties: + ip: + type: string + ip6: + type: string + required: + - ip + - ip6 + type: object + networkType: + default: p2p + enum: + - p2p + - gateway + type: string + nicNodeNames: + items: + properties: + interfaceName: + type: string + nodeName: + items: + type: string + type: array + required: + - interfaceName + - nodeName + type: object + type: array + useIPPool: + default: false + type: boolean type: object - cni: - default: calico - type: string - defaultNICName: - default: '*' - type: string - globalCIDRsMap: - additionalProperties: - type: string + clusterTreeOptions: + properties: + enable: + default: true + type: boolean type: object imageRepository: type: string - ipFamily: - default: all - type: string kubeconfig: format: byte type: string - localCIDRs: - default: - ip: 210.0.0.0/8 - ip6: 9480::/16 - properties: - ip: - type: string - ip6: - type: string - required: - - ip - - ip6 - type: object namespace: - default: clusterlink-system - type: string - networkType: - default: p2p - enum: - - p2p - - gateway + default: kosmos-system type: string - nicNodeNames: - items: - properties: - interfaceName: - type: string - nodeName: - items: - type: string - type: array - required: - - interfaceName - - nodeName - type: object - type: array - useIPPool: - default: false - type: boolean type: object status: description: Status describes the current status of a cluster. properties: - podCIDRs: - items: - type: string - type: array - serviceCIDRs: - items: - type: string - type: array + clusterLinkStatus: + properties: + podCIDRs: + items: + type: string + type: array + serviceCIDRs: + items: + type: string + type: array + type: object type: object required: - spec diff --git a/deploy/crds/kosmos.io_knodes.yaml b/deploy/crds/kosmos.io_knodes.yaml index 193826fd1..647c18313 100644 --- a/deploy/crds/kosmos.io_knodes.yaml +++ b/deploy/crds/kosmos.io_knodes.yaml @@ -35,6 +35,9 @@ spec: properties: disableTaint: type: boolean + kubeAPIBurst: + default: 100 + type: integer kubeconfig: format: byte type: string diff --git a/pkg/apis/kosmos/v1alpha1/cluster_types.go b/pkg/apis/kosmos/v1alpha1/cluster_types.go index a6b59c83b..24506835b 100644 --- a/pkg/apis/kosmos/v1alpha1/cluster_types.go +++ b/pkg/apis/kosmos/v1alpha1/cluster_types.go @@ -8,8 +8,8 @@ import ( // +genclient:nonNamespaced // +kubebuilder:resource:scope="Cluster" // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +kubebuilder:printcolumn:name="NETWORK_TYPE",type=string,JSONPath=`.spec.networkType` -// +kubebuilder:printcolumn:name="IP_FAMILY",type=string,JSONPath=`.spec.ipFamily` +// +kubebuilder:printcolumn:name="NETWORK_TYPE",type=string,JSONPath=`.spec.clusterLinkOptions.networkType` +// +kubebuilder:printcolumn:name="IP_FAMILY",type=string,JSONPath=`.spec.clusterLinkOptions.ipFamily` type Cluster struct { metav1.TypeMeta `json:",inline"` @@ -27,6 +27,13 @@ type ClusterSpec struct { // +optional Kubeconfig []byte `json:"kubeconfig,omitempty"` + // +kubebuilder:default=kosmos-system + // +optional + Namespace string `json:"namespace"` + + // +optional + ImageRepository string `json:"imageRepository,omitempty"` + // +optional ClusterLinkOptions ClusterLinkOptions `json:"clusterLinkOptions,omitempty"` @@ -35,40 +42,54 @@ type ClusterSpec struct { } type ClusterStatus struct { - ClusterLinkStatus ClusterLinkStatus + ClusterLinkStatus ClusterLinkStatus `json:"clusterLinkStatus,omitempty"` } type ClusterLinkOptions struct { + // +kubebuilder:default=true + // +optional + Enable bool `json:"enable"` + // +kubebuilder:default=calico // +optional CNI string `json:"cni"` + // +kubebuilder:validation:Enum=p2p;gateway // +kubebuilder:default=p2p // +optional NetworkType NetworkType `json:"networkType"` + // +kubebuilder:default=all // +optional - IPFamily IPFamilyType `json:"ipFamily"` - ImageRepository string `json:"imageRepository,omitempty"` + IPFamily IPFamilyType `json:"ipFamily"` + // +kubebuilder:default=false // +optional UseIPPool bool `json:"useIPPool,omitempty"` + // +kubebuilder:default={ip:"210.0.0.0/8",ip6:"9480::/16"} // +optional LocalCIDRs VxlanCIDRs `json:"localCIDRs,omitempty"` + // +kubebuilder:default={ip:"220.0.0.0/8",ip6:"9470::/16"} // +optional BridgeCIDRs VxlanCIDRs `json:"bridgeCIDRs,omitempty"` + // +optional NICNodeNames []NICNodeNames `json:"nicNodeNames,omitempty"` + // +kubebuilder:default=* // +optional DefaultNICName string `json:"defaultNICName,omitempty"` + // +optional GlobalCIDRsMap map[string]string `json:"globalCIDRsMap,omitempty"` } type ClusterTreeOptions struct { + // +kubebuilder:default=true + // +optional + Enable bool `json:"enable"` } type ClusterLinkStatus struct { diff --git a/pkg/apis/kosmos/v1alpha1/knode_types.go b/pkg/apis/kosmos/v1alpha1/knode_types.go index 427bf95d2..7fb63db77 100644 --- a/pkg/apis/kosmos/v1alpha1/knode_types.go +++ b/pkg/apis/kosmos/v1alpha1/knode_types.go @@ -28,10 +28,6 @@ type KnodeSpec struct { // +optional Kubeconfig []byte `json:"kubeconfig,omitempty"` - // +kubebuilder:default=50 - // +optional - KubeAPIQPS float32 `json:"kubeAPIQPS,omitempty"` - // +kubebuilder:default=100 // +optional KubeAPIBurst int `json:"kubeAPIBurst,omitempty"` diff --git a/pkg/apis/kosmos/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/kosmos/v1alpha1/zz_generated.deepcopy.go index 50d4223b8..1e2a1486c 100644 --- a/pkg/apis/kosmos/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/kosmos/v1alpha1/zz_generated.deepcopy.go @@ -55,6 +55,64 @@ func (in *Cluster) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterLinkOptions) DeepCopyInto(out *ClusterLinkOptions) { + *out = *in + out.LocalCIDRs = in.LocalCIDRs + out.BridgeCIDRs = in.BridgeCIDRs + if in.NICNodeNames != nil { + in, out := &in.NICNodeNames, &out.NICNodeNames + *out = make([]NICNodeNames, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.GlobalCIDRsMap != nil { + in, out := &in.GlobalCIDRsMap, &out.GlobalCIDRsMap + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterLinkOptions. +func (in *ClusterLinkOptions) DeepCopy() *ClusterLinkOptions { + if in == nil { + return nil + } + out := new(ClusterLinkOptions) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterLinkStatus) DeepCopyInto(out *ClusterLinkStatus) { + *out = *in + if in.PodCIDRs != nil { + in, out := &in.PodCIDRs, &out.PodCIDRs + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.ServiceCIDRs != nil { + in, out := &in.ServiceCIDRs, &out.ServiceCIDRs + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterLinkStatus. +func (in *ClusterLinkStatus) DeepCopy() *ClusterLinkStatus { + if in == nil { + return nil + } + out := new(ClusterLinkStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterList) DeepCopyInto(out *ClusterList) { *out = *in @@ -194,27 +252,13 @@ func (in *ClusterNodeStatus) DeepCopy() *ClusterNodeStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) { *out = *in - out.LocalCIDRs = in.LocalCIDRs - out.BridgeCIDRs = in.BridgeCIDRs - if in.NICNodeNames != nil { - in, out := &in.NICNodeNames, &out.NICNodeNames - *out = make([]NICNodeNames, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.GlobalCIDRsMap != nil { - in, out := &in.GlobalCIDRsMap, &out.GlobalCIDRsMap - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } if in.Kubeconfig != nil { in, out := &in.Kubeconfig, &out.Kubeconfig *out = make([]byte, len(*in)) copy(*out, *in) } + in.ClusterLinkOptions.DeepCopyInto(&out.ClusterLinkOptions) + out.ClusterTreeOptions = in.ClusterTreeOptions return } @@ -231,16 +275,7 @@ func (in *ClusterSpec) DeepCopy() *ClusterSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterStatus) DeepCopyInto(out *ClusterStatus) { *out = *in - if in.PodCIDRs != nil { - in, out := &in.PodCIDRs, &out.PodCIDRs - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.ServiceCIDRs != nil { - in, out := &in.ServiceCIDRs, &out.ServiceCIDRs - *out = make([]string, len(*in)) - copy(*out, *in) - } + in.ClusterLinkStatus.DeepCopyInto(&out.ClusterLinkStatus) return } @@ -254,6 +289,22 @@ func (in *ClusterStatus) DeepCopy() *ClusterStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterTreeOptions) DeepCopyInto(out *ClusterTreeOptions) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTreeOptions. +func (in *ClusterTreeOptions) DeepCopy() *ClusterTreeOptions { + if in == nil { + return nil + } + out := new(ClusterTreeOptions) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DaemonSet) DeepCopyInto(out *DaemonSet) { *out = *in diff --git a/pkg/clusterlink/controllers/calicoippool/calicoippool_controller.go b/pkg/clusterlink/controllers/calicoippool/calicoippool_controller.go index 32303a34a..ba409c794 100644 --- a/pkg/clusterlink/controllers/calicoippool/calicoippool_controller.go +++ b/pkg/clusterlink/controllers/calicoippool/calicoippool_controller.go @@ -339,8 +339,8 @@ func (c *Controller) Reconcile(key utils.QueueKey) error { } klog.Infof("start reconcile cluster %s", cluster.Name) - if cluster.Spec.CNI != utils.CNITypeCalico { - klog.Infof("cluster %s cni type is %s skip reconcile", cluster.Name, cluster.Spec.CNI) + if cluster.Spec.ClusterLinkOptions.CNI != utils.CNITypeCalico { + klog.Infof("cluster %s cni type is %s skip reconcile", cluster.Name, cluster.Spec.ClusterLinkOptions.CNI) return nil } for ipPool := range c.globalExtIPPoolSet { @@ -355,9 +355,9 @@ func (c *Controller) Reconcile(key utils.QueueKey) error { return cidr } } - cidrMap := cluster.Spec.GlobalCIDRsMap - podCIDRS := cluster.Status.PodCIDRs - serviceCIDR := cluster.Status.ServiceCIDRs + cidrMap := cluster.Spec.ClusterLinkOptions.GlobalCIDRsMap + podCIDRS := cluster.Status.ClusterLinkStatus.PodCIDRs + serviceCIDR := cluster.Status.ClusterLinkStatus.ServiceCIDRs for _, cidr := range podCIDRS { extIPPool := ExternalClusterIPPool{ cluster: cluster.Name, diff --git a/pkg/clusterlink/controllers/cluster/cluster_controller.go b/pkg/clusterlink/controllers/cluster/cluster_controller.go index 306de3c64..89eed5c1e 100644 --- a/pkg/clusterlink/controllers/cluster/cluster_controller.go +++ b/pkg/clusterlink/controllers/cluster/cluster_controller.go @@ -124,7 +124,7 @@ func (c *Controller) Start(ctx context.Context) error { return err } - if cluster.Spec.CNI == FlannelCNI { + if cluster.Spec.ClusterLinkOptions.CNI == FlannelCNI { c.setClusterPodCIDRFun, err = c.initFlannelInformer(ctx, cluster, c.kubeClient) if err != nil { klog.Errorf("cluster %s initCalicoInformer err: %v", err) @@ -202,7 +202,7 @@ func (c *Controller) Reconcile(key utils.QueueKey) error { return err } - reconcileCluster.Status.ServiceCIDRs = serviceCIDRS + reconcileCluster.Status.ClusterLinkStatus.ServiceCIDRs = serviceCIDRS //TODO use sub resource _, err = c.clusterLinkClient.KosmosV1alpha1().Clusters().Update(context.TODO(), reconcileCluster, metav1.UpdateOptions{}) if err != nil { @@ -289,7 +289,7 @@ func (c *Controller) initCalicoInformer(context context.Context, cluster *cluste } } } - cluster.Status.PodCIDRs = podCIDRS + cluster.Status.ClusterLinkStatus.PodCIDRs = podCIDRS return nil }, nil } @@ -364,7 +364,7 @@ func (c *Controller) initCalicoWatcherWithEtcdBackend(ctx context.Context, clust podCIDRs = append(podCIDRs, ippool.Spec.CIDR) } } - cluster.Status.PodCIDRs = podCIDRs + cluster.Status.ClusterLinkStatus.PodCIDRs = podCIDRs return nil }, nil } @@ -434,7 +434,7 @@ func (c *Controller) initFlannelInformer(context context.Context, cluster *clust break } } - cluster.Status.PodCIDRs = podCIDRS + cluster.Status.ClusterLinkStatus.PodCIDRs = podCIDRS return nil }, nil } diff --git a/pkg/clusterlink/controllers/node/node_controller.go b/pkg/clusterlink/controllers/node/node_controller.go index 02ddd3949..2f0e33bf9 100644 --- a/pkg/clusterlink/controllers/node/node_controller.go +++ b/pkg/clusterlink/controllers/node/node_controller.go @@ -115,7 +115,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) ( n.Spec.ClusterName = r.ClusterName n.Spec.IP = internalIP n.Spec.IP6 = internalIP6 - n.Spec.InterfaceName = interfacepolicy.GetInterfaceName(cluster.Spec.NICNodeNames, node.Name, cluster.Spec.DefaultNICName) + n.Spec.InterfaceName = interfacepolicy.GetInterfaceName(cluster.Spec.ClusterLinkOptions.NICNodeNames, node.Name, cluster.Spec.ClusterLinkOptions.DefaultNICName) return nil }) if err != nil { diff --git a/pkg/clusterlink/controllers/nodecidr/nodecidr_controller.go b/pkg/clusterlink/controllers/nodecidr/nodecidr_controller.go index 3f6b1774a..d529040ce 100644 --- a/pkg/clusterlink/controllers/nodecidr/nodecidr_controller.go +++ b/pkg/clusterlink/controllers/nodecidr/nodecidr_controller.go @@ -102,7 +102,7 @@ func (c *controller) Start(ctx context.Context) error { clusterInformerFactory.WaitForCacheSync(stopCh) // third step: init CNI Adapter - if cluster.Spec.CNI == calicoCNI { + if cluster.Spec.ClusterLinkOptions.CNI == calicoCNI { c.cniAdapter = NewCalicoAdapter(c.config, c.clusterNodeLister, c.processor) } else { c.cniAdapter = NewCommonAdapter(c.config, c.clusterNodeLister, c.processor) diff --git a/pkg/clusterlink/network-manager/handlers/globalmap.go b/pkg/clusterlink/network-manager/handlers/globalmap.go index 823685b98..3c8393e46 100644 --- a/pkg/clusterlink/network-manager/handlers/globalmap.go +++ b/pkg/clusterlink/network-manager/handlers/globalmap.go @@ -23,10 +23,10 @@ func (h *GlobalMap) Do(c *Context) (err error) { for _, n := range nodes { cluster := c.Filter.GetClusterByName(n.Spec.ClusterName) - globalMap := cluster.Spec.GlobalCIDRsMap + globalMap := cluster.Spec.ClusterLinkOptions.GlobalCIDRsMap if len(globalMap) > 0 { - for src, dst := range cluster.Spec.GlobalCIDRsMap { + for src, dst := range cluster.Spec.ClusterLinkOptions.GlobalCIDRsMap { ipType := helpers.GetIPType(src) var vxBridge string diff --git a/pkg/clusterlink/network-manager/handlers/host_network.go b/pkg/clusterlink/network-manager/handlers/host_network.go index 18e177e30..8496c57bf 100644 --- a/pkg/clusterlink/network-manager/handlers/host_network.go +++ b/pkg/clusterlink/network-manager/handlers/host_network.go @@ -24,13 +24,13 @@ func (h *HostNetwork) Do(c *Context) (err error) { c.Results[n.Name].Iptables = append(c.Results[n.Name].Iptables, v1alpha1.Iptables{ Table: "nat", Chain: constants.IPTablesPostRoutingChain, - Rule: fmt.Sprintf("-s %s -o %s -j MASQUERADE", cluster.Spec.LocalCIDRs.IP, constants.VXLAN_BRIDGE_NAME), + Rule: fmt.Sprintf("-s %s -o %s -j MASQUERADE", cluster.Spec.ClusterLinkOptions.LocalCIDRs.IP, constants.VXLAN_BRIDGE_NAME), }) c.Results[n.Name].Iptables = append(c.Results[n.Name].Iptables, v1alpha1.Iptables{ Table: "nat", Chain: constants.IPTablesPostRoutingChain, - Rule: fmt.Sprintf("-s %s -j MASQUERADE", cluster.Spec.BridgeCIDRs.IP), + Rule: fmt.Sprintf("-s %s -j MASQUERADE", cluster.Spec.ClusterLinkOptions.BridgeCIDRs.IP), }) } @@ -38,13 +38,13 @@ func (h *HostNetwork) Do(c *Context) (err error) { c.Results[n.Name].Iptables = append(c.Results[n.Name].Iptables, v1alpha1.Iptables{ Table: "nat", Chain: constants.IPTablesPostRoutingChain, - Rule: fmt.Sprintf("-s %s -o %s -j MASQUERADE", cluster.Spec.LocalCIDRs.IP6, constants.VXLAN_BRIDGE_NAME_6), + Rule: fmt.Sprintf("-s %s -o %s -j MASQUERADE", cluster.Spec.ClusterLinkOptions.LocalCIDRs.IP6, constants.VXLAN_BRIDGE_NAME_6), }) c.Results[n.Name].Iptables = append(c.Results[n.Name].Iptables, v1alpha1.Iptables{ Table: "nat", Chain: constants.IPTablesPostRoutingChain, - Rule: fmt.Sprintf("-s %s -j MASQUERADE", cluster.Spec.BridgeCIDRs.IP6), + Rule: fmt.Sprintf("-s %s -j MASQUERADE", cluster.Spec.ClusterLinkOptions.BridgeCIDRs.IP6), }) } } diff --git a/pkg/clusterlink/network-manager/handlers/pod_routes.go b/pkg/clusterlink/network-manager/handlers/pod_routes.go index 8cba943db..6584d185e 100644 --- a/pkg/clusterlink/network-manager/handlers/pod_routes.go +++ b/pkg/clusterlink/network-manager/handlers/pod_routes.go @@ -27,10 +27,10 @@ func (h *PodRoutes) Do(c *Context) (err error) { if cluster.IsP2P() { podCIDRs = target.Spec.PodCIDRs } else { - podCIDRs = cluster.Status.PodCIDRs + podCIDRs = cluster.Status.ClusterLinkStatus.PodCIDRs } - podCIDRs = ConvertToGlobalCIDRs(podCIDRs, cluster.Spec.GlobalCIDRsMap) + podCIDRs = ConvertToGlobalCIDRs(podCIDRs, cluster.Spec.ClusterLinkOptions.GlobalCIDRsMap) BuildRoutes(c, target, podCIDRs) } @@ -90,7 +90,7 @@ func BuildRoutes(ctx *Context, target *v1alpha1.ClusterNode, cidrs []string) { for _, n := range otherClusterNodes { srcCluster := ctx.Filter.GetClusterByName(n.Spec.ClusterName) - allCIDRs := append(srcCluster.Status.PodCIDRs, srcCluster.Status.ServiceCIDRs...) + allCIDRs := append(srcCluster.Status.ClusterLinkStatus.PodCIDRs, srcCluster.Status.ClusterLinkStatus.ServiceCIDRs...) if ifCIDRConflictWithSelf(allCIDRs, cidr) { continue } diff --git a/pkg/clusterlink/network-manager/handlers/svc_routes.go b/pkg/clusterlink/network-manager/handlers/svc_routes.go index d21a98d48..4498f02d3 100644 --- a/pkg/clusterlink/network-manager/handlers/svc_routes.go +++ b/pkg/clusterlink/network-manager/handlers/svc_routes.go @@ -9,9 +9,9 @@ func (h *ServiceRoutes) Do(c *Context) (err error) { for _, target := range gwNodes { cluster := c.Filter.GetClusterByName(target.Spec.ClusterName) - serviceCIDRs := cluster.Status.ServiceCIDRs + serviceCIDRs := cluster.Status.ClusterLinkStatus.ServiceCIDRs - serviceCIDRs = ConvertToGlobalCIDRs(serviceCIDRs, cluster.Spec.GlobalCIDRsMap) + serviceCIDRs = ConvertToGlobalCIDRs(serviceCIDRs, cluster.Spec.ClusterLinkOptions.GlobalCIDRsMap) BuildRoutes(c, target, serviceCIDRs) } diff --git a/pkg/clusterlink/network-manager/handlers/vxbridge_network.go b/pkg/clusterlink/network-manager/handlers/vxbridge_network.go index be2a48b21..e80012cd2 100644 --- a/pkg/clusterlink/network-manager/handlers/vxbridge_network.go +++ b/pkg/clusterlink/network-manager/handlers/vxbridge_network.go @@ -40,18 +40,18 @@ func (h *VxBridgeNetwork) Do(c *Context) (err error) { func (h *VxBridgeNetwork) needToCreateVxBridge(c *Context, clusterNode *v1alpha1.ClusterNode, cluster *v1alpha1.Cluster) bool { return c.Filter.SupportIPv4(clusterNode) && clusterNode.Spec.IP != "" && - cluster.Spec.BridgeCIDRs.IP != "" + cluster.Spec.ClusterLinkOptions.BridgeCIDRs.IP != "" } func (h *VxBridgeNetwork) needToCreateVxBridge6(c *Context, clusterNode *v1alpha1.ClusterNode, cluster *v1alpha1.Cluster) bool { return c.Filter.SupportIPv6(clusterNode) && clusterNode.Spec.IP6 != "" && - cluster.Spec.BridgeCIDRs.IP6 != "" + cluster.Spec.ClusterLinkOptions.BridgeCIDRs.IP6 != "" } func (h *VxBridgeNetwork) createVxBridge(c *Context, clusterNode *v1alpha1.ClusterNode, cluster *v1alpha1.Cluster) *v1alpha1.Device { devOld := c.Filter.GetDeviceFromNodeConfig(clusterNode.Name, constants.VXLAN_BRIDGE_NAME) - dev := helpers.BuildVxlanDevice(constants.VXLAN_BRIDGE_NAME, clusterNode.Spec.IP, cluster.Spec.BridgeCIDRs.IP, clusterNode.Spec.InterfaceName) + dev := helpers.BuildVxlanDevice(constants.VXLAN_BRIDGE_NAME, clusterNode.Spec.IP, cluster.Spec.ClusterLinkOptions.BridgeCIDRs.IP, clusterNode.Spec.InterfaceName) if devOld != nil && devOld.Mac != "" { dev.Mac = devOld.Mac } @@ -60,7 +60,7 @@ func (h *VxBridgeNetwork) createVxBridge(c *Context, clusterNode *v1alpha1.Clust func (h *VxBridgeNetwork) createVxBridge6(c *Context, clusterNode *v1alpha1.ClusterNode, cluster *v1alpha1.Cluster) *v1alpha1.Device { devOld := c.Filter.GetDeviceFromNodeConfig(clusterNode.Name, constants.VXLAN_BRIDGE_NAME_6) - dev := helpers.BuildVxlanDevice(constants.VXLAN_BRIDGE_NAME_6, clusterNode.Spec.IP6, cluster.Spec.BridgeCIDRs.IP6, clusterNode.Spec.InterfaceName) + dev := helpers.BuildVxlanDevice(constants.VXLAN_BRIDGE_NAME_6, clusterNode.Spec.IP6, cluster.Spec.ClusterLinkOptions.BridgeCIDRs.IP6, clusterNode.Spec.InterfaceName) if devOld != nil && devOld.Mac != "" { dev.Mac = devOld.Mac } diff --git a/pkg/clusterlink/network-manager/handlers/vxlocal_network.go b/pkg/clusterlink/network-manager/handlers/vxlocal_network.go index 3ed508b5f..fab4ab352 100644 --- a/pkg/clusterlink/network-manager/handlers/vxlocal_network.go +++ b/pkg/clusterlink/network-manager/handlers/vxlocal_network.go @@ -37,18 +37,18 @@ func (h *VxLocalNetwork) Do(c *Context) (err error) { func (h *VxLocalNetwork) needToCreateVxLocal(c *Context, clusterNode *v1alpha1.ClusterNode, cluster *v1alpha1.Cluster) bool { return c.Filter.SupportIPv4(clusterNode) && clusterNode.Spec.IP != "" && - cluster.Spec.LocalCIDRs.IP != "" + cluster.Spec.ClusterLinkOptions.LocalCIDRs.IP != "" } func (h *VxLocalNetwork) needToCreateVxLocal6(c *Context, clusterNode *v1alpha1.ClusterNode, cluster *v1alpha1.Cluster) bool { return c.Filter.SupportIPv6(clusterNode) && clusterNode.Spec.IP6 != "" && - cluster.Spec.LocalCIDRs.IP6 != "" + cluster.Spec.ClusterLinkOptions.LocalCIDRs.IP6 != "" } func (h *VxLocalNetwork) createVxLocal(c *Context, clusterNode *v1alpha1.ClusterNode, cluster *v1alpha1.Cluster) *v1alpha1.Device { devOld := c.Filter.GetDeviceFromNodeConfig(clusterNode.Name, constants.VXLAN_LOCAL_NAME) - dev := helpers.BuildVxlanDevice(constants.VXLAN_LOCAL_NAME, clusterNode.Spec.IP, cluster.Spec.LocalCIDRs.IP, clusterNode.Spec.InterfaceName) + dev := helpers.BuildVxlanDevice(constants.VXLAN_LOCAL_NAME, clusterNode.Spec.IP, cluster.Spec.ClusterLinkOptions.LocalCIDRs.IP, clusterNode.Spec.InterfaceName) if devOld != nil && devOld.Mac != "" { dev.Mac = devOld.Mac } @@ -57,7 +57,7 @@ func (h *VxLocalNetwork) createVxLocal(c *Context, clusterNode *v1alpha1.Cluster func (h *VxLocalNetwork) createVxLocal6(c *Context, clusterNode *v1alpha1.ClusterNode, cluster *v1alpha1.Cluster) *v1alpha1.Device { devOld := c.Filter.GetDeviceFromNodeConfig(clusterNode.Name, constants.VXLAN_LOCAL_NAME_6) - dev := helpers.BuildVxlanDevice(constants.VXLAN_LOCAL_NAME_6, clusterNode.Spec.IP6, cluster.Spec.LocalCIDRs.IP6, clusterNode.Spec.InterfaceName) + dev := helpers.BuildVxlanDevice(constants.VXLAN_LOCAL_NAME_6, clusterNode.Spec.IP6, cluster.Spec.ClusterLinkOptions.LocalCIDRs.IP6, clusterNode.Spec.InterfaceName) if devOld != nil && devOld.Mac != "" { dev.Mac = devOld.Mac } diff --git a/pkg/clusterlink/network-manager/helpers/filter.go b/pkg/clusterlink/network-manager/helpers/filter.go index 98b89c8c6..071a5746b 100644 --- a/pkg/clusterlink/network-manager/helpers/filter.go +++ b/pkg/clusterlink/network-manager/helpers/filter.go @@ -121,12 +121,12 @@ func (f *Filter) GetGatewayClusterNodes() []*v1alpha1.ClusterNode { func (f *Filter) SupportIPv4(node *v1alpha1.ClusterNode) bool { cluster := f.GetClusterByName(node.Spec.ClusterName) - return cluster.Spec.IPFamily == v1alpha1.IPFamilyTypeALL || cluster.Spec.IPFamily == v1alpha1.IPFamilyTypeIPV4 + return cluster.Spec.ClusterLinkOptions.IPFamily == v1alpha1.IPFamilyTypeALL || cluster.Spec.ClusterLinkOptions.IPFamily == v1alpha1.IPFamilyTypeIPV4 } func (f *Filter) SupportIPv6(node *v1alpha1.ClusterNode) bool { cluster := f.GetClusterByName(node.Spec.ClusterName) - return cluster.Spec.IPFamily == v1alpha1.IPFamilyTypeALL || cluster.Spec.IPFamily == v1alpha1.IPFamilyTypeIPV6 + return cluster.Spec.ClusterLinkOptions.IPFamily == v1alpha1.IPFamilyTypeALL || cluster.Spec.ClusterLinkOptions.IPFamily == v1alpha1.IPFamilyTypeIPV6 } func (f *Filter) GetDeviceFromNodeConfig(nodeName string, devName string) *v1alpha1.Device { diff --git a/pkg/clusterlink/network/adapter.go b/pkg/clusterlink/network/adapter.go index 458e690d8..c8ce08b80 100644 --- a/pkg/clusterlink/network/adapter.go +++ b/pkg/clusterlink/network/adapter.go @@ -185,5 +185,5 @@ func (n *DefaultNetWork) InitSys() { } func (n *DefaultNetWork) UpdateCidrConfig(cluster *clusterlinkv1alpha1.Cluster) { - UpdateCidr(cluster.Spec.BridgeCIDRs.IP, cluster.Spec.BridgeCIDRs.IP6, cluster.Spec.LocalCIDRs.IP, cluster.Spec.LocalCIDRs.IP6) + UpdateCidr(cluster.Spec.ClusterLinkOptions.BridgeCIDRs.IP, cluster.Spec.ClusterLinkOptions.BridgeCIDRs.IP6, cluster.Spec.ClusterLinkOptions.LocalCIDRs.IP, cluster.Spec.ClusterLinkOptions.LocalCIDRs.IP6) } diff --git a/pkg/clusterlink/operator/addons/option/option.go b/pkg/clusterlink/operator/addons/option/option.go index 5cc814d2c..d92777524 100644 --- a/pkg/clusterlink/operator/addons/option/option.go +++ b/pkg/clusterlink/operator/addons/option/option.go @@ -55,7 +55,7 @@ func (o *AddonOption) GetSpecNamespace() string { } func (o *AddonOption) GetImageRepository() string { - return o.Spec.ClusterLinkOptions.ImageRepository + return o.Spec.ImageRepository } func (o *AddonOption) GetIPFamily() string { diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 61095e4c8..750301275 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -17,6 +17,8 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA return map[string]common.OpenAPIDefinition{ "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.Arp": schema_pkg_apis_kosmos_v1alpha1_Arp(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.Cluster": schema_pkg_apis_kosmos_v1alpha1_Cluster(ref), + "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.ClusterLinkOptions": schema_pkg_apis_kosmos_v1alpha1_ClusterLinkOptions(ref), + "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.ClusterLinkStatus": schema_pkg_apis_kosmos_v1alpha1_ClusterLinkStatus(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.ClusterList": schema_pkg_apis_kosmos_v1alpha1_ClusterList(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.ClusterNode": schema_pkg_apis_kosmos_v1alpha1_ClusterNode(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.ClusterNodeList": schema_pkg_apis_kosmos_v1alpha1_ClusterNodeList(ref), @@ -24,6 +26,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.ClusterNodeStatus": schema_pkg_apis_kosmos_v1alpha1_ClusterNodeStatus(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.ClusterSpec": schema_pkg_apis_kosmos_v1alpha1_ClusterSpec(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.ClusterStatus": schema_pkg_apis_kosmos_v1alpha1_ClusterStatus(ref), + "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.ClusterTreeOptions": schema_pkg_apis_kosmos_v1alpha1_ClusterTreeOptions(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.DaemonSet": schema_pkg_apis_kosmos_v1alpha1_DaemonSet(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.DaemonSetList": schema_pkg_apis_kosmos_v1alpha1_DaemonSetList(ref), "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.DaemonSetSpec": schema_pkg_apis_kosmos_v1alpha1_DaemonSetSpec(ref), @@ -183,6 +186,140 @@ func schema_pkg_apis_kosmos_v1alpha1_Cluster(ref common.ReferenceCallback) commo } } +func schema_pkg_apis_kosmos_v1alpha1_ClusterLinkOptions(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "enable": { + SchemaProps: spec.SchemaProps{ + Default: false, + Type: []string{"boolean"}, + Format: "", + }, + }, + "cni": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "networkType": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "ipFamily": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "useIPPool": { + SchemaProps: spec.SchemaProps{ + Type: []string{"boolean"}, + Format: "", + }, + }, + "localCIDRs": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.VxlanCIDRs"), + }, + }, + "bridgeCIDRs": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.VxlanCIDRs"), + }, + }, + "nicNodeNames": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.NICNodeNames"), + }, + }, + }, + }, + }, + "defaultNICName": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + "globalCIDRsMap": { + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + }, + }, + }, + Dependencies: []string{ + "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.NICNodeNames", "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.VxlanCIDRs"}, + } +} + +func schema_pkg_apis_kosmos_v1alpha1_ClusterLinkStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "podCIDRs": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + "serviceCIDRs": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + }, + }, + }, + } +} + func schema_pkg_apis_kosmos_v1alpha1_ClusterList(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -413,31 +550,10 @@ func schema_pkg_apis_kosmos_v1alpha1_ClusterSpec(ref common.ReferenceCallback) c SchemaProps: spec.SchemaProps{ Type: []string{"object"}, Properties: map[string]spec.Schema{ - "cni": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "networkType": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "ipFamily": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "imageRepository": { + "kubeconfig": { SchemaProps: spec.SchemaProps{ Type: []string{"string"}, - Format: "", + Format: "byte", }, }, "namespace": { @@ -447,69 +563,29 @@ func schema_pkg_apis_kosmos_v1alpha1_ClusterSpec(ref common.ReferenceCallback) c Format: "", }, }, - "useIPPool": { + "imageRepository": { SchemaProps: spec.SchemaProps{ - Type: []string{"boolean"}, + Type: []string{"string"}, Format: "", }, }, - "localCIDRs": { + "clusterLinkOptions": { SchemaProps: spec.SchemaProps{ Default: map[string]interface{}{}, - Ref: ref("github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.VxlanCIDRs"), + Ref: ref("github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.ClusterLinkOptions"), }, }, - "bridgeCIDRs": { + "clusterTreeOptions": { SchemaProps: spec.SchemaProps{ Default: map[string]interface{}{}, - Ref: ref("github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.VxlanCIDRs"), - }, - }, - "nicNodeNames": { - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.NICNodeNames"), - }, - }, - }, - }, - }, - "defaultNICName": { - SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "", - }, - }, - "globalCIDRsMap": { - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - AdditionalProperties: &spec.SchemaOrBool{ - Allows: true, - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - "kubeconfig": { - SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "byte", + Ref: ref("github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.ClusterTreeOptions"), }, }, }, }, }, Dependencies: []string{ - "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.NICNodeNames", "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.VxlanCIDRs"}, + "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.ClusterLinkOptions", "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.ClusterTreeOptions"}, } } @@ -519,32 +595,31 @@ func schema_pkg_apis_kosmos_v1alpha1_ClusterStatus(ref common.ReferenceCallback) SchemaProps: spec.SchemaProps{ Type: []string{"object"}, Properties: map[string]spec.Schema{ - "podCIDRs": { + "clusterLinkStatus": { SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, + Default: map[string]interface{}{}, + Ref: ref("github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.ClusterLinkStatus"), }, }, - "serviceCIDRs": { + }, + }, + }, + Dependencies: []string{ + "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1.ClusterLinkStatus"}, + } +} + +func schema_pkg_apis_kosmos_v1alpha1_ClusterTreeOptions(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "enable": { SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, + Default: false, + Type: []string{"boolean"}, + Format: "", }, }, }, @@ -1043,12 +1118,6 @@ func schema_pkg_apis_kosmos_v1alpha1_KnodeSpec(ref common.ReferenceCallback) com Format: "byte", }, }, - "kubeAPIQPS": { - SchemaProps: spec.SchemaProps{ - Type: []string{"number"}, - Format: "float", - }, - }, "kubeAPIBurst": { SchemaProps: spec.SchemaProps{ Type: []string{"integer"},