kubekey/pkg/bootstrap/os/module.go
pixiake dbe5027cf0 Support the use of kubeadm to manage etcd and use of existing etcd
Signed-off-by: pixiake <guofeng@yunify.com>
2022-03-24 09:14:10 +08:00

272 lines
6.1 KiB
Go

/*
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 os
import (
"github.com/kubesphere/kubekey/pkg/bootstrap/os/templates"
"github.com/kubesphere/kubekey/pkg/common"
"github.com/kubesphere/kubekey/pkg/core/action"
"github.com/kubesphere/kubekey/pkg/core/task"
"github.com/kubesphere/kubekey/pkg/core/util"
"path/filepath"
)
type ConfigureOSModule struct {
common.KubeModule
}
func (c *ConfigureOSModule) Init() {
c.Name = "ConfigureOSModule"
c.Desc = "Init os dependencies"
initOS := &task.RemoteTask{
Name: "InitOS",
Desc: "Prepare to init OS",
Hosts: c.Runtime.GetAllHosts(),
Action: new(NodeConfigureOS),
Parallel: true,
}
GenerateScript := &task.RemoteTask{
Name: "GenerateScript",
Desc: "Generate init os script",
Hosts: c.Runtime.GetAllHosts(),
Action: &action.Template{
Template: templates.InitOsScriptTmpl,
Dst: filepath.Join(common.KubeScriptDir, "initOS.sh"),
Data: util.Data{
"Hosts": templates.GenerateHosts(c.Runtime, c.KubeConf),
},
},
Parallel: true,
}
ExecScript := &task.RemoteTask{
Name: "ExecScript",
Desc: "Exec init os script",
Hosts: c.Runtime.GetAllHosts(),
Action: new(NodeExecScript),
Parallel: true,
}
ConfigureNtpServer := &task.RemoteTask{
Name: "ConfigureNtpServer",
Desc: "configure the ntp server for each node",
Hosts: c.Runtime.GetAllHosts(),
Prepare: new(NodeConfigureNtpCheck),
Action: new(NodeConfigureNtpServer),
Parallel: true,
}
c.Tasks = []task.Interface{
initOS,
GenerateScript,
ExecScript,
ConfigureNtpServer,
}
}
type ClearOSEnvironmentModule struct {
common.KubeModule
}
func (c *ClearOSEnvironmentModule) Init() {
c.Name = "ClearOSModule"
resetNetworkConfig := &task.RemoteTask{
Name: "ResetNetworkConfig",
Desc: "Reset os network config",
Hosts: c.Runtime.GetHostsByRole(common.K8s),
Action: new(ResetNetworkConfig),
Parallel: true,
}
uninstallETCD := &task.RemoteTask{
Name: "UninstallETCD",
Desc: "Uninstall etcd",
Hosts: c.Runtime.GetHostsByRole(common.ETCD),
Prepare: new(EtcdTypeIsKubeKey),
Action: new(UninstallETCD),
Parallel: true,
}
removeFiles := &task.RemoteTask{
Name: "RemoveFiles",
Desc: "Remove cluster files",
Hosts: c.Runtime.GetHostsByRole(common.K8s),
Action: new(RemoveFiles),
Parallel: true,
}
daemonReload := &task.RemoteTask{
Name: "DaemonReload",
Desc: "Systemd daemon reload",
Hosts: c.Runtime.GetHostsByRole(common.K8s),
Action: new(DaemonReload),
Parallel: true,
}
c.Tasks = []task.Interface{
resetNetworkConfig,
uninstallETCD,
removeFiles,
daemonReload,
}
}
type InitDependenciesModule struct {
common.KubeModule
}
func (i *InitDependenciesModule) Init() {
i.Name = "InitDependenciesModule"
getOSData := &task.RemoteTask{
Name: "GetOSData",
Desc: "Get OS release",
Hosts: i.Runtime.GetAllHosts(),
Action: new(GetOSData),
Parallel: true,
}
onlineInstall := &task.RemoteTask{
Name: "OnlineInstallDependencies",
Desc: "Online install dependencies",
Hosts: i.Runtime.GetAllHosts(),
Action: new(OnlineInstallDependencies),
Parallel: true,
}
offlineInstall := &task.RemoteTask{
Name: "OnlineInstallDependencies",
Desc: "Offline install dependencies",
Hosts: i.Runtime.GetAllHosts(),
Action: new(OfflineInstallDependencies),
Parallel: true,
}
if i.KubeConf.Arg.SourcesDir == "" {
i.Tasks = []task.Interface{
getOSData,
onlineInstall,
}
} else {
i.Tasks = []task.Interface{
getOSData,
offlineInstall,
}
}
}
type RepositoryModule struct {
common.KubeModule
Skip bool
}
func (r *RepositoryModule) IsSkip() bool {
return r.Skip
}
func (r *RepositoryModule) Init() {
r.Name = "RepositoryModule"
r.Desc = "Install local repository"
getOSData := &task.RemoteTask{
Name: "GetOSData",
Desc: "Get OS release",
Hosts: r.Runtime.GetAllHosts(),
Action: new(GetOSData),
Parallel: true,
}
sync := &task.RemoteTask{
Name: "SyncRepositoryISOFile",
Desc: "Sync repository iso file to all nodes",
Hosts: r.Runtime.GetAllHosts(),
Action: new(SyncRepositoryFile),
Parallel: true,
Retry: 2,
}
mount := &task.RemoteTask{
Name: "MountISO",
Desc: "Mount iso file",
Hosts: r.Runtime.GetAllHosts(),
Action: new(MountISO),
Parallel: true,
Retry: 1,
}
backup := &task.RemoteTask{
Name: "BackupOriginalRepository",
Desc: "Backup original repository",
Hosts: r.Runtime.GetAllHosts(),
Action: new(BackupOriginalRepository),
Parallel: true,
Retry: 1,
Rollback: new(RollbackUmount),
}
add := &task.RemoteTask{
Name: "AddLocalRepository",
Desc: "Add local repository",
Hosts: r.Runtime.GetAllHosts(),
Action: new(AddLocalRepository),
Parallel: true,
Retry: 1,
Rollback: new(RecoverRepository),
}
install := &task.RemoteTask{
Name: "InstallPackage",
Desc: "Install packages",
Hosts: r.Runtime.GetAllHosts(),
Action: new(InstallPackage),
Parallel: true,
Retry: 1,
Rollback: new(RecoverRepository),
}
reset := &task.RemoteTask{
Name: "ResetRepository",
Desc: "Reset repository to the original repository",
Hosts: r.Runtime.GetAllHosts(),
Action: new(ResetRepository),
Parallel: true,
Retry: 1,
}
umount := &task.RemoteTask{
Name: "UmountISO",
Desc: "Umount ISO file",
Hosts: r.Runtime.GetAllHosts(),
Action: new(UmountISO),
Parallel: true,
}
r.Tasks = []task.Interface{
getOSData,
sync,
mount,
backup,
add,
install,
reset,
umount,
}
}