From 91762d38a0da276fe91b16a6b9560319ca222463 Mon Sep 17 00:00:00 2001 From: ONE7live Date: Tue, 7 Nov 2023 14:37:25 +0800 Subject: [PATCH] fix: Remove node related logic Signed-off-by: ONE7live --- deploy/crds/kosmos.io_knodes.yaml | 127 ----- pkg/kosmosctl/install/install.go | 291 ++++++++---- pkg/kosmosctl/join/join.go | 24 +- pkg/kosmosctl/manifest/manifest_crds.go | 603 +++++------------------- pkg/kosmosctl/uninstall/uninstall.go | 10 +- pkg/operator/operator_controller.go | 10 +- pkg/utils/constants.go | 2 +- 7 files changed, 345 insertions(+), 722 deletions(-) delete mode 100644 deploy/crds/kosmos.io_knodes.yaml diff --git a/deploy/crds/kosmos.io_knodes.yaml b/deploy/crds/kosmos.io_knodes.yaml deleted file mode 100644 index 647c18313..000000000 --- a/deploy/crds/kosmos.io_knodes.yaml +++ /dev/null @@ -1,127 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.11.0 - creationTimestamp: null - name: knodes.kosmos.io -spec: - group: kosmos.io - names: - kind: Knode - listKind: KnodeList - plural: knodes - singular: knode - scope: Cluster - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - properties: - disableTaint: - type: boolean - kubeAPIBurst: - default: 100 - type: integer - kubeconfig: - format: byte - type: string - nodeName: - type: string - type: - default: k8s - type: string - type: object - status: - properties: - apiserver: - type: string - conditions: - items: - description: "Condition contains details for one aspect of the current - state of this API Resource. --- This struct is intended for direct - use as an array at the field path .status.conditions. For example, - \n type FooStatus struct{ // Represents the observations of a - foo's current state. // Known .status.conditions.type are: \"Available\", - \"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge - // +listType=map // +listMapKey=type Conditions []metav1.Condition - `json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\" - protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }" - properties: - lastTransitionTime: - description: lastTransitionTime is the last time the condition - transitioned from one status to another. This should be when - the underlying condition changed. If that is not known, then - using the time when the API field changed is acceptable. - format: date-time - type: string - message: - description: message is a human readable message indicating - details about the transition. This may be an empty string. - maxLength: 32768 - type: string - observedGeneration: - description: observedGeneration represents the .metadata.generation - that the condition was set based upon. For instance, if .metadata.generation - is currently 12, but the .status.conditions[x].observedGeneration - is 9, the condition is out of date with respect to the current - state of the instance. - format: int64 - minimum: 0 - type: integer - reason: - description: reason contains a programmatic identifier indicating - the reason for the condition's last transition. Producers - of specific condition types may define expected values and - meanings for this field, and whether the values are considered - a guaranteed API. The value should be a CamelCase string. - This field may not be empty. - maxLength: 1024 - minLength: 1 - pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$ - type: string - status: - description: status of the condition, one of True, False, Unknown. - enum: - - "True" - - "False" - - Unknown - type: string - type: - description: type of condition in CamelCase or in foo.example.com/CamelCase. - --- Many .condition.type values are consistent across resources - like Available, but because arbitrary conditions can be useful - (see .node.status.conditions), the ability to deconflict is - important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt) - maxLength: 316 - pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ - type: string - required: - - lastTransitionTime - - message - - reason - - status - - type - type: object - type: array - version: - type: string - type: object - type: object - served: true - storage: true diff --git a/pkg/kosmosctl/install/install.go b/pkg/kosmosctl/install/install.go index 7429cb4de..fba7441b0 100644 --- a/pkg/kosmosctl/install/install.go +++ b/pkg/kosmosctl/install/install.go @@ -2,7 +2,6 @@ package install import ( "context" - "encoding/base64" "fmt" "os" "path/filepath" @@ -173,12 +172,20 @@ func (o *CommandInstallOptions) Run() error { if err != nil { return err } + err = o.createControlCluster() + if err != nil { + return err + } util.CheckInstall("Clusterlink") case utils.ClusterTree: err := o.runClustertree() if err != nil { return err } + err = o.createControlCluster() + if err != nil { + return err + } util.CheckInstall("Clustertree") case utils.All: err := o.runClusterlink() @@ -189,6 +196,10 @@ func (o *CommandInstallOptions) Run() error { if err != nil { return err } + err = o.createControlCluster() + if err != nil { + return err + } util.CheckInstall("Clusterlink && Clustertree") } @@ -250,17 +261,17 @@ func (o *CommandInstallOptions) runClusterlink() error { klog.Info("Attempting to create Kosmos-Clusterlink CRDs...") crds := apiextensionsv1.CustomResourceDefinitionList{} - clusterlinkCluster, err := util.GenerateCustomResourceDefinition(manifest.ClusterlinkCluster, manifest.ClusterlinkReplace{ + clusterlinkCluster, err := util.GenerateCustomResourceDefinition(manifest.Cluster, manifest.CRDReplace{ Namespace: o.Namespace, }) if err != nil { return err } - clusterlinkClusterNode, err := util.GenerateCustomResourceDefinition(manifest.ClusterlinkClusterNode, nil) + clusterlinkClusterNode, err := util.GenerateCustomResourceDefinition(manifest.ClusterNode, nil) if err != nil { return err } - clusterlinkNodeConfig, err := util.GenerateCustomResourceDefinition(manifest.ClusterlinkNodeConfig, nil) + clusterlinkNodeConfig, err := util.GenerateCustomResourceDefinition(manifest.NodeConfig, nil) if err != nil { return err } @@ -268,7 +279,10 @@ func (o *CommandInstallOptions) runClusterlink() error { for i := range crds.Items { _, err = o.K8sExtensionsClient.ApiextensionsV1().CustomResourceDefinitions().Create(context.Background(), &crds.Items[i], metav1.CreateOptions{}) if err != nil { - if !apierrors.IsAlreadyExists(err) { + if apierrors.IsAlreadyExists(err) { + klog.Warningf("CRD %v is existed, creation process will skip", &crds.Items[i].Name) + continue + } else { return fmt.Errorf("kosmosctl install clusterlink run error, crd options failed: %v", err) } } @@ -318,59 +332,6 @@ func (o *CommandInstallOptions) runClusterlink() error { } } - controlCluster, err := o.KosmosClient.KosmosV1alpha1().Clusters().Get(context.TODO(), utils.DefaultClusterName, metav1.GetOptions{}) - if err != nil { - if apierrors.IsNotFound(err) { - clusterArgs := []string{"cluster"} - base64ClusterKubeConfig := base64.StdEncoding.EncodeToString(o.HostKubeConfigStream) - joinOptions := join.CommandJoinOptions{ - Name: utils.DefaultClusterName, - KubeConfig: base64ClusterKubeConfig, - WaitTime: o.WaitTime, - KosmosClient: o.KosmosClient, - K8sClient: o.K8sClient, - K8sDynamicClient: o.K8sDynamicClient, - RootFlag: true, - } - - joinOptions.CNI = o.CNI - joinOptions.DefaultNICName = o.DefaultNICName - joinOptions.NetworkType = o.NetworkType - joinOptions.IpFamily = o.IpFamily - joinOptions.UseProxy = o.UseProxy - - err = joinOptions.Run(clusterArgs) - if err != nil { - return fmt.Errorf("kosmosctl install run error, join control panel cluster failed: %s", err) - } - } else { - return fmt.Errorf("kosmosctl install run error, get control panel cluster failed: %s", err) - } - } - - if !controlCluster.Spec.ClusterLinkOptions.Enable { - controlCluster.Spec.ClusterLinkOptions.Enable = true - controlCluster.Spec.ClusterLinkOptions.CNI = o.CNI - controlCluster.Spec.ClusterLinkOptions.DefaultNICName = o.DefaultNICName - switch o.NetworkType { - case utils.NetworkTypeGateway: - controlCluster.Spec.ClusterLinkOptions.NetworkType = v1alpha1.NetWorkTypeGateWay - case utils.NetworkTypeP2P: - controlCluster.Spec.ClusterLinkOptions.NetworkType = v1alpha1.NetworkTypeP2P - } - - switch o.IpFamily { - case utils.DefaultIPv4: - controlCluster.Spec.ClusterLinkOptions.IPFamily = v1alpha1.IPFamilyTypeIPV4 - case utils.DefaultIPv6: - controlCluster.Spec.ClusterLinkOptions.IPFamily = v1alpha1.IPFamilyTypeIPV6 - } - _, err = o.KosmosClient.KosmosV1alpha1().Clusters().Update(context.TODO(), controlCluster, metav1.UpdateOptions{}) - if err != nil { - return fmt.Errorf("kosmosctl install clusterlink run error, update control panel cluster failed: %s", err) - } - } - return nil } @@ -429,18 +390,20 @@ func (o *CommandInstallOptions) runClustertree() error { } klog.Info("ClusterRoleBinding " + clustertreeCRB.Name + " has been created.") - klog.Info("Attempting to create kosmos-clustertree knode CRDs...") - clustertreeKnode, err := util.GenerateCustomResourceDefinition(manifest.ClusterTreeKnode, nil) + klog.Info("Attempting to create kosmos-clustertree CRDs...") + clustertreeCluster, err := util.GenerateCustomResourceDefinition(manifest.Cluster, nil) if err != nil { return err } - _, err = o.K8sExtensionsClient.ApiextensionsV1().CustomResourceDefinitions().Create(context.Background(), clustertreeKnode, metav1.CreateOptions{}) + _, err = o.K8sExtensionsClient.ApiextensionsV1().CustomResourceDefinitions().Create(context.Background(), clustertreeCluster, metav1.CreateOptions{}) if err != nil { - if !apierrors.IsAlreadyExists(err) { + if apierrors.IsAlreadyExists(err) { + klog.Warningf("CRD %v is existed, creation process will skip", clustertreeCluster.Name) + } else { return fmt.Errorf("kosmosctl install clustertree run error, crd options failed: %v", err) } } - klog.Info("Create CRD " + clustertreeKnode.Name + " successful.") + klog.Info("Create CRD " + clustertreeCluster.Name + " successful.") serviceExport, err := util.GenerateCustomResourceDefinition(manifest.ServiceExport, nil) if err != nil { @@ -527,38 +490,6 @@ func (o *CommandInstallOptions) runClustertree() error { } } - controlCluster, err := o.KosmosClient.KosmosV1alpha1().Clusters().Get(context.TODO(), utils.DefaultClusterName, metav1.GetOptions{}) - if err != nil { - if apierrors.IsNotFound(err) { - clusterArgs := []string{"cluster"} - base64ClusterKubeConfig := base64.StdEncoding.EncodeToString(o.HostKubeConfigStream) - joinOptions := join.CommandJoinOptions{ - Name: utils.DefaultClusterName, - KubeConfig: base64ClusterKubeConfig, - WaitTime: o.WaitTime, - KosmosClient: o.KosmosClient, - K8sClient: o.K8sClient, - K8sDynamicClient: o.K8sDynamicClient, - RootFlag: true, - } - - err = joinOptions.Run(clusterArgs) - if err != nil { - return fmt.Errorf("kosmosctl install run error, join control panel cluster failed: %s", err) - } - } else { - return fmt.Errorf("kosmosctl install run error, get control panel cluster failed: %s", err) - } - } - - if !controlCluster.Spec.ClusterTreeOptions.Enable { - controlCluster.Spec.ClusterTreeOptions.Enable = true - _, err = o.KosmosClient.KosmosV1alpha1().Clusters().Update(context.TODO(), controlCluster, metav1.UpdateOptions{}) - if err != nil { - return fmt.Errorf("kosmosctl install clustertree run error, update control panel cluster failed: %s", err) - } - } - return nil } @@ -634,6 +565,166 @@ func (o *CommandInstallOptions) createOperator() error { return nil } +func (o *CommandInstallOptions) createControlCluster() error { + switch o.Module { + case utils.ClusterLink: + controlCluster, err := o.KosmosClient.KosmosV1alpha1().Clusters().Get(context.TODO(), utils.DefaultClusterName, metav1.GetOptions{}) + if err != nil { + if apierrors.IsNotFound(err) { + clusterArgs := []string{"cluster"} + joinOptions := join.CommandJoinOptions{ + Name: utils.DefaultClusterName, + Namespace: o.Namespace, + ImageRegistry: o.ImageRegistry, + KubeConfigStream: o.HostKubeConfigStream, + WaitTime: o.WaitTime, + KosmosClient: o.KosmosClient, + K8sClient: o.K8sClient, + K8sDynamicClient: o.K8sDynamicClient, + RootFlag: true, + EnableLink: true, + CNI: o.CNI, + DefaultNICName: o.DefaultNICName, + NetworkType: o.NetworkType, + IpFamily: o.IpFamily, + UseProxy: o.UseProxy, + } + + err = joinOptions.Run(clusterArgs) + if err != nil { + return fmt.Errorf("kosmosctl install run error, join control panel cluster failed: %s", err) + } + } else { + return fmt.Errorf("kosmosctl install run error, get control panel cluster failed: %s", err) + } + } + + if len(controlCluster.Name) > 0 { + if !controlCluster.Spec.ClusterLinkOptions.Enable { + controlCluster.Spec.ClusterLinkOptions.Enable = true + controlCluster.Spec.ClusterLinkOptions.CNI = o.CNI + controlCluster.Spec.ClusterLinkOptions.DefaultNICName = o.DefaultNICName + switch o.NetworkType { + case utils.NetworkTypeGateway: + controlCluster.Spec.ClusterLinkOptions.NetworkType = v1alpha1.NetWorkTypeGateWay + case utils.NetworkTypeP2P: + controlCluster.Spec.ClusterLinkOptions.NetworkType = v1alpha1.NetworkTypeP2P + } + + switch o.IpFamily { + case utils.DefaultIPv4: + controlCluster.Spec.ClusterLinkOptions.IPFamily = v1alpha1.IPFamilyTypeIPV4 + case utils.DefaultIPv6: + controlCluster.Spec.ClusterLinkOptions.IPFamily = v1alpha1.IPFamilyTypeIPV6 + } + _, err = o.KosmosClient.KosmosV1alpha1().Clusters().Update(context.TODO(), controlCluster, metav1.UpdateOptions{}) + if err != nil { + klog.Infof("ControlCluster-Link: ", controlCluster) + return fmt.Errorf("kosmosctl install clusterlink run error, update control panel cluster failed: %s", err) + } + } + } + case utils.ClusterTree: + controlCluster, err := o.KosmosClient.KosmosV1alpha1().Clusters().Get(context.TODO(), utils.DefaultClusterName, metav1.GetOptions{}) + if err != nil { + if apierrors.IsNotFound(err) { + clusterArgs := []string{"cluster"} + joinOptions := join.CommandJoinOptions{ + Name: utils.DefaultClusterName, + Namespace: o.Namespace, + ImageRegistry: o.ImageRegistry, + KubeConfigStream: o.HostKubeConfigStream, + WaitTime: o.WaitTime, + KosmosClient: o.KosmosClient, + K8sClient: o.K8sClient, + K8sDynamicClient: o.K8sDynamicClient, + RootFlag: true, + EnableTree: true, + } + + err = joinOptions.Run(clusterArgs) + if err != nil { + return fmt.Errorf("kosmosctl install run error, join control panel cluster failed: %s", err) + } + } else { + return fmt.Errorf("kosmosctl install run error, get control panel cluster failed: %s", err) + } + } + + if len(controlCluster.Name) > 0 { + if !controlCluster.Spec.ClusterTreeOptions.Enable { + controlCluster.Spec.ClusterTreeOptions.Enable = true + _, err = o.KosmosClient.KosmosV1alpha1().Clusters().Update(context.TODO(), controlCluster, metav1.UpdateOptions{}) + if err != nil { + klog.Infof("ControlCluster-Tree: ", controlCluster) + return fmt.Errorf("kosmosctl install clustertree run error, update control panel cluster failed: %s", err) + } + } + } + case utils.All: + controlCluster, err := o.KosmosClient.KosmosV1alpha1().Clusters().Get(context.TODO(), utils.DefaultClusterName, metav1.GetOptions{}) + if err != nil { + if apierrors.IsNotFound(err) { + clusterArgs := []string{"cluster"} + joinOptions := join.CommandJoinOptions{ + Name: utils.DefaultClusterName, + Namespace: o.Namespace, + ImageRegistry: o.ImageRegistry, + KubeConfigStream: o.HostKubeConfigStream, + WaitTime: o.WaitTime, + KosmosClient: o.KosmosClient, + K8sClient: o.K8sClient, + K8sDynamicClient: o.K8sDynamicClient, + RootFlag: true, + EnableLink: true, + CNI: o.CNI, + DefaultNICName: o.DefaultNICName, + NetworkType: o.NetworkType, + IpFamily: o.IpFamily, + UseProxy: o.UseProxy, + EnableTree: true, + } + + err = joinOptions.Run(clusterArgs) + if err != nil { + return fmt.Errorf("kosmosctl install run error, join control panel cluster failed: %s", err) + } + } else { + return fmt.Errorf("kosmosctl install run error, get control panel cluster failed: %s", err) + } + } + + if len(controlCluster.Name) > 0 { + if !controlCluster.Spec.ClusterTreeOptions.Enable || !controlCluster.Spec.ClusterLinkOptions.Enable { + controlCluster.Spec.ClusterTreeOptions.Enable = true + controlCluster.Spec.ClusterLinkOptions.Enable = true + controlCluster.Spec.ClusterLinkOptions.CNI = o.CNI + controlCluster.Spec.ClusterLinkOptions.DefaultNICName = o.DefaultNICName + switch o.NetworkType { + case utils.NetworkTypeGateway: + controlCluster.Spec.ClusterLinkOptions.NetworkType = v1alpha1.NetWorkTypeGateWay + case utils.NetworkTypeP2P: + controlCluster.Spec.ClusterLinkOptions.NetworkType = v1alpha1.NetworkTypeP2P + } + + switch o.IpFamily { + case utils.DefaultIPv4: + controlCluster.Spec.ClusterLinkOptions.IPFamily = v1alpha1.IPFamilyTypeIPV4 + case utils.DefaultIPv6: + controlCluster.Spec.ClusterLinkOptions.IPFamily = v1alpha1.IPFamilyTypeIPV6 + } + _, err = o.KosmosClient.KosmosV1alpha1().Clusters().Update(context.TODO(), controlCluster, metav1.UpdateOptions{}) + if err != nil { + klog.Infof("ControlCluster-All: ", controlCluster) + return fmt.Errorf("kosmosctl install clustertree run error, update control panel cluster failed: %s", err) + } + } + } + } + + return nil +} + func (o *CommandInstallOptions) runCoreDNS() error { klog.Info("Start creating kosmos-coredns...") namespace := &corev1.Namespace{} @@ -702,7 +793,7 @@ func (o *CommandInstallOptions) runCoreDNS() error { return fmt.Errorf("kosmosctl install coredns coreFile run error, configmap options failed: %v", err) } } - klog.Info("ConfigMap corefile has been created.") + klog.Infof("ConfigMap %s has been created.", coreFile.Name) customerHosts, err := util.GenerateConfigMap(manifest.CorednsCustomerHosts, manifest.ConfigmapReplace{ Namespace: o.Namespace, @@ -716,10 +807,10 @@ func (o *CommandInstallOptions) runCoreDNS() error { return fmt.Errorf("kosmosctl install coredns customerHosts run error, configmap options failed: %v", err) } } - klog.Info("ConfigMap customerHosts has been created.") + klog.Infof("ConfigMap %s has been created.", customerHosts.Name) klog.Info("Attempting to create coredns CRDs, coredns reuses clusterlink's cluster CRD") - crd, err := util.GenerateCustomResourceDefinition(manifest.ClusterlinkCluster, manifest.ClusterlinkReplace{ + crd, err := util.GenerateCustomResourceDefinition(manifest.Cluster, manifest.CRDReplace{ Namespace: o.Namespace, }) if err != nil { @@ -727,7 +818,9 @@ func (o *CommandInstallOptions) runCoreDNS() error { } _, err = o.K8sExtensionsClient.ApiextensionsV1().CustomResourceDefinitions().Create(context.Background(), crd, metav1.CreateOptions{}) if err != nil { - if !apierrors.IsAlreadyExists(err) { + if apierrors.IsAlreadyExists(err) { + klog.Warningf("CRD %v is existed, creation process will skip", crd.Name) + } else { return fmt.Errorf("kosmosctl install coredns run error, crd options failed: %v", err) } } diff --git a/pkg/kosmosctl/join/join.go b/pkg/kosmosctl/join/join.go index c1e68ad87..051aea1a1 100644 --- a/pkg/kosmosctl/join/join.go +++ b/pkg/kosmosctl/join/join.go @@ -198,15 +198,22 @@ func (o *CommandJoinOptions) runCluster() error { Name: o.Name, }, Spec: v1alpha1.ClusterSpec{ - ImageRepository: o.ImageRegistry, Kubeconfig: o.KubeConfigStream, Namespace: o.Namespace, + ImageRepository: o.ImageRegistry, + ClusterLinkOptions: v1alpha1.ClusterLinkOptions{ + Enable: o.EnableLink, + NetworkType: v1alpha1.NetWorkTypeGateWay, + IPFamily: v1alpha1.IPFamilyTypeIPV4, + CNI: o.CNI, + DefaultNICName: o.DefaultNICName, + }, + ClusterTreeOptions: v1alpha1.ClusterTreeOptions{ + Enable: o.EnableTree, + }, }, } - cluster.Spec.ClusterLinkOptions.Enable = o.EnableLink - cluster.Spec.ClusterTreeOptions.Enable = o.EnableTree - if o.EnableLink { switch o.NetworkType { case utils.NetworkTypeGateway: @@ -221,16 +228,13 @@ func (o *CommandJoinOptions) runCluster() error { case utils.DefaultIPv6: cluster.Spec.ClusterLinkOptions.IPFamily = v1alpha1.IPFamilyTypeIPV6 } - - cluster.Spec.ClusterLinkOptions.CNI = o.CNI - cluster.Spec.ClusterLinkOptions.DefaultNICName = o.DefaultNICName } // ToDo if enable ClusterTree - if o.RootFlag { - cluster.Annotations[utils.RootClusterAnnotationKey] = utils.RootClusterAnnotationValue - } + //if o.RootFlag { + // cluster.Annotations[utils.RootClusterAnnotationKey] = utils.RootClusterAnnotationValue + //} _, err := o.KosmosClient.KosmosV1alpha1().Clusters().Create(context.TODO(), &cluster, metav1.CreateOptions{}) if err != nil { diff --git a/pkg/kosmosctl/manifest/manifest_crds.go b/pkg/kosmosctl/manifest/manifest_crds.go index 75035d74d..20314e586 100644 --- a/pkg/kosmosctl/manifest/manifest_crds.go +++ b/pkg/kosmosctl/manifest/manifest_crds.go @@ -1,481 +1,6 @@ package manifest -type ClusterlinkReplace struct { - Namespace string -} - const ( - ClusterlinkClusterNode = `--- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.11.0 - creationTimestamp: null - name: clusternodes.kosmos.io -spec: - group: kosmos.io - names: - kind: ClusterNode - listKind: ClusterNodeList - plural: clusternodes - singular: clusternode - scope: Cluster - versions: - - additionalPrinterColumns: - - jsonPath: .spec.roles - name: ROLES - type: string - - jsonPath: .spec.interfaceName - name: INTERFACE - type: string - - jsonPath: .spec.ip - name: IP - type: string - name: v1alpha1 - schema: - openAPIV3Schema: - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - properties: - clusterName: - type: string - interfaceName: - type: string - ip: - type: string - ip6: - type: string - nodeName: - type: string - podCIDRs: - items: - type: string - type: array - roles: - items: - type: string - type: array - type: object - status: - type: object - required: - - spec - type: object - served: true - storage: true - subresources: - status: {} -` - - ClusterlinkCluster = `--- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.11.0 - creationTimestamp: null - name: clusters.kosmos.io -spec: - group: kosmos.io - names: - kind: Cluster - listKind: ClusterList - plural: clusters - singular: cluster - scope: Cluster - versions: - - additionalPrinterColumns: - - jsonPath: .spec.networkType - name: NETWORK_TYPE - type: string - - jsonPath: .spec.ipFamily - name: IP_FAMILY - type: string - name: v1alpha1 - schema: - openAPIV3Schema: - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: Spec is the specification for the behaviour of the cluster. - properties: - 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 - globalCIDRsMap: - additionalProperties: - type: string - 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: {{ .Namespace }} - type: string - 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 - status: - description: Status describes the current status of a cluster. - properties: - podCIDRs: - items: - type: string - type: array - serviceCIDRs: - items: - type: string - type: array - type: object - required: - - spec - type: object - served: true - storage: true - subresources: {} -` - - ClusterlinkNodeConfig = `--- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.11.0 - creationTimestamp: null - name: nodeconfigs.kosmos.io -spec: - group: kosmos.io - names: - kind: NodeConfig - listKind: NodeConfigList - plural: nodeconfigs - singular: nodeconfig - scope: Cluster - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - properties: - arps: - items: - properties: - dev: - type: string - ip: - type: string - mac: - type: string - required: - - dev - - ip - - mac - type: object - type: array - devices: - items: - properties: - addr: - type: string - bindDev: - type: string - id: - format: int32 - type: integer - mac: - type: string - name: - type: string - port: - format: int32 - type: integer - type: - type: string - required: - - addr - - bindDev - - id - - mac - - name - - port - - type - type: object - type: array - fdbs: - items: - properties: - dev: - type: string - ip: - type: string - mac: - type: string - required: - - dev - - ip - - mac - type: object - type: array - iptables: - items: - properties: - chain: - type: string - rule: - type: string - table: - type: string - required: - - chain - - rule - - table - type: object - type: array - routes: - items: - properties: - cidr: - type: string - dev: - type: string - gw: - type: string - required: - - cidr - - dev - - gw - type: object - type: array - type: object - status: - properties: - lastChangeTime: - format: date-time - type: string - lastSyncTime: - format: date-time - type: string - type: object - required: - - spec - type: object - served: true - storage: true - subresources: - status: {} -` - - ClusterTreeKnode = `--- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.11.0 - creationTimestamp: null - name: knodes.kosmos.io -spec: - group: kosmos.io - names: - kind: Knode - listKind: KnodeList - plural: knodes - singular: knode - scope: Cluster - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - properties: - disableTaint: - type: boolean - kubeconfig: - format: byte - type: string - nodeName: - type: string - type: - default: k8s - type: string - type: object - status: - properties: - apiserver: - type: string - conditions: - items: - description: "Condition contains details for one aspect of the current - state of this API Resource. --- This struct is intended for direct - use as an array at the field path .status.conditions." - properties: - lastTransitionTime: - description: lastTransitionTime is the last time the condition - transitioned from one status to another. This should be when - the underlying condition changed. If that is not known, then - using the time when the API field changed is acceptable. - format: date-time - type: string - message: - description: message is a human readable message indicating - details about the transition. This may be an empty string. - maxLength: 32768 - type: string - observedGeneration: - description: observedGeneration represents the .metadata.generation - that the condition was set based upon. For instance, if .metadata.generation - is currently 12, but the .status.conditions[x].observedGeneration - is 9, the condition is out of date with respect to the current - state of the instance. - format: int64 - minimum: 0 - type: integer - reason: - description: reason contains a programmatic identifier indicating - the reason for the condition's last transition. Producers - of specific condition types may define expected values and - meanings for this field, and whether the values are considered - a guaranteed API. The value should be a CamelCase string. - This field may not be empty. - maxLength: 1024 - minLength: 1 - pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$ - type: string - status: - description: status of the condition, one of True, False, Unknown. - enum: - - "True" - - "False" - - Unknown - type: string - type: - description: type of condition in CamelCase or in foo.example.com/CamelCase. - --- Many .condition.type values are consistent across resources - like Available, but because arbitrary conditions can be useful - (see .node.status.conditions), the ability to deconflict is - important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt) - maxLength: 316 - pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ - type: string - required: - - lastTransitionTime - - message - - reason - - status - - type - type: object - type: array - version: - type: string - type: object - type: object - served: true - storage: true -` ServiceImport = `# Copyright 2020 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -638,6 +163,7 @@ spec: - cluster x-kubernetes-list-type: map ` + ServiceExport = `# Copyright 2020 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -848,6 +374,7 @@ spec: subresources: status: {} ` + const Cluster = `--- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition @@ -964,6 +491,105 @@ spec: enable: default: true type: boolean + leafModel: + description: LeafModel provide an api to arrange the member cluster + with some rules to pretend one or more leaf node + items: + properties: + labelSelector: + description: LabelSelector is a filter to select member + cluster nodes to pretend a leaf node in clusterTree by + labels. If nil or empty, the hole member cluster nodes + will pretend one leaf node. + properties: + matchExpressions: + description: matchExpressions is a list of label selector + requirements. The requirements are ANDed. + items: + description: A label selector requirement is a selector + that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that the selector + applies to. + type: string + operator: + description: operator represents a key's relationship + to a set of values. Valid operators are In, + NotIn, Exists and DoesNotExist. + type: string + values: + description: values is an array of string values. + If the operator is In or NotIn, the values array + must be non-empty. If the operator is Exists + or DoesNotExist, the values array must be empty. + This array is replaced during a strategic merge + patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: matchLabels is a map of {key,value} pairs. + A single {key,value} in the matchLabels map is equivalent + to an element of matchExpressions, whose key field + is "key", the operator is "In", and the values array + contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + labels: + additionalProperties: + type: string + description: Labels that will be setting in the pretended + Node labels + type: object + leafNodeName: + description: LeafNodeName defines leaf name If nil or empty, + the leaf node name will generate by controller and fill + in cluster link status + type: string + taints: + description: Taints attached to the leaf pretended Node. + If nil or empty, controller will set the default no-schedule + taint + items: + description: The node this Taint is attached to has the + "effect" on any pod that does not tolerate the Taint. + properties: + effect: + description: Required. The effect of the taint on + pods that do not tolerate the taint. Valid effects + are NoSchedule, PreferNoSchedule and NoExecute. + type: string + key: + description: Required. The taint key to be applied + to a node. + type: string + timeAdded: + description: TimeAdded represents the time at which + the taint was added. It is only written for NoExecute + taints. + format: date-time + type: string + value: + description: The taint value corresponding to the + taint key. + type: string + required: + - effect + - key + type: object + type: array + type: object + type: array type: object imageRepository: type: string @@ -978,6 +604,7 @@ spec: description: Status describes the current status of a cluster. properties: clusterLinkStatus: + description: ClusterLinkStatus contain the cluster network information properties: podCIDRs: items: @@ -988,6 +615,25 @@ spec: type: string type: array type: object + clusterTreeStatus: + description: ClusterTreeStatus contain the member cluster leafNode + end status + properties: + leafNodeItems: + description: LeafNodeItems represents list of the leaf node Items + calculating in each member cluster. + items: + properties: + leafNodeName: + description: LeafNodeName represents the leaf node name + generate by controller. suggest name format like cluster-shortLabel-number + like member-az1-1 + type: string + required: + - leafNodeName + type: object + type: array + type: object type: object required: - spec @@ -996,6 +642,7 @@ spec: storage: true subresources: {} ` + const NodeConfig = `--- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition @@ -1138,6 +785,7 @@ spec: subresources: status: {} ` + const DaemonSet = `--- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition @@ -1445,6 +1093,7 @@ spec: subresources: status: {} ` + const ShadowDaemonSet = `--- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition @@ -1755,3 +1404,7 @@ spec: subresources: status: {} ` + +type CRDReplace struct { + Namespace string +} diff --git a/pkg/kosmosctl/uninstall/uninstall.go b/pkg/kosmosctl/uninstall/uninstall.go index 437edbec8..b8a6cedc9 100644 --- a/pkg/kosmosctl/uninstall/uninstall.go +++ b/pkg/kosmosctl/uninstall/uninstall.go @@ -186,7 +186,7 @@ func (o *CommandUninstallOptions) runClusterlink() error { } else if clusters != nil && len(clusters.Items) > 0 { klog.Info("kosmosctl uninstall warning, skip removing cluster crd because cr instance exists") } else { - clusterCRD, err := util.GenerateCustomResourceDefinition(manifest.ClusterlinkCluster, nil) + clusterCRD, err := util.GenerateCustomResourceDefinition(manifest.Cluster, nil) if err != nil { return err } @@ -205,7 +205,7 @@ func (o *CommandUninstallOptions) runClusterlink() error { } else if clusternodes != nil && len(clusternodes.Items) > 0 { klog.Info("kosmosctl uninstall warning, skip removing clusternode crd because cr instance exists") } else { - clusternodeCRD, err := util.GenerateCustomResourceDefinition(manifest.ClusterlinkClusterNode, nil) + clusternodeCRD, err := util.GenerateCustomResourceDefinition(manifest.ClusterNode, nil) if err != nil { return err } @@ -224,7 +224,7 @@ func (o *CommandUninstallOptions) runClusterlink() error { } else if nodeconfigs != nil && len(nodeconfigs.Items) > 0 { klog.Info("kosmosctl uninstall warning, skip removing nodeconfig crd because cr instance exists") } else { - nodeConfigCRD, err := util.GenerateCustomResourceDefinition(manifest.ClusterlinkNodeConfig, nil) + nodeConfigCRD, err := util.GenerateCustomResourceDefinition(manifest.NodeConfig, nil) if err != nil { return err } @@ -329,7 +329,7 @@ func (o *CommandUninstallOptions) runClustertree() error { } else if clusters != nil && len(clusters.Items) > 0 { klog.Info("kosmosctl uninstall warning, skip removing cluster crd because cr instance exists") } else { - clusterCRD, err := util.GenerateCustomResourceDefinition(manifest.ClusterlinkCluster, nil) + clusterCRD, err := util.GenerateCustomResourceDefinition(manifest.Cluster, nil) if err != nil { return err } @@ -466,7 +466,7 @@ func (o *CommandUninstallOptions) runCoredns() error { } else if len(clusters.Items) > 0 { klog.Info("kosmosctl uninstall warning, skip removing cluster crd because cr instance exists") } else { - clusterCRD, _ := util.GenerateCustomResourceDefinition(manifest.ClusterlinkCluster, nil) + clusterCRD, _ := util.GenerateCustomResourceDefinition(manifest.Cluster, nil) if err != nil { return err } diff --git a/pkg/operator/operator_controller.go b/pkg/operator/operator_controller.go index a5b773875..7d6364378 100644 --- a/pkg/operator/operator_controller.go +++ b/pkg/operator/operator_controller.go @@ -130,12 +130,12 @@ func (r *Reconciler) removeFinalizer(cluster *v1alpha1.Cluster) (reconcile.Resul // Reconcile is for controller reconcile func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { - klog.Infof("Reconciling cluster %s, operator cluster name %s", request.NamespacedName.Name, r.ClusterName) + klog.Infof("Reconciling cluster %s", request.NamespacedName.Name) - if request.NamespacedName.Name != r.ClusterName { - klog.Infof("Skip this event") - return reconcile.Result{}, nil - } + //if request.NamespacedName.Name != r.ClusterName { + // klog.Infof("Skip this event") + // return reconcile.Result{}, nil + //} cluster := &v1alpha1.Cluster{} diff --git a/pkg/utils/constants.go b/pkg/utils/constants.go index 5a4b6ddb6..70a7ef788 100644 --- a/pkg/utils/constants.go +++ b/pkg/utils/constants.go @@ -9,7 +9,7 @@ import ( const ( DefaultNamespace = "kosmos-system" - DefaultClusterName = "kosmos-cluster" + DefaultClusterName = "kosmos-control-cluster" DefaultImageRepository = "ghcr.io/kosmos-io" DefaultWaitTime = 120 RootClusterAnnotationKey = "kosmos.io/cluster-role"