mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-26 09:32:52 +00:00
71 lines
1.9 KiB
Go
71 lines
1.9 KiB
Go
/*
|
|
Copyright 2020 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 bootstrap
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/kubesphere/kubekey/pkg/config"
|
|
"github.com/kubesphere/kubekey/pkg/util"
|
|
"github.com/kubesphere/kubekey/pkg/util/executor"
|
|
"github.com/kubesphere/kubekey/pkg/util/manager"
|
|
"github.com/pkg/errors"
|
|
log "github.com/sirupsen/logrus"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func Init(clusterCfgFile, sourcesDir string, addImagesRepo bool, logger *log.Logger) error {
|
|
currentDir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
|
if err != nil {
|
|
return errors.Wrap(err, "Faild to get current dir")
|
|
}
|
|
if err := util.CreateDir(fmt.Sprintf("%s/kubekey", currentDir)); err != nil {
|
|
return errors.Wrap(err, "Failed to create work dir")
|
|
}
|
|
|
|
cfg, err := config.ParseClusterCfg(clusterCfgFile, "", "", false, logger)
|
|
if err != nil {
|
|
return errors.Wrap(err, "Failed to download cluster config")
|
|
}
|
|
|
|
return Execute(executor.NewExecutor(&cfg.Spec, logger, sourcesDir, true, true, true, addImagesRepo))
|
|
}
|
|
|
|
func Execute(executor *executor.Executor) error {
|
|
mgr, err := executor.CreateManager()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ExecTasks(mgr)
|
|
}
|
|
|
|
func ExecTasks(mgr *manager.Manager) error {
|
|
createTasks := []manager.Task{
|
|
{Task: InitOS, ErrMsg: "Failed to init operating system"},
|
|
}
|
|
|
|
for _, step := range createTasks {
|
|
if err := step.Run(mgr); err != nil {
|
|
return errors.Wrap(err, step.ErrMsg)
|
|
}
|
|
}
|
|
|
|
mgr.Logger.Infoln("Init operating system successful.")
|
|
|
|
return nil
|
|
}
|