kubekey/pkg/bootstrap/init.go
pixiake efc63740a9 addons charts
Signed-off-by: pixiake <guofeng@yunify.com>
2020-10-10 16:43:47 +08:00

71 lines
2.0 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, objName, err := config.ParseClusterCfg(clusterCfgFile, "", "", false, logger)
if err != nil {
return errors.Wrap(err, "Failed to download cluster config")
}
return Execute(executor.NewExecutor(&cfg.Spec, objName, 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
}