From ea259db913552fd3a124aaa642615a8d1c4a0717 Mon Sep 17 00:00:00 2001 From: pixiake Date: Thu, 26 Dec 2024 19:18:28 +0800 Subject: [PATCH] support only etcd Signed-off-by: pixiake --- cmd/kk/cmd/create/cluster.go | 3 + cmd/kk/pkg/common/kube_runtime.go | 1 + cmd/kk/pkg/pipelines/create_cluster.go | 107 +++++++++++++++---------- 3 files changed, 70 insertions(+), 41 deletions(-) diff --git a/cmd/kk/cmd/create/cluster.go b/cmd/kk/cmd/create/cluster.go index 3ca16ec03..c1d101656 100644 --- a/cmd/kk/cmd/create/cluster.go +++ b/cmd/kk/cmd/create/cluster.go @@ -45,6 +45,7 @@ type CreateClusterOptions struct { DownloadCmd string Artifact string InstallPackages bool + OnlyEtcd bool localStorageChanged bool } @@ -122,6 +123,7 @@ func (o *CreateClusterOptions) Run() error { Artifact: o.Artifact, InstallPackages: o.InstallPackages, Namespace: o.CommonOptions.Namespace, + OnlyEtcd: o.OnlyEtcd, } if o.localStorageChanged { @@ -145,6 +147,7 @@ func (o *CreateClusterOptions) AddFlags(cmd *cobra.Command) { `The user defined command to download the necessary binary files. The first param '%s' is output path, the second param '%s', is the URL`) cmd.Flags().StringVarP(&o.Artifact, "artifact", "a", "", "Path to a KubeKey artifact") cmd.Flags().BoolVarP(&o.InstallPackages, "with-packages", "", false, "install operation system packages by artifact") + cmd.Flags().BoolVarP(&o.OnlyEtcd, "only-etcd", "", false, "create etcd cluster only") } func completionSetting(cmd *cobra.Command) (err error) { diff --git a/cmd/kk/pkg/common/kube_runtime.go b/cmd/kk/pkg/common/kube_runtime.go index e983fe735..db0899a53 100644 --- a/cmd/kk/pkg/common/kube_runtime.go +++ b/cmd/kk/pkg/common/kube_runtime.go @@ -54,6 +54,7 @@ type Argument struct { DeleteCRI bool Role string Type string + OnlyEtcd bool } func NewKubeRuntime(flag string, arg Argument) (*KubeRuntime, error) { diff --git a/cmd/kk/pkg/pipelines/create_cluster.go b/cmd/kk/pkg/pipelines/create_cluster.go index 4f5935f6c..336fa38ef 100644 --- a/cmd/kk/pkg/pipelines/create_cluster.go +++ b/cmd/kk/pkg/pipelines/create_cluster.go @@ -56,47 +56,72 @@ func NewCreateClusterPipeline(runtime *common.KubeRuntime) error { skipLocalStorage = false } - m := []module.Module{ - &precheck.GreetingsModule{}, - &customscripts.CustomScriptsModule{Phase: "PreInstall", Scripts: runtime.Cluster.System.PreInstall}, - &precheck.NodePreCheckModule{}, - &confirm.InstallConfirmModule{}, - &artifact.UnArchiveModule{Skip: noArtifact}, - &os.RepositoryModule{Skip: noArtifact || !runtime.Arg.InstallPackages}, - &binaries.NodeBinariesModule{}, - &os.ConfigureOSModule{Skip: runtime.Cluster.System.SkipConfigureOS}, - &kubernetes.StatusModule{}, - &container.InstallContainerModule{}, - &container.InstallCriDockerdModule{Skip: runtime.Cluster.Kubernetes.ContainerManager != "docker"}, - &images.CopyImagesToRegistryModule{Skip: skipPushImages}, - &images.PullModule{Skip: runtime.Arg.SkipPullImages}, - &etcd.PreCheckModule{Skip: runtime.Cluster.Etcd.Type != kubekeyapiv1alpha2.KubeKey}, - &etcd.CertsModule{}, - &etcd.InstallETCDBinaryModule{Skip: runtime.Cluster.Etcd.Type != kubekeyapiv1alpha2.KubeKey}, - &etcd.ConfigureModule{Skip: runtime.Cluster.Etcd.Type != kubekeyapiv1alpha2.KubeKey}, - &etcd.BackupModule{Skip: runtime.Cluster.Etcd.Type != kubekeyapiv1alpha2.KubeKey}, - &kubernetes.InstallKubeBinariesModule{}, - // init kubeVip on first master - &loadbalancer.KubevipModule{Skip: !runtime.Cluster.ControlPlaneEndpoint.IsInternalLBEnabledVip()}, - &kubernetes.InitKubernetesModule{}, - &dns.ClusterDNSModule{}, - &kubernetes.StatusModule{}, - &kubernetes.JoinNodesModule{}, - // deploy kubeVip on other masters - &loadbalancer.KubevipModule{Skip: !runtime.Cluster.ControlPlaneEndpoint.IsInternalLBEnabledVip()}, - &loadbalancer.HaproxyModule{Skip: !runtime.Cluster.ControlPlaneEndpoint.IsInternalLBEnabled()}, - &network.DeployNetworkPluginModule{}, - &kubernetes.ConfigureKubernetesModule{}, - &filesystem.ChownModule{}, - &certs.AutoRenewCertsModule{Skip: !runtime.Cluster.Kubernetes.EnableAutoRenewCerts()}, - &kubernetes.SecurityEnhancementModule{Skip: !runtime.Arg.SecurityEnhancement}, - &kubernetes.SaveKubeConfigModule{}, - &plugins.DeployPluginsModule{}, - &addons.AddonsModule{}, - &storage.DeployLocalVolumeModule{Skip: skipLocalStorage}, - &kubesphere.DeployModule{Skip: !runtime.Cluster.KubeSphere.Enabled}, - &kubesphere.CheckResultModule{Skip: !runtime.Cluster.KubeSphere.Enabled}, - &customscripts.CustomScriptsModule{Phase: "PostInstall", Scripts: runtime.Cluster.System.PostInstall}, + m := []module.Module{} + + if runtime.Arg.OnlyEtcd { + m = []module.Module{ + &precheck.GreetingsModule{}, + &customscripts.CustomScriptsModule{Phase: "PreInstall", Scripts: runtime.Cluster.System.PreInstall}, + &precheck.NodePreCheckModule{}, + &confirm.InstallConfirmModule{}, + &artifact.UnArchiveModule{Skip: noArtifact}, + &os.RepositoryModule{Skip: noArtifact || !runtime.Arg.InstallPackages}, + &binaries.NodeBinariesModule{}, + &os.ConfigureOSModule{Skip: runtime.Cluster.System.SkipConfigureOS}, + &kubernetes.StatusModule{}, + &container.InstallContainerModule{}, + &container.InstallCriDockerdModule{Skip: runtime.Cluster.Kubernetes.ContainerManager != "docker"}, + &images.CopyImagesToRegistryModule{Skip: skipPushImages}, + &images.PullModule{Skip: runtime.Arg.SkipPullImages}, + &etcd.PreCheckModule{Skip: runtime.Cluster.Etcd.Type != kubekeyapiv1alpha2.KubeKey}, + &etcd.CertsModule{}, + &etcd.InstallETCDBinaryModule{Skip: runtime.Cluster.Etcd.Type != kubekeyapiv1alpha2.KubeKey}, + &etcd.ConfigureModule{Skip: runtime.Cluster.Etcd.Type != kubekeyapiv1alpha2.KubeKey}, + &etcd.BackupModule{Skip: runtime.Cluster.Etcd.Type != kubekeyapiv1alpha2.KubeKey}, + } + } else { + m = []module.Module{ + &precheck.GreetingsModule{}, + &customscripts.CustomScriptsModule{Phase: "PreInstall", Scripts: runtime.Cluster.System.PreInstall}, + &precheck.NodePreCheckModule{}, + &confirm.InstallConfirmModule{}, + &artifact.UnArchiveModule{Skip: noArtifact}, + &os.RepositoryModule{Skip: noArtifact || !runtime.Arg.InstallPackages}, + &binaries.NodeBinariesModule{}, + &os.ConfigureOSModule{Skip: runtime.Cluster.System.SkipConfigureOS}, + &kubernetes.StatusModule{}, + &container.InstallContainerModule{}, + &container.InstallCriDockerdModule{Skip: runtime.Cluster.Kubernetes.ContainerManager != "docker"}, + &images.CopyImagesToRegistryModule{Skip: skipPushImages}, + &images.PullModule{Skip: runtime.Arg.SkipPullImages}, + &etcd.PreCheckModule{Skip: runtime.Cluster.Etcd.Type != kubekeyapiv1alpha2.KubeKey}, + &etcd.CertsModule{}, + &etcd.InstallETCDBinaryModule{Skip: runtime.Cluster.Etcd.Type != kubekeyapiv1alpha2.KubeKey}, + &etcd.ConfigureModule{Skip: runtime.Cluster.Etcd.Type != kubekeyapiv1alpha2.KubeKey}, + &etcd.BackupModule{Skip: runtime.Cluster.Etcd.Type != kubekeyapiv1alpha2.KubeKey}, + &kubernetes.InstallKubeBinariesModule{}, + // init kubeVip on first master + &loadbalancer.KubevipModule{Skip: !runtime.Cluster.ControlPlaneEndpoint.IsInternalLBEnabledVip()}, + &kubernetes.InitKubernetesModule{}, + &dns.ClusterDNSModule{}, + &kubernetes.StatusModule{}, + &kubernetes.JoinNodesModule{}, + // deploy kubeVip on other masters + &loadbalancer.KubevipModule{Skip: !runtime.Cluster.ControlPlaneEndpoint.IsInternalLBEnabledVip()}, + &loadbalancer.HaproxyModule{Skip: !runtime.Cluster.ControlPlaneEndpoint.IsInternalLBEnabled()}, + &network.DeployNetworkPluginModule{}, + &kubernetes.ConfigureKubernetesModule{}, + &filesystem.ChownModule{}, + &certs.AutoRenewCertsModule{Skip: !runtime.Cluster.Kubernetes.EnableAutoRenewCerts()}, + &kubernetes.SecurityEnhancementModule{Skip: !runtime.Arg.SecurityEnhancement}, + &kubernetes.SaveKubeConfigModule{}, + &plugins.DeployPluginsModule{}, + &addons.AddonsModule{}, + &storage.DeployLocalVolumeModule{Skip: skipLocalStorage}, + &kubesphere.DeployModule{Skip: !runtime.Cluster.KubeSphere.Enabled}, + &kubesphere.CheckResultModule{Skip: !runtime.Cluster.KubeSphere.Enabled}, + &customscripts.CustomScriptsModule{Phase: "PostInstall", Scripts: runtime.Cluster.System.PostInstall}, + } } p := pipeline.Pipeline{