diff --git a/cmd/kk/cmd/create/cluster.go b/cmd/kk/cmd/create/cluster.go index 3ba592c43..01c76e51b 100644 --- a/cmd/kk/cmd/create/cluster.go +++ b/cmd/kk/cmd/create/cluster.go @@ -47,6 +47,7 @@ type CreateClusterOptions struct { Artifact string InstallPackages bool WithBuildx bool + OnlyEtcd bool localStorageChanged bool } @@ -114,7 +115,6 @@ func (o *CreateClusterOptions) Run() error { KubernetesVersion: o.Kubernetes, KsEnable: o.EnableKubeSphere, KsVersion: o.KubeSphere, - SkipInstallAddons: o.SkipInstallAddons, SkipPullImages: o.SkipPullImages, SkipPushImages: o.SkipPushImages, SecurityEnhancement: o.SecurityEnhancement, @@ -125,7 +125,6 @@ func (o *CreateClusterOptions) Run() error { Artifact: o.Artifact, InstallPackages: o.InstallPackages, Namespace: o.CommonOptions.Namespace, - WithBuildx: o.WithBuildx, } if o.localStorageChanged { @@ -141,7 +140,6 @@ func (o *CreateClusterOptions) AddFlags(cmd *cobra.Command) { cmd.Flags().StringVarP(&o.Kubernetes, "with-kubernetes", "", "", "Specify a supported version of kubernetes") cmd.Flags().BoolVarP(&o.LocalStorage, "with-local-storage", "", false, "Deploy a local PV provisioner") cmd.Flags().BoolVarP(&o.EnableKubeSphere, "with-kubesphere", "", false, fmt.Sprintf("Deploy a specific version of kubesphere (default %s)", kubesphere.Latest().Version)) - cmd.Flags().BoolVarP(&o.SkipInstallAddons, "skip-install-addons", "", false, "Skip install addons") cmd.Flags().BoolVarP(&o.SkipPullImages, "skip-pull-images", "", false, "Skip pre pull images") cmd.Flags().BoolVarP(&o.SkipPushImages, "skip-push-images", "", false, "Skip pre push images") cmd.Flags().BoolVarP(&o.SecurityEnhancement, "with-security-enhancement", "", false, "Security enhancement") @@ -150,7 +148,6 @@ 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.WithBuildx, "with-buildx", "", false, "install buildx when Container runtime is docker") } 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 b500a3f06..758fbe4d7 100644 --- a/cmd/kk/pkg/common/kube_runtime.go +++ b/cmd/kk/pkg/common/kube_runtime.go @@ -59,6 +59,7 @@ type Argument struct { Type string EtcdUpgrade bool WithBuildx bool + 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 a083d290b..149d4c1ba 100644 --- a/cmd/kk/pkg/pipelines/create_cluster.go +++ b/cmd/kk/pkg/pipelines/create_cluster.go @@ -35,8 +35,6 @@ import ( "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/etcd" "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/filesystem" "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/images" - "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/k3s" - "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/k8e" "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/kubernetes" "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/kubesphere" "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/loadbalancer" @@ -75,183 +73,38 @@ func NewCreateClusterPipeline(runtime *common.KubeRuntime) error { &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{}, - &customscripts.CustomScriptsModule{Phase: "PostClusterInstall", Scripts: runtime.Cluster.System.PostClusterInstall}, - &addons.AddonsModule{Skip: runtime.Arg.SkipInstallAddons}, - &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{ - Name: "CreateClusterPipeline", - Modules: m, - Runtime: runtime, } - if err := p.Start(); err != nil { - return err - } - - if runtime.Cluster.KubeSphere.Enabled { - - fmt.Print(`Installation is complete. - -Please check the result using the command: - - kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f - -`) - } else { - fmt.Print(`Installation is complete. - -Please check the result using the command: - - kubectl get pod -A - -`) - } - - return nil -} - -func NewK3sCreateClusterPipeline(runtime *common.KubeRuntime) error { - noArtifact := runtime.Arg.Artifact == "" - skipPushImages := runtime.Arg.SkipPushImages || noArtifact || (!noArtifact && runtime.Cluster.Registry.PrivateRegistry == "") - skipLocalStorage := true - if runtime.Arg.DeployLocalStorage != nil { - skipLocalStorage = !*runtime.Arg.DeployLocalStorage - } else if runtime.Cluster.KubeSphere.Enabled { - skipLocalStorage = false - } - - m := []module.Module{ - &precheck.GreetingsModule{}, - &artifact.UnArchiveModule{Skip: noArtifact}, - &os.RepositoryModule{Skip: noArtifact || !runtime.Arg.InstallPackages}, - &binaries.K3sNodeBinariesModule{}, - &os.ConfigureOSModule{Skip: runtime.Cluster.System.SkipConfigureOS}, - &customscripts.CustomScriptsModule{Phase: "PreInstall", Scripts: runtime.Cluster.System.PreInstall}, - &k3s.StatusModule{}, - &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}, - &loadbalancer.K3sKubevipModule{Skip: !runtime.Cluster.ControlPlaneEndpoint.IsInternalLBEnabledVip()}, - &k3s.InstallKubeBinariesModule{}, - &k3s.InitClusterModule{}, - &k3s.StatusModule{}, - &k3s.JoinNodesModule{}, - &images.CopyImagesToRegistryModule{Skip: skipPushImages}, - &loadbalancer.K3sHaproxyModule{Skip: !runtime.Cluster.ControlPlaneEndpoint.IsInternalLBEnabled()}, - &network.DeployNetworkPluginModule{}, - &kubernetes.ConfigureKubernetesModule{}, - &filesystem.ChownModule{}, - &certs.AutoRenewCertsModule{Skip: !runtime.Cluster.Kubernetes.EnableAutoRenewCerts()}, - &k3s.SaveKubeConfigModule{}, - &customscripts.CustomScriptsModule{Phase: "PostClusterInstall", Scripts: runtime.Cluster.System.PostClusterInstall}, - &addons.AddonsModule{Skip: runtime.Arg.SkipInstallAddons}, - &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}, + if !runtime.Arg.OnlyEtcd { + m = append(m, []module.Module{ + &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{}, + &customscripts.CustomScriptsModule{Phase: "PostClusterInstall", Scripts: runtime.Cluster.System.PostClusterInstall}, + &addons.AddonsModule{Skip: runtime.Arg.SkipInstallAddons}, + &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{ - Name: "K3sCreateClusterPipeline", - Modules: m, - Runtime: runtime, - } - if err := p.Start(); err != nil { - return err - } - - if runtime.Cluster.KubeSphere.Enabled { - - fmt.Print(`Installation is complete. - -Please check the result using the command: - - kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f - -`) - } else { - fmt.Print(`Installation is complete. - -Please check the result using the command: - - kubectl get pod -A - -`) - - } - - return nil -} - -func NewK8eCreateClusterPipeline(runtime *common.KubeRuntime) error { - noArtifact := runtime.Arg.Artifact == "" - skipPushImages := runtime.Arg.SkipPushImages || noArtifact || (!noArtifact && runtime.Cluster.Registry.PrivateRegistry == "") - skipLocalStorage := true - if runtime.Arg.DeployLocalStorage != nil { - skipLocalStorage = !*runtime.Arg.DeployLocalStorage - } else if runtime.Cluster.KubeSphere.Enabled { - skipLocalStorage = false - } - - m := []module.Module{ - &precheck.GreetingsModule{}, - &artifact.UnArchiveModule{Skip: noArtifact}, - &os.RepositoryModule{Skip: noArtifact || !runtime.Arg.InstallPackages}, - &binaries.K8eNodeBinariesModule{}, - &os.ConfigureOSModule{Skip: runtime.Cluster.System.SkipConfigureOS}, - &customscripts.CustomScriptsModule{Phase: "PreInstall", Scripts: runtime.Cluster.System.PreInstall}, - &k8e.StatusModule{}, - &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}, - &loadbalancer.K3sKubevipModule{Skip: !runtime.Cluster.ControlPlaneEndpoint.IsInternalLBEnabledVip()}, - &k8e.InstallKubeBinariesModule{}, - &k8e.InitClusterModule{}, - &k8e.StatusModule{}, - &k8e.JoinNodesModule{}, - &images.CopyImagesToRegistryModule{Skip: skipPushImages}, - &loadbalancer.K3sHaproxyModule{Skip: !runtime.Cluster.ControlPlaneEndpoint.IsInternalLBEnabled()}, - &network.DeployNetworkPluginModule{}, - &kubernetes.ConfigureKubernetesModule{}, - &filesystem.ChownModule{}, - &certs.AutoRenewCertsModule{Skip: !runtime.Cluster.Kubernetes.EnableAutoRenewCerts()}, - &k8e.SaveKubeConfigModule{}, - &customscripts.CustomScriptsModule{Phase: "PostClusterInstall", Scripts: runtime.Cluster.System.PostClusterInstall}, - &addons.AddonsModule{Skip: runtime.Arg.SkipInstallAddons}, - &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{ - Name: "K8eCreateClusterPipeline", + Name: "CreateClusterPipeline", Modules: m, Runtime: runtime, } @@ -265,7 +118,7 @@ func NewK8eCreateClusterPipeline(runtime *common.KubeRuntime) error { Please check the result using the command: - kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f + kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f `) } else { @@ -282,6 +135,7 @@ Please check the result using the command: return nil } +// CreateCluster is the main function to create a cluster func CreateCluster(args common.Argument, downloadCmd string) error { args.DownloadCommand = func(path, url string) string { // this is an extension point for downloading tools, for example users can set the timeout, proxy or retry under diff --git a/cmd/kk/pkg/pipelines/create_k3s_cluster.go b/cmd/kk/pkg/pipelines/create_k3s_cluster.go new file mode 100644 index 000000000..6d681bb97 --- /dev/null +++ b/cmd/kk/pkg/pipelines/create_k3s_cluster.go @@ -0,0 +1,117 @@ +/* + Copyright 2021 The KubeSphere Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package pipelines + +import ( + "fmt" + + kubekeyapiv1alpha2 "github.com/kubesphere/kubekey/v3/cmd/kk/apis/kubekey/v1alpha2" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/addons" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/artifact" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/binaries" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/bootstrap/customscripts" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/bootstrap/os" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/bootstrap/precheck" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/certs" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/common" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/module" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/pipeline" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/etcd" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/filesystem" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/images" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/k3s" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/kubernetes" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/kubesphere" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/loadbalancer" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/plugins/network" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/plugins/storage" +) + +func NewK3sCreateClusterPipeline(runtime *common.KubeRuntime) error { + noArtifact := runtime.Arg.Artifact == "" + skipPushImages := runtime.Arg.SkipPushImages || noArtifact || (!noArtifact && runtime.Cluster.Registry.PrivateRegistry == "") + skipLocalStorage := true + if runtime.Arg.DeployLocalStorage != nil { + skipLocalStorage = !*runtime.Arg.DeployLocalStorage + } else if runtime.Cluster.KubeSphere.Enabled { + skipLocalStorage = false + } + + m := []module.Module{ + &precheck.GreetingsModule{}, + &artifact.UnArchiveModule{Skip: noArtifact}, + &os.RepositoryModule{Skip: noArtifact || !runtime.Arg.InstallPackages}, + &binaries.K3sNodeBinariesModule{}, + &os.ConfigureOSModule{Skip: runtime.Cluster.System.SkipConfigureOS}, + &customscripts.CustomScriptsModule{Phase: "PreInstall", Scripts: runtime.Cluster.System.PreInstall}, + &k3s.StatusModule{}, + &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}, + &loadbalancer.K3sKubevipModule{Skip: !runtime.Cluster.ControlPlaneEndpoint.IsInternalLBEnabledVip()}, + &k3s.InstallKubeBinariesModule{}, + &k3s.InitClusterModule{}, + &k3s.StatusModule{}, + &k3s.JoinNodesModule{}, + &images.CopyImagesToRegistryModule{Skip: skipPushImages}, + &loadbalancer.K3sHaproxyModule{Skip: !runtime.Cluster.ControlPlaneEndpoint.IsInternalLBEnabled()}, + &network.DeployNetworkPluginModule{}, + &kubernetes.ConfigureKubernetesModule{}, + &filesystem.ChownModule{}, + &certs.AutoRenewCertsModule{Skip: !runtime.Cluster.Kubernetes.EnableAutoRenewCerts()}, + &k3s.SaveKubeConfigModule{}, + &customscripts.CustomScriptsModule{Phase: "PostClusterInstall", Scripts: runtime.Cluster.System.PostClusterInstall}, + &addons.AddonsModule{Skip: runtime.Arg.SkipInstallAddons}, + &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{ + Name: "K3sCreateClusterPipeline", + Modules: m, + Runtime: runtime, + } + if err := p.Start(); err != nil { + return err + } + + if runtime.Cluster.KubeSphere.Enabled { + + fmt.Print(`Installation is complete. + +Please check the result using the command: + + kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f + +`) + } else { + fmt.Print(`Installation is complete. + +Please check the result using the command: + + kubectl get pod -A + +`) + + } + + return nil +} diff --git a/cmd/kk/pkg/pipelines/create_k8e_cluster.go b/cmd/kk/pkg/pipelines/create_k8e_cluster.go new file mode 100644 index 000000000..b2712e497 --- /dev/null +++ b/cmd/kk/pkg/pipelines/create_k8e_cluster.go @@ -0,0 +1,117 @@ +/* + Copyright 2021 The KubeSphere Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package pipelines + +import ( + "fmt" + + kubekeyapiv1alpha2 "github.com/kubesphere/kubekey/v3/cmd/kk/apis/kubekey/v1alpha2" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/addons" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/artifact" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/binaries" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/bootstrap/customscripts" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/bootstrap/os" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/bootstrap/precheck" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/certs" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/common" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/module" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/pipeline" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/etcd" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/filesystem" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/images" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/k8e" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/kubernetes" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/kubesphere" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/loadbalancer" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/plugins/network" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/plugins/storage" +) + +func NewK8eCreateClusterPipeline(runtime *common.KubeRuntime) error { + noArtifact := runtime.Arg.Artifact == "" + skipPushImages := runtime.Arg.SkipPushImages || noArtifact || (!noArtifact && runtime.Cluster.Registry.PrivateRegistry == "") + skipLocalStorage := true + if runtime.Arg.DeployLocalStorage != nil { + skipLocalStorage = !*runtime.Arg.DeployLocalStorage + } else if runtime.Cluster.KubeSphere.Enabled { + skipLocalStorage = false + } + + m := []module.Module{ + &precheck.GreetingsModule{}, + &artifact.UnArchiveModule{Skip: noArtifact}, + &os.RepositoryModule{Skip: noArtifact || !runtime.Arg.InstallPackages}, + &binaries.K8eNodeBinariesModule{}, + &os.ConfigureOSModule{Skip: runtime.Cluster.System.SkipConfigureOS}, + &customscripts.CustomScriptsModule{Phase: "PreInstall", Scripts: runtime.Cluster.System.PreInstall}, + &k8e.StatusModule{}, + &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}, + &loadbalancer.K3sKubevipModule{Skip: !runtime.Cluster.ControlPlaneEndpoint.IsInternalLBEnabledVip()}, + &k8e.InstallKubeBinariesModule{}, + &k8e.InitClusterModule{}, + &k8e.StatusModule{}, + &k8e.JoinNodesModule{}, + &images.CopyImagesToRegistryModule{Skip: skipPushImages}, + &loadbalancer.K3sHaproxyModule{Skip: !runtime.Cluster.ControlPlaneEndpoint.IsInternalLBEnabled()}, + &network.DeployNetworkPluginModule{}, + &kubernetes.ConfigureKubernetesModule{}, + &filesystem.ChownModule{}, + &certs.AutoRenewCertsModule{Skip: !runtime.Cluster.Kubernetes.EnableAutoRenewCerts()}, + &k8e.SaveKubeConfigModule{}, + &customscripts.CustomScriptsModule{Phase: "PostClusterInstall", Scripts: runtime.Cluster.System.PostClusterInstall}, + &addons.AddonsModule{Skip: runtime.Arg.SkipInstallAddons}, + &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{ + Name: "K8eCreateClusterPipeline", + Modules: m, + Runtime: runtime, + } + if err := p.Start(); err != nil { + return err + } + + if runtime.Cluster.KubeSphere.Enabled { + + fmt.Print(`Installation is complete. + +Please check the result using the command: + + kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f + +`) + } else { + fmt.Print(`Installation is complete. + +Please check the result using the command: + + kubectl get pod -A + +`) + + } + + return nil +}