mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-26 01:22:51 +00:00
add init operating system
Signed-off-by: pixiake <guofeng@yunify.com>
This commit is contained in:
parent
cb962e0f27
commit
0c5c3586ca
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
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 cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// initCmd represents the create command
|
||||
var initCmd = &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "Initializes the installation environment",
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(initCmd)
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
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 cmd
|
||||
|
||||
import (
|
||||
"github.com/kubesphere/kubekey/pkg/bootstrap"
|
||||
"github.com/kubesphere/kubekey/pkg/util"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// osCmd represents the os command
|
||||
var osCmd = &cobra.Command{
|
||||
Use: "os",
|
||||
Short: "Init operating system",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
logger := util.InitLogger(opt.Verbose)
|
||||
return bootstrap.Init(opt.ClusterCfgFile, opt.SourcesDir, opt.AddImagesRepo, logger)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
initCmd.AddCommand(osCmd)
|
||||
osCmd.Flags().StringVarP(&opt.ClusterCfgFile, "filename", "f", "", "Path to a configuration file")
|
||||
osCmd.Flags().StringVarP(&opt.SourcesDir, "sources", "s", "", "Path to the dependencies' dir")
|
||||
osCmd.Flags().BoolVarP(&opt.AddImagesRepo, "add-images-repo", "", false, "Create a local images registry")
|
||||
}
|
||||
|
|
@ -36,6 +36,8 @@ type Options struct {
|
|||
SkipPullImages bool
|
||||
KsVersion string
|
||||
Registry string
|
||||
SourcesDir string
|
||||
AddImagesRepo bool
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
|
|||
3
go.mod
3
go.mod
|
|
@ -3,7 +3,8 @@ module github.com/kubesphere/kubekey
|
|||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/ghodss/yaml v1.0.0
|
||||
github.com/dominodatalab/os-release v0.0.0-20190522011736-bcdb4a3e3c2f
|
||||
github.com/ghodss/yaml v1.0.0 // indirect
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||
github.com/lithammer/dedent v1.1.0
|
||||
github.com/mitchellh/mapstructure v1.3.3
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -270,6 +270,8 @@ github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1/go.mod h1:cyGadeNE
|
|||
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 h1:cenwrSVm+Z7QLSV/BsnenAOcDXdX4cMv4wP0B/5QbPg=
|
||||
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
|
||||
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
|
||||
github.com/dominodatalab/os-release v0.0.0-20190522011736-bcdb4a3e3c2f h1:oEt43goQgsL1DzoOyQ/UZHQw7t9TqwyJec9W0vh0wfE=
|
||||
github.com/dominodatalab/os-release v0.0.0-20190522011736-bcdb4a3e3c2f/go.mod h1:RU3x9VqPvzbOGJ3wtP0pPBtUOp4yU/yzA/8qdxgi/6Q=
|
||||
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
|
||||
|
|
@ -989,6 +991,7 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
|
|||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
|
||||
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
|
||||
|
|
@ -1409,6 +1412,7 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20190905181640-827449938966/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
|
||||
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ func AddNodes(clusterCfgFile, k8sVersion, ksVersion string, logger *log.Logger,
|
|||
return errors.Wrap(err, "Failed to download cluster config")
|
||||
}
|
||||
|
||||
return Execute(executor.NewExecutor(&cfg.Spec, logger, verbose, skipCheck, skipPullImages))
|
||||
return Execute(executor.NewExecutor(&cfg.Spec, logger, "", verbose, skipCheck, skipPullImages, false))
|
||||
}
|
||||
|
||||
func ExecTasks(mgr *manager.Manager) error {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
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
|
||||
}
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
/*
|
||||
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 (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
osrelease "github.com/dominodatalab/os-release"
|
||||
kubekeyapi "github.com/kubesphere/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/kubesphere/kubekey/pkg/container-engine/docker"
|
||||
"github.com/kubesphere/kubekey/pkg/util"
|
||||
"github.com/kubesphere/kubekey/pkg/util/manager"
|
||||
"github.com/pkg/errors"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var registryCrt string
|
||||
|
||||
func InitOS(mgr *manager.Manager) error {
|
||||
user, _ := user.Current()
|
||||
if user.Name != "root" {
|
||||
return errors.New(fmt.Sprintf("Current user is %s. Please use root!", user.Name))
|
||||
}
|
||||
mgr.Logger.Infoln("Init operating system")
|
||||
|
||||
if err := mgr.RunTaskOnAllNodes(initOS, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if mgr.AddImagesRepo {
|
||||
if output, err := exec.Command("/bin/bash", "-c", "if [[ ! \"$(docker ps --filter 'name=kubekey-registry' --format '{{.Names}}')\" =~ 'kubekey-registry' ]]; then "+
|
||||
"mkdir -p /opt/registry/certs && "+
|
||||
"openssl req -newkey rsa:4096 -nodes -sha256 -keyout /opt/registry/certs/domain.key -x509 -days 36500 -out /opt/registry/certs/domain.crt -subj '/CN=dockerhub.kubekey.local';"+
|
||||
"fi").CombinedOutput(); err != nil {
|
||||
return errors.Wrapf(err, string(output))
|
||||
}
|
||||
registryCrtBase64Cmd := "cat /opt/registry/certs/domain.crt | base64 --wrap=0"
|
||||
if output, err := exec.Command("/bin/sh", "-c", registryCrtBase64Cmd).CombinedOutput(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
registryCrt = strings.TrimSpace(string(output))
|
||||
}
|
||||
if output, err := exec.Command("/bin/bash", "-c",
|
||||
"if [[ ! \"$(docker ps --filter 'name=kubekey-registry' --format '{{.Names}}')\" =~ 'kubekey-registry' ]]; then "+
|
||||
"docker run -d --restart=always --name kubekey-registry "+
|
||||
"-v /opt/registry/certs:/certs -v /mnt/registry:/var/lib/registry "+
|
||||
"-e REGISTRY_HTTP_ADDR=0.0.0.0:443 -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key "+
|
||||
"-p 443:443 registry:2; fi").CombinedOutput(); err != nil {
|
||||
return errors.Wrapf(err, string(output))
|
||||
}
|
||||
|
||||
if err := mgr.RunTaskOnAllNodes(initImagesRepo, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println("\nLocal images repository created successfully. Address: dockerhub.kubekey.local\n")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func initOS(mgr *manager.Manager, node *kubekeyapi.HostCfg) error {
|
||||
initFlag, err1 := mgr.Runner.ExecuteCmd(fmt.Sprintf("sudo -E /bin/sh -c \"if [ -z $(which docker) ] || [ ! -e /var/run/docker.sock ]; then echo needToInit; fi\""), 1, false)
|
||||
if err1 != nil {
|
||||
return err1
|
||||
}
|
||||
|
||||
if strings.Contains(initFlag, "needToInit") {
|
||||
osReleaseStr, err := mgr.Runner.ExecuteCmd("sudo -E /bin/sh -c \"cat /etc/os-release\"", 2, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
osrData := osrelease.Parse(strings.Replace(osReleaseStr, "\r\n", "\n", -1))
|
||||
|
||||
pkgToolStr, err := mgr.Runner.ExecuteCmd("sudo -E /bin/sh -c \"if [ ! -z $(which yum 2>/dev/null) ]; then echo rpm; elif [ ! -z $(which apt 2>/dev/null) ]; then echo deb; fi\"", 2, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dockerConfig, err := docker.GenerateDockerConfig(mgr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dockerConfigBase64 := base64.StdEncoding.EncodeToString([]byte(dockerConfig))
|
||||
mgr.Logger.Info(fmt.Sprintf("Start initializing %s [%s]\n", node.Name, node.InternalAddress))
|
||||
if mgr.SourcesDir == "" {
|
||||
switch strings.TrimSpace(pkgToolStr) {
|
||||
case "deb":
|
||||
if _, err := mgr.Runner.ExecuteCmd("sudo -E /bin/sh -c \""+
|
||||
"apt update;"+
|
||||
"apt install socat conntrack ipset ebtables nfs-common ceph-common software-properties-common -y;"+
|
||||
"add-apt-repository ppa:gluster/glusterfs-7 -y;"+
|
||||
"apt update;"+
|
||||
"apt install glusterfs-client -y"+
|
||||
"\"", 2, false); err != nil {
|
||||
return err
|
||||
}
|
||||
case "rpm":
|
||||
if _, err := mgr.Runner.ExecuteCmd("sudo -E /bin/sh -c \""+
|
||||
"yum install yum-utils openssl socat conntrack ipset ebtables nfs-utils ceph-common glusterfs-fuse -y\"", 2, false); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return errors.New(fmt.Sprintf("Unsupported operating system: %s", osrData.ID))
|
||||
}
|
||||
|
||||
output, err1 := mgr.Runner.ExecuteCmd(fmt.Sprintf("sudo -E /bin/sh -c \"if [ -z $(which docker) ] || [ ! -e /var/run/docker.sock ]; then curl https://kubernetes.pek3b.qingstor.com/tools/kubekey/docker-install.sh | sh && systemctl enable docker && echo %s | base64 -d > /etc/docker/daemon.json && systemctl reload docker && systemctl restart docker; fi\"", dockerConfigBase64), 0, false)
|
||||
if err1 != nil {
|
||||
return errors.Wrap(errors.WithStack(err1), fmt.Sprintf("Failed to install docker:\n%s", output))
|
||||
}
|
||||
} else {
|
||||
fp, err := filepath.Abs(mgr.SourcesDir)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to look up current directory")
|
||||
}
|
||||
|
||||
switch strings.TrimSpace(pkgToolStr) {
|
||||
case "deb":
|
||||
dirName := fmt.Sprintf("%s-%s-%s-debs", osrData.ID, osrData.VersionID, node.Arch)
|
||||
_ = mgr.Runner.ScpFile(fmt.Sprintf("%s/%s.tar.gz", fp, dirName), "/tmp")
|
||||
if _, err := mgr.Runner.ExecuteCmd("sudo -E /bin/sh -c \""+
|
||||
fmt.Sprintf("tar -zxvf /tmp/%s.tar.gz -C /tmp && dpkg -iR --force-all /tmp/%s", dirName, dirName)+"\"", 2, false); err != nil {
|
||||
return err
|
||||
}
|
||||
case "rpm":
|
||||
dirName := fmt.Sprintf("%s-%s-%s-rpms", osrData.ID, osrData.VersionID, node.Arch)
|
||||
_ = mgr.Runner.ScpFile(fmt.Sprintf("%s/%s.tar.gz", fp, dirName), "/tmp")
|
||||
if _, err := mgr.Runner.ExecuteCmd("sudo -E /bin/sh -c \""+
|
||||
fmt.Sprintf("tar -zxvf /tmp/%s.tar.gz -C /tmp && rpm -Uvh --force --nodeps /tmp/%s/*rpm", dirName, dirName)+"\"", 2, false); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return errors.New(fmt.Sprintf("Unsupported operating system: %s", osrData.ID))
|
||||
}
|
||||
|
||||
output, err1 := mgr.Runner.ExecuteCmd(fmt.Sprintf("sudo -E /bin/sh -c \"systemctl start docker && systemctl enable docker && echo %s | base64 -d > /etc/docker/daemon.json && systemctl reload docker && systemctl restart docker\"", dockerConfigBase64), 0, false)
|
||||
if err1 != nil {
|
||||
return errors.Wrap(errors.WithStack(err1), fmt.Sprintf("Failed to install docker:\n%s", output))
|
||||
}
|
||||
}
|
||||
mgr.Logger.Info(fmt.Sprintf("Complete initialization %s [%s]\n", node.Name, node.InternalAddress))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func initImagesRepo(mgr *manager.Manager, _ *kubekeyapi.HostCfg) error {
|
||||
crtPath := "/etc/docker/certs.d/dockerhub.kubekey.local"
|
||||
syncKubeconfigForRootCmd := fmt.Sprintf("sudo -E /bin/sh -c \"mkdir -p %s && echo %s | base64 -d > %s/ca.crt\"", crtPath, registryCrt, crtPath)
|
||||
if _, err := mgr.Runner.ExecuteCmd(syncKubeconfigForRootCmd, 1, false); err != nil {
|
||||
return errors.Wrap(errors.WithStack(err), "Failed to sync registry crt")
|
||||
}
|
||||
|
||||
if _, err := mgr.Runner.ExecuteCmd(fmt.Sprintf("sudo -E /bin/sh -c \"echo '%s dockerhub.kubekey.local' >> /etc/hosts\"", util.LocalIP())+" && "+
|
||||
"sudo awk ' !x[$0]++{print > \"/etc/hosts\"}' /etc/hosts", 2, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -267,7 +267,7 @@ func BackupEtcd(mgr *manager.Manager) error {
|
|||
}
|
||||
|
||||
func backupEtcd(mgr *manager.Manager, node *kubekeyapi.HostCfg) error {
|
||||
_, err := mgr.Runner.ExecuteCmd("sudo -E /bin/sh -c \"if [ -d /opt/etcd_back ]; then rm -rf /opt/etcd_back ;fi\" && mkdir -p /opt/etcd_back", 0, false)
|
||||
_, err := mgr.Runner.ExecuteCmd("sudo -E /bin/sh -c \"if [ -d /opt/etcd_back ]; then rm -rf /opt/etcd_back ;fi && mkdir -p /opt/etcd_back\"", 0, false)
|
||||
if err != nil {
|
||||
return errors.Wrap(errors.WithStack(err), "Failed to mkdir /opt/etcd_back")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ func addWorker(mgr *manager.Manager) error {
|
|||
}
|
||||
syncKubeconfigForRootCmd := fmt.Sprintf("sudo -E /bin/sh -c \"echo %s | base64 -d > %s\"", clusterStatus["kubeConfig"], "/root/.kube/config")
|
||||
syncKubeconfigForUserCmd := fmt.Sprintf("echo %s | base64 -d > %s && %s", clusterStatus["kubeConfig"], "$HOME/.kube/config", chownKubeConfig)
|
||||
if _, err := mgr.Runner.ExecuteCmd(fmt.Sprintf("sudo -E /bin/sh -c \"%s\"", syncKubeconfigForRootCmd), 1, false); err != nil {
|
||||
if _, err := mgr.Runner.ExecuteCmd(syncKubeconfigForRootCmd, 1, false); err != nil {
|
||||
return errors.Wrap(errors.WithStack(err), "Failed to sync kube config")
|
||||
}
|
||||
if _, err := mgr.Runner.ExecuteCmd(fmt.Sprintf("sudo -E /bin/sh -c \"%s\"", syncKubeconfigForUserCmd), 1, false); err != nil {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ func ResetCluster(clusterCfgFile string, logger *log.Logger, verbose bool) error
|
|||
return errors.Wrap(err, "Failed to download cluster config")
|
||||
}
|
||||
|
||||
return Execute(executor.NewExecutor(&cfg.Spec, logger, verbose, false, true))
|
||||
return Execute(executor.NewExecutor(&cfg.Spec, logger, "", verbose, false, true, false))
|
||||
}
|
||||
|
||||
func ResetNode(clusterCfgFile string, logger *log.Logger, verbose bool, nodeName string) error {
|
||||
|
|
@ -60,7 +60,7 @@ func ResetNode(clusterCfgFile string, logger *log.Logger, verbose bool, nodeName
|
|||
cmd := fmt.Sprintf("sed -i /%s/d %s", nodeName, fp)
|
||||
_ = exec.Command("/bin/sh", "-c", cmd).Run()
|
||||
cfg, _ := config.ParseClusterCfg(clusterCfgFile, "", "", false, logger)
|
||||
return Execute1(executor.NewExecutor(&cfg.Spec, logger, verbose, false, true))
|
||||
return Execute1(executor.NewExecutor(&cfg.Spec, logger, "", verbose, false, true, false))
|
||||
}
|
||||
if string(nodeNameNum) == "1\n" {
|
||||
cmd := fmt.Sprintf("sed -i /%s/d %s", nodeName, fp)
|
||||
|
|
@ -69,7 +69,7 @@ func ResetNode(clusterCfgFile string, logger *log.Logger, verbose bool, nodeName
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to download cluster config")
|
||||
}
|
||||
mgr, err1 := executor.NewExecutor(&cfg.Spec, logger, verbose, false, true).CreateManager()
|
||||
mgr, err1 := executor.NewExecutor(&cfg.Spec, logger, "", verbose, false, true, false).CreateManager()
|
||||
if err1 != nil {
|
||||
return errors.Wrap(err1, "Failed to get cluster config")
|
||||
}
|
||||
|
|
@ -105,7 +105,7 @@ func ResetNode(clusterCfgFile string, logger *log.Logger, verbose bool, nodeName
|
|||
_ = exec.Command("/bin/sh", "-c", cmd2).Run()
|
||||
}
|
||||
cfg1, _ := config.ParseClusterCfg(clusterCfgFile, "", "", false, logger)
|
||||
return Execute1(executor.NewExecutor(&cfg1.Spec, logger, verbose, false, true))
|
||||
return Execute1(executor.NewExecutor(&cfg1.Spec, logger, "", verbose, false, true, false))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ func CreateCluster(clusterCfgFile, k8sVersion, ksVersion string, logger *log.Log
|
|||
return errors.Wrap(err, "Failed to download cluster config")
|
||||
}
|
||||
|
||||
return Execute(executor.NewExecutor(&cfg.Spec, logger, verbose, skipCheck, skipPullImages))
|
||||
return Execute(executor.NewExecutor(&cfg.Spec, logger, "", verbose, skipCheck, skipPullImages, false))
|
||||
}
|
||||
|
||||
func ExecTasks(mgr *manager.Manager) error {
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ EOF
|
|||
}
|
||||
}
|
||||
|
||||
_, err3 := mgr.Runner.ExecuteCmd(`cat <<EOF | kubectl apply -f -
|
||||
_, err3 := mgr.Runner.ExecuteCmd(`cat <<EOF | /usr/local/bin/kubectl apply -f -
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ func UpgradeCluster(clusterCfgFile, k8sVersion, ksVersion string, logger *log.Lo
|
|||
return errors.Wrap(err, "Failed to download cluster config")
|
||||
}
|
||||
|
||||
return Execute(executor.NewExecutor(&cfg.Spec, logger, verbose, true, skipPullImages))
|
||||
return Execute(executor.NewExecutor(&cfg.Spec, logger, "", verbose, true, skipPullImages, false))
|
||||
}
|
||||
|
||||
func ExecTasks(mgr *manager.Manager) error {
|
||||
|
|
|
|||
|
|
@ -30,18 +30,22 @@ import (
|
|||
type Executor struct {
|
||||
Cluster *kubekeyapi.ClusterSpec
|
||||
Logger *log.Logger
|
||||
SourcesDir string
|
||||
Debug bool
|
||||
SkipCheck bool
|
||||
SkipPullImages bool
|
||||
AddImagesRepo bool
|
||||
}
|
||||
|
||||
func NewExecutor(cluster *kubekeyapi.ClusterSpec, logger *log.Logger, debug, skipCheck, skipPullImages bool) *Executor {
|
||||
func NewExecutor(cluster *kubekeyapi.ClusterSpec, logger *log.Logger, sourcesDir string, debug, skipCheck, skipPullImages, addImagesRepo bool) *Executor {
|
||||
return &Executor{
|
||||
Cluster: cluster,
|
||||
Logger: logger,
|
||||
SourcesDir: sourcesDir,
|
||||
Debug: debug,
|
||||
SkipCheck: skipCheck,
|
||||
SkipPullImages: skipPullImages,
|
||||
AddImagesRepo: addImagesRepo,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -64,6 +68,8 @@ func (executor *Executor) CreateManager() (*manager.Manager, error) {
|
|||
mgr.Debug = executor.Debug
|
||||
mgr.SkipCheck = executor.SkipCheck
|
||||
mgr.SkipPullImages = executor.SkipPullImages
|
||||
mgr.SourcesDir = executor.SourcesDir
|
||||
mgr.AddImagesRepo = executor.AddImagesRepo
|
||||
return mgr, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ type Manager struct {
|
|||
Debug bool
|
||||
SkipCheck bool
|
||||
SkipPullImages bool
|
||||
SourcesDir string
|
||||
AddImagesRepo bool
|
||||
}
|
||||
|
||||
func (mgr *Manager) Copy() *Manager {
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ config_daemon(){
|
|||
"max-file":"3"
|
||||
},
|
||||
"exec-opts": ["native.cgroupdriver=systemd"],
|
||||
"registry-mirrors": ["https://hub-mirror.c.163.com", "https://docker.mirrors.ustc.edu.cn"]
|
||||
}
|
||||
EOF
|
||||
sudo systemctl daemon-reload
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ var (
|
|||
//
|
||||
// Increment major number for new feature additions and behavioral changes.
|
||||
// Increment minor number for bug fixes and performance enhancements.
|
||||
version = "v1.0.0"
|
||||
version = "v1.0.1"
|
||||
|
||||
// metadata is extra build time data
|
||||
metadata = ""
|
||||
|
|
|
|||
Loading…
Reference in New Issue