mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-26 01:22:51 +00:00
add pre download images
This commit is contained in:
parent
e0df9df425
commit
429d9aa90f
|
|
@ -0,0 +1,3 @@
|
|||
#! /bin/bash
|
||||
|
||||
docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp golang:1.14 go build -v -o kk
|
||||
|
|
@ -5,13 +5,15 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func NewKubekeyCommand() *cobra.Command {
|
||||
var Verbose bool
|
||||
|
||||
func NewKubekeyCommand() *cobra.Command {
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "kk",
|
||||
Short: "Kubernetes Deploy Tool",
|
||||
Long: "Deploy a Kubernetes Cluster Flexibly and Easily .",
|
||||
}
|
||||
|
||||
rootCmd.AddCommand(create.NewCmdCreate())
|
||||
rootCmd.AddCommand(NewCmdScaleCluster())
|
||||
rootCmd.AddCommand(NewCmdVersion())
|
||||
|
|
|
|||
|
|
@ -11,18 +11,20 @@ func NewCmdCreateCluster() *cobra.Command {
|
|||
clusterCfgFile string
|
||||
addons string
|
||||
pkgDir string
|
||||
Verbose bool
|
||||
)
|
||||
var clusterCmd = &cobra.Command{
|
||||
Use: "cluster",
|
||||
Short: "Create Kubernetes Cluster",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
logger := util.InitLogger(true)
|
||||
return install.CreateCluster(clusterCfgFile, logger, addons, pkgDir)
|
||||
logger := util.InitLogger(Verbose)
|
||||
return install.CreateCluster(clusterCfgFile, logger, addons, pkgDir, Verbose)
|
||||
},
|
||||
}
|
||||
|
||||
clusterCmd.Flags().StringVarP(&clusterCfgFile, "config", "f", "", "")
|
||||
clusterCmd.Flags().StringVarP(&addons, "add", "", "", "")
|
||||
clusterCmd.Flags().StringVarP(&pkgDir, "pkg", "", "", "")
|
||||
clusterCmd.Flags().StringVarP(&clusterCfgFile, "config", "f", "", "cluster info config")
|
||||
clusterCmd.Flags().StringVarP(&addons, "add", "", "", "add plugins")
|
||||
clusterCmd.Flags().StringVarP(&pkgDir, "pkg", "", "", "release package (offline)")
|
||||
clusterCmd.Flags().BoolVarP(&Verbose, "debug", "", true, "debug info")
|
||||
return clusterCmd
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,11 +15,12 @@ import (
|
|||
)
|
||||
|
||||
func NewCmdCreateCfg() *cobra.Command {
|
||||
var culsterCfgCmd = &cobra.Command{
|
||||
var addons string
|
||||
var clusterCfgCmd = &cobra.Command{
|
||||
Use: "config",
|
||||
Short: "Create Cluster-Info Config",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
err := GenerateK2ClusterObj()
|
||||
err := GenerateK2ClusterObj(addons)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -27,7 +28,9 @@ func NewCmdCreateCfg() *cobra.Command {
|
|||
//clusterConfig()
|
||||
},
|
||||
}
|
||||
return culsterCfgCmd
|
||||
|
||||
clusterCfgCmd.Flags().StringVarP(&addons, "add", "", "", "add plugins")
|
||||
return clusterCfgCmd
|
||||
}
|
||||
|
||||
func getConfig(reader *bufio.Reader, text, def string) (string, error) {
|
||||
|
|
|
|||
|
|
@ -5,16 +5,16 @@ import (
|
|||
"fmt"
|
||||
"github.com/lithammer/dedent"
|
||||
"github.com/pixiake/kubekey/pkg/util"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
"github.com/pkg/errors"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
var (
|
||||
K2ClusterObjTempl = template.Must(template.New("etcdSslCfg").Parse(
|
||||
K2ClusterObjTempl = template.Must(template.New("K2Cluster").Parse(
|
||||
dedent.Dedent(`apiVersion: kubekey.io/v1alpha1
|
||||
kind: K2Cluster
|
||||
metadata:
|
||||
|
|
@ -44,15 +44,66 @@ spec:
|
|||
plugin: calico
|
||||
kube_pods_cidr: 10.233.64.0/18
|
||||
kube_service_cidr: 10.233.0.0/18
|
||||
registry:
|
||||
registryMirrors: []
|
||||
insecureRegistries: []
|
||||
{{- if ne .PluginsNum 0 }}
|
||||
plugins:
|
||||
{{- if .Options.LocalVolumeEnable }}
|
||||
localVolume:
|
||||
isDefaultClass: {{ .Options.LocalVolumeIsDefault }}
|
||||
{{- end }}
|
||||
{{- if .Options.NfsClientEnable }}
|
||||
nfsClient:
|
||||
isDefaultClass: {{ .Options.NfsClientIsDefault }}
|
||||
nfsServer: ""
|
||||
nfsPath: ""
|
||||
nfsVrs3Enabled: false
|
||||
nfsArchiveOnDelete: false
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
`)))
|
||||
)
|
||||
|
||||
func GenerateK2ClusterObjStr(mgr *manager.Manager, index int) (string, error) {
|
||||
return util.Render(K2ClusterObjTempl, util.Data{})
|
||||
type PluginOptions struct {
|
||||
LocalVolumeEnable bool
|
||||
LocalVolumeIsDefault bool
|
||||
NfsClientEnable bool
|
||||
NfsClientIsDefault bool
|
||||
}
|
||||
|
||||
func GenerateK2ClusterObj() error {
|
||||
K2ClusterObjStr, _ := GenerateK2ClusterObjStr(nil, 0)
|
||||
func GenerateK2ClusterObjStr(opt *PluginOptions, plugins []string) (string, error) {
|
||||
return util.Render(K2ClusterObjTempl, util.Data{
|
||||
"PluginsNum": len(plugins),
|
||||
"Options": opt,
|
||||
})
|
||||
}
|
||||
|
||||
func GenerateK2ClusterObj(addons string) error {
|
||||
opt := PluginOptions{}
|
||||
addonsList := strings.Split(addons, ",")
|
||||
for index, addon := range addonsList {
|
||||
switch strings.TrimSpace(addon) {
|
||||
case "localVolume":
|
||||
opt.LocalVolumeEnable = true
|
||||
if index == 0 {
|
||||
opt.LocalVolumeIsDefault = true
|
||||
}
|
||||
case "nfsClient":
|
||||
opt.NfsClientEnable = true
|
||||
if index == 0 {
|
||||
opt.NfsClientIsDefault = true
|
||||
}
|
||||
default:
|
||||
return errors.New(fmt.Sprintf("This plugin is not supported: %s", strings.TrimSpace(addon)))
|
||||
}
|
||||
}
|
||||
|
||||
K2ClusterObjStr, err := GenerateK2ClusterObjStr(&opt, addonsList)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "faild to generate k2cluster config")
|
||||
}
|
||||
fmt.Println(K2ClusterObjStr)
|
||||
K2ClusterObjStrBase64 := base64.StdEncoding.EncodeToString([]byte(K2ClusterObjStr))
|
||||
|
||||
currentDir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||
|
|
|
|||
|
|
@ -10,17 +10,19 @@ func NewCmdScaleCluster() *cobra.Command {
|
|||
var (
|
||||
clusterCfgFile string
|
||||
pkgDir string
|
||||
Verbose bool
|
||||
)
|
||||
var clusterCmd = &cobra.Command{
|
||||
Use: "scale",
|
||||
Short: "Scale cluster",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
logger := util.InitLogger(true)
|
||||
return scale.ScaleCluster(clusterCfgFile, logger, pkgDir)
|
||||
logger := util.InitLogger(Verbose)
|
||||
return scale.ScaleCluster(clusterCfgFile, logger, pkgDir, Verbose)
|
||||
},
|
||||
}
|
||||
|
||||
clusterCmd.Flags().StringVarP(&clusterCfgFile, "config", "f", "", "")
|
||||
clusterCmd.Flags().StringVarP(&pkgDir, "pkg", "", "", "")
|
||||
clusterCmd.Flags().BoolVarP(&Verbose, "debug", "", true, "")
|
||||
return clusterCmd
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ const (
|
|||
DefaultEtcdVersion = "v3.3.12"
|
||||
DefaultEtcdPort = "2379"
|
||||
DefaultKubeVersion = "v1.17.4"
|
||||
DefaultCalicoVersion = "v3.13.0"
|
||||
DefaultFlannelVersion = "v0.11.0"
|
||||
DefaultCniVersion = "v0.8.2"
|
||||
DefaultHelmVersion = "v3.1.2"
|
||||
ETCDRole = "etcd"
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
package v1alpha1
|
||||
|
||||
type LocalVolume struct {
|
||||
IsDefaultClass bool
|
||||
IsDefaultClass bool `yaml:"isDefaultClass" json:"isDefaultClass,omitempty"`
|
||||
}
|
||||
|
||||
type NfsClient struct {
|
||||
IsDefaultClass bool
|
||||
NfsServer string
|
||||
NfsPath string
|
||||
NfsVrs3Enabled bool
|
||||
NfsArchiveOnDelete bool
|
||||
IsDefaultClass bool `yaml:"isDefaultClass" json:"isDefaultClass,omitempty"`
|
||||
NfsServer string `yaml:"nfsServer" json:"nfsServer,omitempty"`
|
||||
NfsPath string `yaml:"nfsPath" json:"nfsPath,omitempty"`
|
||||
NfsVrs3Enabled bool `yaml:"nfsVrs3Enabled" json:"nfsVrs3Enabled,omitempty"`
|
||||
NfsArchiveOnDelete bool `yaml:"nfsArchiveOnDelete" json:"nfsArchiveOnDelete,omitempty"`
|
||||
}
|
||||
|
||||
type GlusterFS struct {
|
||||
|
|
|
|||
|
|
@ -128,7 +128,6 @@ func GenerateEtcdService(mgr *manager.Manager) error {
|
|||
}
|
||||
|
||||
func generateEtcdService(mgr *manager.Manager, node *kubekeyapi.HostCfg, conn ssh.Connection) error {
|
||||
PreDownloadEtcdImages(mgr, node)
|
||||
etcdService, err := tmpl.GenerateEtcdService(mgr, mgr.Runner.Index)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
package etcd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/images"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
)
|
||||
|
||||
func PreDownloadEtcdImages(mgr *manager.Manager, node *kubekeyapi.HostCfg) {
|
||||
imagesList := []images.Image{
|
||||
{Prefix: images.GetImagePrefix(mgr.Cluster.Registry.PrivateRegistry, kubekeyapi.DefaultKubeImageRepo), Repo: "etcd", Tag: kubekeyapi.DefaultEtcdVersion},
|
||||
}
|
||||
|
||||
for _, image := range imagesList {
|
||||
fmt.Printf("[%s] Download image: %s\n", node.HostName, image.NewImage())
|
||||
mgr.Runner.RunCmd(fmt.Sprintf("sudo -E /bin/sh \"docker pull %s\"", image.NewImage()))
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
package kubernetes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/images"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
)
|
||||
|
||||
func PreDownloadNodeImages(mgr *manager.Manager, node *kubekeyapi.HostCfg) {
|
||||
imagesList := []images.Image{
|
||||
{Prefix: images.GetImagePrefix(mgr.Cluster.Registry.PrivateRegistry, kubekeyapi.DefaultKubeImageRepo), Repo: "pause", Tag: "3.1"},
|
||||
{Prefix: images.GetImagePrefix(mgr.Cluster.Registry.PrivateRegistry, "coredns"), Repo: "coredns", Tag: "1.6.0"},
|
||||
{Prefix: images.GetImagePrefix(mgr.Cluster.Registry.PrivateRegistry, "node"), Repo: "coredns", Tag: "1.6.0"},
|
||||
}
|
||||
|
||||
for _, image := range imagesList {
|
||||
fmt.Printf("[%s] Download image: %s\n", node.HostName, image.NewImage())
|
||||
mgr.Runner.RunCmd(fmt.Sprintf("sudo -E /bin/sh \"docker pull %s\"", image.NewImage()))
|
||||
}
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func SyncKubeBinaries(mgr *manager.Manager) error {
|
||||
mgr.Logger.Infoln("Syncing kube binaries……")
|
||||
mgr.Logger.Infoln("Syncing kube binaries")
|
||||
|
||||
return mgr.RunTaskOnK8sNodes(syncKubeBinaries, true)
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ func syncKubeBinaries(mgr *manager.Manager, node *kubekeyapi.HostCfg, conn ssh.C
|
|||
}
|
||||
|
||||
func ConfigureKubeletService(mgr *manager.Manager) error {
|
||||
mgr.Logger.Infoln("Configure kubelet service……")
|
||||
mgr.Logger.Infoln("Configure kubelet service")
|
||||
|
||||
return mgr.RunTaskOnAllNodes(setKubelet, true)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,16 +2,23 @@ package images
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
"github.com/pixiake/kubekey/pkg/util/ssh"
|
||||
"github.com/pkg/errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Image struct {
|
||||
Prefix string
|
||||
Repo string
|
||||
Tag string
|
||||
Group string
|
||||
Enable bool
|
||||
}
|
||||
|
||||
func (image *Image) NewImage() string {
|
||||
return fmt.Sprintf("%s%s/%s", image.Prefix, image.Repo, image.Tag)
|
||||
return fmt.Sprintf("%s%s:%s", image.Prefix, image.Repo, image.Tag)
|
||||
}
|
||||
|
||||
func GetImagePrefix(privateRegistry, ns string) string {
|
||||
|
|
@ -31,3 +38,51 @@ func GetImagePrefix(privateRegistry, ns string) string {
|
|||
}
|
||||
return prefix
|
||||
}
|
||||
|
||||
func PreDownloadImages(mgr *manager.Manager) error {
|
||||
mgr.Logger.Infoln("Pre-download images")
|
||||
|
||||
return mgr.RunTaskOnAllNodes(preDownloadImages, true)
|
||||
}
|
||||
|
||||
func preDownloadImages(mgr *manager.Manager, node *kubekeyapi.HostCfg, conn ssh.Connection) error {
|
||||
imagesList := []Image{
|
||||
{Prefix: GetImagePrefix(mgr.Cluster.Registry.PrivateRegistry, kubekeyapi.DefaultKubeImageRepo), Repo: "etcd", Tag: kubekeyapi.DefaultEtcdVersion, Group: "etcd", Enable: true},
|
||||
{Prefix: GetImagePrefix(mgr.Cluster.Registry.PrivateRegistry, kubekeyapi.DefaultKubeImageRepo), Repo: "pause", Tag: "3.1", Group: "k8s", Enable: true},
|
||||
{Prefix: GetImagePrefix(mgr.Cluster.Registry.PrivateRegistry, kubekeyapi.DefaultKubeImageRepo), Repo: "kube-apiserver", Tag: mgr.Cluster.KubeCluster.Version, Group: "master", Enable: true},
|
||||
{Prefix: GetImagePrefix(mgr.Cluster.Registry.PrivateRegistry, kubekeyapi.DefaultKubeImageRepo), Repo: "kube-controller-manager", Tag: mgr.Cluster.KubeCluster.Version, Group: "master", Enable: true},
|
||||
{Prefix: GetImagePrefix(mgr.Cluster.Registry.PrivateRegistry, kubekeyapi.DefaultKubeImageRepo), Repo: "kube-scheduler", Tag: mgr.Cluster.KubeCluster.Version, Group: "master", Enable: true},
|
||||
{Prefix: GetImagePrefix(mgr.Cluster.Registry.PrivateRegistry, kubekeyapi.DefaultKubeImageRepo), Repo: "kube-proxy", Tag: mgr.Cluster.KubeCluster.Version, Group: "k8s", Enable: true},
|
||||
{Prefix: GetImagePrefix(mgr.Cluster.Registry.PrivateRegistry, "coredns"), Repo: "coredns", Tag: "1.6.0", Group: "k8s", Enable: true},
|
||||
{Prefix: GetImagePrefix(mgr.Cluster.Registry.PrivateRegistry, "calico"), Repo: "node", Tag: kubekeyapi.DefaultCalicoVersion, Group: "k8s", Enable: strings.EqualFold(mgr.Cluster.Network.Plugin, "calico")},
|
||||
{Prefix: GetImagePrefix(mgr.Cluster.Registry.PrivateRegistry, "calico"), Repo: "pod2daemon-flexvol", Tag: kubekeyapi.DefaultCalicoVersion, Group: "k8s", Enable: strings.EqualFold(mgr.Cluster.Network.Plugin, "calico")},
|
||||
{Prefix: GetImagePrefix(mgr.Cluster.Registry.PrivateRegistry, "calico"), Repo: "cni", Tag: kubekeyapi.DefaultCalicoVersion, Group: "k8s", Enable: strings.EqualFold(mgr.Cluster.Network.Plugin, "calico")},
|
||||
{Prefix: GetImagePrefix(mgr.Cluster.Registry.PrivateRegistry, "calico"), Repo: "kube-controllers", Tag: kubekeyapi.DefaultCalicoVersion, Group: "k8s", Enable: strings.EqualFold(mgr.Cluster.Network.Plugin, "calico")},
|
||||
{Prefix: GetImagePrefix(mgr.Cluster.Registry.PrivateRegistry, "kubesphere"), Repo: "flannel", Tag: kubekeyapi.DefaultFlannelVersion, Group: "k8s", Enable: strings.EqualFold(mgr.Cluster.Network.Plugin, "flannel")},
|
||||
}
|
||||
|
||||
for _, image := range imagesList {
|
||||
if node.IsMaster && image.Group == "master" && image.Enable {
|
||||
fmt.Printf("[%s] Downloading image: %s\n", node.HostName, image.NewImage())
|
||||
_, err := mgr.Runner.RunCmd(fmt.Sprintf("sudo -E docker pull %s", image.NewImage()))
|
||||
if err != nil {
|
||||
return errors.Wrap(errors.WithStack(err), fmt.Sprintf("failed to download image: %s", image.NewImage()))
|
||||
}
|
||||
}
|
||||
if node.IsMaster && node.IsWorker && image.Group == "k8s" && image.Enable {
|
||||
fmt.Printf("[%s] Downloading image: %s\n", node.HostName, image.NewImage())
|
||||
_, err := mgr.Runner.RunCmd(fmt.Sprintf("sudo -E docker pull %s", image.NewImage()))
|
||||
if err != nil {
|
||||
return errors.Wrap(errors.WithStack(err), fmt.Sprintf("failed to download image: %s", image.NewImage()))
|
||||
}
|
||||
}
|
||||
if node.IsEtcd && image.Group == "etcd" && image.Enable {
|
||||
fmt.Printf("[%s] Downloading image: %s\n", node.HostName, image.NewImage())
|
||||
_, err := mgr.Runner.RunCmd(fmt.Sprintf("sudo -E docker pull %s", image.NewImage()))
|
||||
if err != nil {
|
||||
return errors.Wrap(errors.WithStack(err), fmt.Sprintf("failed to download image: %s", image.NewImage()))
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,14 @@ import (
|
|||
type Executor struct {
|
||||
cluster *kubekeyapi.K2ClusterSpec
|
||||
logger *log.Logger
|
||||
Verbose bool
|
||||
}
|
||||
|
||||
func NewExecutor(cluster *kubekeyapi.K2ClusterSpec, logger *log.Logger) *Executor {
|
||||
func NewExecutor(cluster *kubekeyapi.K2ClusterSpec, logger *log.Logger, verbose bool) *Executor {
|
||||
return &Executor{
|
||||
cluster: cluster,
|
||||
logger: logger,
|
||||
Verbose: verbose,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -39,7 +41,7 @@ func (executor *Executor) createManager() (*manager.Manager, error) {
|
|||
mgr.Cluster = executor.cluster
|
||||
mgr.Connector = ssh.NewConnector()
|
||||
mgr.Logger = executor.logger
|
||||
mgr.Verbose = true
|
||||
mgr.Verbose = executor.Verbose
|
||||
|
||||
return mgr, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
package install
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pixiake/kubekey/pkg/cluster/etcd"
|
||||
"github.com/pixiake/kubekey/pkg/cluster/kubernetes"
|
||||
"github.com/pixiake/kubekey/pkg/cluster/preinstall"
|
||||
"github.com/pixiake/kubekey/pkg/config"
|
||||
"github.com/pixiake/kubekey/pkg/container-engine/docker"
|
||||
"github.com/pixiake/kubekey/pkg/images"
|
||||
"github.com/pixiake/kubekey/pkg/plugins/network"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func CreateCluster(clusterCfgFile string, logger *log.Logger, addons string, pkg string) error {
|
||||
func CreateCluster(clusterCfgFile string, logger *log.Logger, addons, pkg string, verbose bool) error {
|
||||
cfg, err := config.ParseClusterCfg(clusterCfgFile, logger)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to download cluster config")
|
||||
}
|
||||
|
||||
out, _ := json.MarshalIndent(cfg, "", " ")
|
||||
fmt.Println(string(out))
|
||||
//out, _ := json.MarshalIndent(cfg, "", " ")
|
||||
//fmt.Println(string(out))
|
||||
if err := preinstall.Prepare(&cfg.Spec, logger); err != nil {
|
||||
return errors.Wrap(err, "failed to load kube binarys")
|
||||
}
|
||||
return NewExecutor(&cfg.Spec, logger).Execute()
|
||||
return NewExecutor(&cfg.Spec, logger, verbose).Execute()
|
||||
}
|
||||
|
||||
func ExecTasks(mgr *manager.Manager) error {
|
||||
|
|
@ -33,6 +33,7 @@ func ExecTasks(mgr *manager.Manager) error {
|
|||
{Task: preinstall.InitOS, ErrMsg: "failed to download kube binaries"},
|
||||
{Task: docker.InstallerDocker, ErrMsg: "failed to install docker"},
|
||||
{Task: kubernetes.SyncKubeBinaries, ErrMsg: "failed to sync kube binaries"},
|
||||
{Task: images.PreDownloadImages, ErrMsg: "failed to pre-download images"},
|
||||
{Task: etcd.GenerateEtcdCerts, ErrMsg: "failed to generate etcd certs"},
|
||||
{Task: etcd.SyncEtcdCertsToMaster, ErrMsg: "failed to sync etcd certs"},
|
||||
{Task: etcd.GenerateEtcdService, ErrMsg: "failed to start etcd cluster"},
|
||||
|
|
@ -48,5 +49,7 @@ func ExecTasks(mgr *manager.Manager) error {
|
|||
return errors.Wrap(err, step.ErrMsg)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("\n\033[1;36;46m%s\033[0m\n", "Successful.")
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func deployNetworkPlugin(mgr *manager.Manager, node *kubekeyapi.HostCfg, conn ss
|
|||
if mgr.Runner.Index == 0 {
|
||||
switch mgr.Cluster.Network.Plugin {
|
||||
case "calico":
|
||||
err := deployCalico(mgr)
|
||||
err := deployCalico(mgr, node)
|
||||
return err
|
||||
case "flannel":
|
||||
err := deployFlannel(mgr)
|
||||
|
|
@ -36,7 +36,7 @@ func deployNetworkPlugin(mgr *manager.Manager, node *kubekeyapi.HostCfg, conn ss
|
|||
return nil
|
||||
}
|
||||
|
||||
func deployCalico(mgr *manager.Manager) error {
|
||||
func deployCalico(mgr *manager.Manager, node *kubekeyapi.HostCfg) error {
|
||||
calicoFile, err := calico.GenerateCalicoFiles(mgr.Cluster)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -10,12 +10,14 @@ import (
|
|||
type Executor struct {
|
||||
cluster *kubekeyapi.K2ClusterSpec
|
||||
logger *log.Logger
|
||||
Verbose bool
|
||||
}
|
||||
|
||||
func NewExecutor(cluster *kubekeyapi.K2ClusterSpec, logger *log.Logger) *Executor {
|
||||
func NewExecutor(cluster *kubekeyapi.K2ClusterSpec, logger *log.Logger, verbose bool) *Executor {
|
||||
return &Executor{
|
||||
cluster: cluster,
|
||||
logger: logger,
|
||||
Verbose: verbose,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -39,7 +41,7 @@ func (executor *Executor) createManager() (*manager.Manager, error) {
|
|||
mgr.Cluster = executor.cluster
|
||||
mgr.Connector = ssh.NewConnector()
|
||||
mgr.Logger = executor.logger
|
||||
mgr.Verbose = true
|
||||
mgr.Verbose = executor.Verbose
|
||||
|
||||
return mgr, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package scale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pixiake/kubekey/pkg/cluster/kubernetes"
|
||||
"github.com/pixiake/kubekey/pkg/cluster/preinstall"
|
||||
|
|
@ -12,18 +11,18 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func ScaleCluster(clusterCfgFile string, logger *log.Logger, pkg string) error {
|
||||
func ScaleCluster(clusterCfgFile string, logger *log.Logger, pkg string, verbose bool) error {
|
||||
cfg, err := config.ParseClusterCfg(clusterCfgFile, logger)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to download cluster config")
|
||||
}
|
||||
|
||||
out, _ := json.MarshalIndent(cfg, "", " ")
|
||||
fmt.Println(string(out))
|
||||
//out, _ := json.MarshalIndent(cfg, "", " ")
|
||||
//fmt.Println(string(out))
|
||||
if err := preinstall.Prepare(&cfg.Spec, logger); err != nil {
|
||||
return errors.Wrap(err, "failed to load kube binarys")
|
||||
}
|
||||
return NewExecutor(&cfg.Spec, logger).Execute()
|
||||
return NewExecutor(&cfg.Spec, logger, verbose).Execute()
|
||||
}
|
||||
|
||||
func ExecTasks(mgr *manager.Manager) error {
|
||||
|
|
@ -41,5 +40,7 @@ func ExecTasks(mgr *manager.Manager) error {
|
|||
return errors.Wrap(err, task.ErrMsg)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("\n\033[1;36;40m%s\033[0m\n", "Successful.")
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ func (r *Runner) RunCmd(cmd string) (string, error) {
|
|||
}
|
||||
|
||||
if output != "" {
|
||||
if strings.Contains(cmd, "base64") && strings.Contains(cmd, "--wrap=0") || strings.Contains(cmd, "make-ssl-etcd.sh") || strings.Contains(cmd, "docker-install.sh") {
|
||||
if strings.Contains(cmd, "base64") && strings.Contains(cmd, "--wrap=0") || strings.Contains(cmd, "make-ssl-etcd.sh") || strings.Contains(cmd, "docker-install.sh") || strings.Contains(cmd, "docker pull") {
|
||||
} else {
|
||||
fmt.Printf("[%s %s] MSG:\n", r.Host.HostName, r.Host.SSHAddress)
|
||||
fmt.Println(output)
|
||||
|
|
|
|||
Loading…
Reference in New Issue