From 7c30c83a842b9d0a9fd57357d7e98b51f5f264aa Mon Sep 17 00:00:00 2001 From: ONE7live Date: Mon, 25 Sep 2023 17:50:27 +0800 Subject: [PATCH] feat: Kosmosctl supports knode-manager module install and uninstall Signed-off-by: ONE7live --- pkg/kosmosctl/install/install.go | 149 ++++++++++++++++-- pkg/kosmosctl/kosmosctl.go | 2 +- .../manifest/manifest_clusterrolebindings.go | 16 ++ .../manifest/manifest_clusterroles.go | 14 ++ pkg/kosmosctl/manifest/manifest_crds.go | 120 ++++++++++++++ .../manifest/manifest_deployments.go | 44 ++++++ .../manifest/manifest_serviceaccounts.go | 9 ++ pkg/kosmosctl/uninstall/uninstall.go | 124 +++++++-------- pkg/kosmosctl/util/builder.go | 3 +- 9 files changed, 406 insertions(+), 75 deletions(-) diff --git a/pkg/kosmosctl/install/install.go b/pkg/kosmosctl/install/install.go index 3f14d66f5..0cad041d6 100644 --- a/pkg/kosmosctl/install/install.go +++ b/pkg/kosmosctl/install/install.go @@ -3,6 +3,7 @@ package install import ( "context" "fmt" + "os" "github.com/spf13/cobra" corev1 "k8s.io/api/core/v1" @@ -20,9 +21,11 @@ import ( ) type CommandInstallOptions struct { - Namespace string - ImageRegistry string - Version string + Namespace string + ImageRegistry string + Version string + Module string + HostKubeConfig string Client kubernetes.Interface ExtensionsClient extensionsclient.Interface @@ -50,6 +53,8 @@ func NewCmdInstall(f ctlutil.Factory) *cobra.Command { flags := cmd.Flags() flags.StringVarP(&o.Namespace, "namespace", "n", util.DefaultNamespace, "Kosmos namespace.") flags.StringVarP(&o.ImageRegistry, "private-image-registry", "", util.DefaultImageRepository, "Private image registry where pull images from. If set, all required images will be downloaded from it, it would be useful in offline installation scenarios. In addition, you still can use --kube-image-registry to specify the registry for Kubernetes's images.") + flags.StringVarP(&o.Module, "module", "m", util.DefaultInstallModule, "Kosmos specify the module to install.") + flags.StringVar(&o.HostKubeConfig, "host-kubeconfig", "", "Absolute path to the host kubeconfig file.") return cmd } @@ -78,16 +83,46 @@ func (o *CommandInstallOptions) Validate() error { return fmt.Errorf("namespace must be specified") } + if o.Module != "clusterlink" && o.HostKubeConfig == "" { + return fmt.Errorf("host-kubeconfig must be specified") + } + return nil } func (o *CommandInstallOptions) Run() error { + switch o.Module { + case "clusterlink": + err := o.runClusterlink() + if err != nil { + return err + } + case "clusterrouter": + err := o.runClusterrouter() + if err != nil { + return err + } + case "all": + err := o.runClusterlink() + if err != nil { + return err + } + err = o.runClusterrouter() + if err != nil { + return err + } + } + + return nil +} + +func (o *CommandInstallOptions) runClusterlink() error { namespace := &corev1.Namespace{} namespace.Name = o.Namespace _, err := o.Client.CoreV1().Namespaces().Create(context.TODO(), namespace, metav1.CreateOptions{}) if err != nil { if !apierrors.IsAlreadyExists(err) { - return fmt.Errorf("kosmosctl install run error, namespace options failed: %v", err) + return fmt.Errorf("kosmosctl install clusterlink run error, namespace options failed: %v", err) } } @@ -100,7 +135,7 @@ func (o *CommandInstallOptions) Run() error { _, err = o.Client.CoreV1().ServiceAccounts(o.Namespace).Create(context.TODO(), clusterlinkServiceAccount, metav1.CreateOptions{}) if err != nil { if !apierrors.IsAlreadyExists(err) { - return fmt.Errorf("kosmosctl install run error, serviceaccount options failed: %v", err) + return fmt.Errorf("kosmosctl install clusterlink run error, serviceaccount options failed: %v", err) } } @@ -111,7 +146,7 @@ func (o *CommandInstallOptions) Run() error { _, err = o.Client.RbacV1().ClusterRoles().Create(context.TODO(), clusterlinkClusterRole, metav1.CreateOptions{}) if err != nil { if !apierrors.IsAlreadyExists(err) { - return fmt.Errorf("kosmosctl install run error, clusterrole options failed: %v", err) + return fmt.Errorf("kosmosctl install clusterlink run error, clusterrole options failed: %v", err) } } @@ -124,7 +159,7 @@ func (o *CommandInstallOptions) Run() error { _, err = o.Client.RbacV1().ClusterRoleBindings().Create(context.TODO(), clusterlinkClusterRoleBinding, metav1.CreateOptions{}) if err != nil { if !apierrors.IsAlreadyExists(err) { - return fmt.Errorf("kosmosctl install run error, clusterrolebinding options failed: %v", err) + return fmt.Errorf("kosmosctl install clusterlink run error, clusterrolebinding options failed: %v", err) } } @@ -147,7 +182,7 @@ func (o *CommandInstallOptions) Run() error { _, err = o.ExtensionsClient.ApiextensionsV1().CustomResourceDefinitions().Create(context.Background(), &crds.Items[i], metav1.CreateOptions{}) if err != nil { if !apierrors.IsAlreadyExists(err) { - return fmt.Errorf("kosmosctl install run error, crd options failed: %v", err) + return fmt.Errorf("kosmosctl install clusterlink run error, crd options failed: %v", err) } } } @@ -163,7 +198,103 @@ func (o *CommandInstallOptions) Run() error { _, err = o.Client.AppsV1().Deployments(o.Namespace).Create(context.Background(), deployment, metav1.CreateOptions{}) if err != nil { if !apierrors.IsAlreadyExists(err) { - return fmt.Errorf("kosmosctl install run error, deployment options failed: %v", err) + return fmt.Errorf("kosmosctl install clusterlink run error, deployment options failed: %v", err) + } + } + + return nil +} + +func (o *CommandInstallOptions) runClusterrouter() error { + namespace := &corev1.Namespace{} + namespace.Name = o.Namespace + _, err := o.Client.CoreV1().Namespaces().Create(context.TODO(), namespace, metav1.CreateOptions{}) + if err != nil { + if !apierrors.IsAlreadyExists(err) { + return fmt.Errorf("kosmosctl install clusterrouter run error, namespace options failed: %v", err) + } + } + + hostKubeconfig, err := os.ReadFile(o.HostKubeConfig) + if err != nil { + return fmt.Errorf("kosmosctl install clusterrouter run error, host-kubeconfig read failed: %v", err) + } + clusterRouterConfigMap := &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: "host-kubeconfig", + Namespace: o.Namespace, + }, + Data: map[string]string{ + "kubeconfig": string(hostKubeconfig), + }, + } + _, err = o.Client.CoreV1().ConfigMaps(o.Namespace).Create(context.TODO(), clusterRouterConfigMap, metav1.CreateOptions{}) + if err != nil { + if !apierrors.IsAlreadyExists(err) { + return fmt.Errorf("kosmosctl install clusterrouter run error, configmap options failed: %v", err) + } + } + + clusterRouterServiceAccount, err := util.GenerateServiceAccount(manifest.ClusterRouterKnodeServiceAccount, manifest.ServiceAccountReplace{ + Namespace: o.Namespace, + }) + if err != nil { + return err + } + _, err = o.Client.CoreV1().ServiceAccounts(o.Namespace).Create(context.TODO(), clusterRouterServiceAccount, metav1.CreateOptions{}) + if err != nil { + if !apierrors.IsAlreadyExists(err) { + return fmt.Errorf("kosmosctl install clusterrouter run error, serviceaccount options failed: %v", err) + } + } + + clusterRouterClusterRole, err := util.GenerateClusterRole(manifest.ClusterRouterKnodeClusterRole, nil) + if err != nil { + return err + } + _, err = o.Client.RbacV1().ClusterRoles().Create(context.TODO(), clusterRouterClusterRole, metav1.CreateOptions{}) + if err != nil { + if !apierrors.IsAlreadyExists(err) { + return fmt.Errorf("kosmosctl install clusterrouter run error, clusterrole options failed: %v", err) + } + } + + clusterRouterClusterRoleBinding, err := util.GenerateClusterRoleBinding(manifest.ClusterRouterKnodeClusterRoleBinding, manifest.ClusterRoleBindingReplace{ + Namespace: o.Namespace, + }) + if err != nil { + return err + } + _, err = o.Client.RbacV1().ClusterRoleBindings().Create(context.TODO(), clusterRouterClusterRoleBinding, metav1.CreateOptions{}) + if err != nil { + if !apierrors.IsAlreadyExists(err) { + return fmt.Errorf("kosmosctl install clusterrouter run error, clusterrolebinding options failed: %v", err) + } + } + + clusterRouterKnode, err := util.GenerateCustomResourceDefinition(manifest.ClusterRouterKnode, nil) + if err != nil { + return err + } + _, err = o.ExtensionsClient.ApiextensionsV1().CustomResourceDefinitions().Create(context.Background(), clusterRouterKnode, metav1.CreateOptions{}) + if err != nil { + if !apierrors.IsAlreadyExists(err) { + return fmt.Errorf("kosmosctl install clusterrouter run error, crd options failed: %v", err) + } + } + + deployment, err := util.GenerateDeployment(manifest.ClusterRouterKnodeDeployment, manifest.DeploymentReplace{ + Namespace: o.Namespace, + ImageRepository: o.ImageRegistry, + Version: version.GetReleaseVersion().PatchRelease(), + }) + if err != nil { + return err + } + _, err = o.Client.AppsV1().Deployments(o.Namespace).Create(context.Background(), deployment, metav1.CreateOptions{}) + if err != nil { + if !apierrors.IsAlreadyExists(err) { + return fmt.Errorf("kosmosctl install clusterrouter run error, deployment options failed: %v", err) } } diff --git a/pkg/kosmosctl/kosmosctl.go b/pkg/kosmosctl/kosmosctl.go index 84ba910c5..df2c84dbd 100644 --- a/pkg/kosmosctl/kosmosctl.go +++ b/pkg/kosmosctl/kosmosctl.go @@ -57,7 +57,7 @@ func NewKosmosCtlCommand() *cobra.Command { Message: "Install/UnInstall Commands:", Commands: []*cobra.Command{ install.NewCmdInstall(f), - uninstall.NewCmdUninstall(f, ioStreams), + uninstall.NewCmdUninstall(f), }, }, { diff --git a/pkg/kosmosctl/manifest/manifest_clusterrolebindings.go b/pkg/kosmosctl/manifest/manifest_clusterrolebindings.go index 1ccc24727..201e29e19 100644 --- a/pkg/kosmosctl/manifest/manifest_clusterrolebindings.go +++ b/pkg/kosmosctl/manifest/manifest_clusterrolebindings.go @@ -47,6 +47,22 @@ subjects: name: clusterlink-operator namespace: clusterlink-system ` + + ClusterRouterKnodeClusterRoleBinding = ` +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: clusterrouter-knode +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: clusterrouter-knode +subjects: + - kind: ServiceAccount + name: clusterrouter-knode + namespace: {{ .Namespace }} +` ) type ClusterRoleBindingReplace struct { diff --git a/pkg/kosmosctl/manifest/manifest_clusterroles.go b/pkg/kosmosctl/manifest/manifest_clusterroles.go index 76a86183c..886058b5c 100644 --- a/pkg/kosmosctl/manifest/manifest_clusterroles.go +++ b/pkg/kosmosctl/manifest/manifest_clusterroles.go @@ -39,4 +39,18 @@ rules: - nonResourceURLs: ['*'] verbs: ["get"] ` + + ClusterRouterKnodeClusterRole = ` +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: clusterrouter-knode +rules: + - apiGroups: ['*'] + resources: ['*'] + verbs: ["*"] + - nonResourceURLs: ['*'] + verbs: ["get"] +` ) diff --git a/pkg/kosmosctl/manifest/manifest_crds.go b/pkg/kosmosctl/manifest/manifest_crds.go index a82c1e37a..169c1e5f4 100644 --- a/pkg/kosmosctl/manifest/manifest_crds.go +++ b/pkg/kosmosctl/manifest/manifest_crds.go @@ -352,4 +352,124 @@ spec: subresources: status: {} ` + + ClusterRouterKnode = `--- +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 +` ) diff --git a/pkg/kosmosctl/manifest/manifest_deployments.go b/pkg/kosmosctl/manifest/manifest_deployments.go index 947f806f3..d32e56b10 100644 --- a/pkg/kosmosctl/manifest/manifest_deployments.go +++ b/pkg/kosmosctl/manifest/manifest_deployments.go @@ -35,6 +35,7 @@ spec: cpu: 500m memory: 500Mi ` + ClusterlinkDeployment = ` apiVersion: apps/v1 kind: Deployment @@ -96,6 +97,49 @@ spec: secret: secretName: controlpanel-config +` + + ClusterRouterKnodeDeployment = `--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: knode + namespace: {{ .Namespace }} + labels: + app: clusterrouter-controller-manager +spec: + replicas: 1 + selector: + matchLabels: + app: knode + template: + metadata: + labels: + app: knode + spec: + serviceAccountName: clusterrouter-knode + containers: + - name: manager + image: {{ .ImageRepository }}/knode:v{{ .Version }} + imagePullPolicy: Always + command: + - /clusterrouter + - --kube-api-qps=500 + - --kube-api-burst=1000 + - --kubeconfig=/etc/kube/config + - --leader-elect=false + volumeMounts: + - mountPath: /etc/kube + name: config-volume + readOnly: true + volumes: + - configMap: + defaultMode: 420 + items: + - key: Kubeconfig + path: Kubeconfig + name: host-kubeconfig + name: config-volume ` ) diff --git a/pkg/kosmosctl/manifest/manifest_serviceaccounts.go b/pkg/kosmosctl/manifest/manifest_serviceaccounts.go index 771bc1e14..b24dbe39c 100644 --- a/pkg/kosmosctl/manifest/manifest_serviceaccounts.go +++ b/pkg/kosmosctl/manifest/manifest_serviceaccounts.go @@ -16,6 +16,7 @@ metadata: name: clusterlink-floater namespace: {{ .Namespace }} ` + ClusterlinkServiceAccount = ` apiVersion: v1 kind: ServiceAccount @@ -23,6 +24,14 @@ metadata: name: clusterlink-operator namespace: clusterlink-system ` + + ClusterRouterKnodeServiceAccount = ` +apiVersion: v1 +kind: ServiceAccount +metadata: + name: clusterrouter-knode + namespace: {{ .Namespace }} +` ) type ServiceAccountReplace struct { diff --git a/pkg/kosmosctl/uninstall/uninstall.go b/pkg/kosmosctl/uninstall/uninstall.go index e67542b46..9465c741c 100644 --- a/pkg/kosmosctl/uninstall/uninstall.go +++ b/pkg/kosmosctl/uninstall/uninstall.go @@ -5,34 +5,30 @@ import ( "fmt" "github.com/spf13/cobra" - extensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" - apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/cli-runtime/pkg/genericclioptions" - coreclient "k8s.io/client-go/kubernetes/typed/core/v1" - ctldelete "k8s.io/kubectl/pkg/cmd/delete" + "k8s.io/client-go/kubernetes" ctlutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/util/i18n" + + "github.com/kosmos.io/kosmos/pkg/kosmosctl/util" ) const ( - clusterlinkSystem = "clusterlink-system" + clusterlinkNetworkManager = "clusterlink-network-manager" + clusterrouterKnode = "knode" + clusterrouterKnodeResource = "clusterrouter-knode" ) type CommandUninstallOptions struct { Namespace string + Module string - CoreClient *coreclient.CoreV1Client - ExtensionsClientSet extensionsclientset.Interface - - DelDeploymentOptions *ctldelete.DeleteOptions - DelServiceAccountOptions *ctldelete.DeleteOptions + Client kubernetes.Interface } // NewCmdUninstall Uninstall the Kosmos control plane in a Kubernetes cluster. -func NewCmdUninstall(f ctlutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { - o, err := NewCommandUninstallOptions(streams) - ctlutil.CheckErr(err) +func NewCmdUninstall(f ctlutil.Factory) *cobra.Command { + o := &CommandUninstallOptions{} cmd := &cobra.Command{ Use: "uninstall", @@ -42,56 +38,29 @@ func NewCmdUninstall(f ctlutil.Factory, streams genericclioptions.IOStreams) *co SilenceUsage: true, DisableFlagsInUseLine: true, RunE: func(cmd *cobra.Command, args []string) error { - ctlutil.CheckErr(o.Complete(f, cmd, args)) + ctlutil.CheckErr(o.Complete(f)) ctlutil.CheckErr(o.Validate()) - ctlutil.CheckErr(o.Run(f)) + ctlutil.CheckErr(o.Run()) return nil }, } - ctlutil.AddDryRunFlag(cmd) flags := cmd.Flags() - flags.StringVarP(&o.Namespace, "namespace", "n", clusterlinkSystem, "Kosmos namespace.") + flags.StringVarP(&o.Namespace, "namespace", "n", util.DefaultNamespace, "Kosmos namespace.") + flags.StringVarP(&o.Module, "module", "m", util.DefaultInstallModule, "Kosmos specify the module to uninstall.") return cmd } -// NewCommandUninstallOptions returns a CommandUninstallOptions. -func NewCommandUninstallOptions(streams genericclioptions.IOStreams) (*CommandUninstallOptions, error) { - delFlags := ctldelete.NewDeleteFlags("Contains resources for Kosmos to delete.") - delOptions, err := delFlags.ToOptions(nil, streams) - if err != nil { - return nil, fmt.Errorf("kosmosctl uninstall error, generate uninstall options failed: %s", err) - } - - return &CommandUninstallOptions{ - DelDeploymentOptions: delOptions, - DelServiceAccountOptions: delOptions, - }, nil -} - -func (o *CommandUninstallOptions) Complete(f ctlutil.Factory, cmd *cobra.Command, args []string) error { +func (o *CommandUninstallOptions) Complete(f ctlutil.Factory) error { config, err := f.ToRESTConfig() if err != nil { return fmt.Errorf("kosmosctl uninstall complete error, generate rest config failed: %v", err) } - coreClient, err := coreclient.NewForConfig(config) + o.Client, err = kubernetes.NewForConfig(config) if err != nil { - return fmt.Errorf("kosmosctl uninstall complete error, create core client failed: %v", err) - } - o.CoreClient = coreClient - - o.DelDeploymentOptions.FieldSelector = "metadata.namespace=" + o.Namespace - err = o.DelDeploymentOptions.Complete(f, []string{"deploy"}, cmd) - if err != nil { - return fmt.Errorf("kosmosctl uninstall complete error, deployment options failed: %v", err) - } - - o.DelServiceAccountOptions.FieldSelector = "metadata.name!=default,metadata.namespace=" + o.Namespace - err = o.DelServiceAccountOptions.Complete(f, []string{"sa"}, cmd) - if err != nil { - return fmt.Errorf("kosmosctl uninstall complete error, serviceaccount options failed: %v", err) + return fmt.Errorf("kosmosctl uninstall complete error, generate basic client failed: %v", err) } return nil @@ -102,35 +71,62 @@ func (o *CommandUninstallOptions) Validate() error { return fmt.Errorf("kosmosctl uninstall validate error, namespace must be specified") } - err := o.DelDeploymentOptions.Validate() - if err != nil { - return fmt.Errorf("kosmosctl uninstall validate error, deployment options failed: %v", err) - } + return nil +} - err = o.DelServiceAccountOptions.Validate() - if err != nil { - return fmt.Errorf("kosmosctl uninstall validate error, serviceaccount options failed: %v", err) +func (o *CommandUninstallOptions) Run() error { + switch o.Module { + case "clusterlink": + err := o.runClusterlink() + if err != nil { + return err + } + case "clusterrouter": + err := o.runClusterrouter() + if err != nil { + return err + } + case "all": + err := o.runClusterlink() + if err != nil { + return err + } + err = o.runClusterrouter() + if err != nil { + return err + } + err = o.Client.CoreV1().Namespaces().Delete(context.TODO(), o.Namespace, metav1.DeleteOptions{}) + if err != nil { + return fmt.Errorf("kosmosctl uninstall all module run error, namespace options failed: %v", err) + } } return nil } -func (o *CommandUninstallOptions) Run(f ctlutil.Factory) error { - err := o.DelDeploymentOptions.RunDelete(f) +func (o *CommandUninstallOptions) runClusterlink() error { + err := o.Client.AppsV1().Deployments(util.DefaultNamespace).Delete(context.TODO(), clusterlinkNetworkManager, metav1.DeleteOptions{}) if err != nil { - return fmt.Errorf("kosmosctl uninstall run error, deployment options failed: %v", err) + return fmt.Errorf("kosmosctl uninstall clusterlink run error, deployment options failed: %v", err) } - err = o.DelServiceAccountOptions.RunDelete(f) + err = o.Client.CoreV1().ServiceAccounts(util.DefaultNamespace).Delete(context.TODO(), clusterlinkNetworkManager, metav1.DeleteOptions{}) if err != nil { - return fmt.Errorf("kosmosctl uninstall run error, serviceaccount options failed: %v", err) + return fmt.Errorf("kosmosctl uninstall clusterlink run error, serviceaccount options failed: %v", err) } - err = o.CoreClient.Namespaces().Delete(context.TODO(), o.Namespace, metav1.DeleteOptions{}) + return nil +} + +func (o *CommandUninstallOptions) runClusterrouter() error { + err := o.Client.AppsV1().Deployments(util.DefaultNamespace).Delete(context.TODO(), clusterrouterKnode, metav1.DeleteOptions{}) if err != nil { - if !apierrors.IsAlreadyExists(err) { - return fmt.Errorf("kosmosctl uninstall run error, deployment options failed: %v", err) - } + return fmt.Errorf("kosmosctl uninstall clusterrouter run error, deployment options failed: %v", err) + } + + err = o.Client.CoreV1().ServiceAccounts(util.DefaultNamespace).Delete(context.TODO(), clusterrouterKnodeResource, metav1.DeleteOptions{}) + if err != nil { + return fmt.Errorf("kosmosctl uninstall clusterrouter run error, serviceaccount options failed: %v", err) } return nil diff --git a/pkg/kosmosctl/util/builder.go b/pkg/kosmosctl/util/builder.go index b9bd374e0..60b2c96ab 100644 --- a/pkg/kosmosctl/util/builder.go +++ b/pkg/kosmosctl/util/builder.go @@ -14,8 +14,9 @@ import ( ) const ( - DefaultNamespace = "clusterlink-system" + DefaultNamespace = "kosmos-system" DefaultImageRepository = "ghcr.io/kosmos-io" + DefaultInstallModule = "all" ) func GenerateDeployment(deployTemplate string, obj interface{}) (*appsv1.Deployment, error) {