2017-11-28 11:26:15 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2018-01-09 22:10:56 +00:00
|
|
|
"context"
|
2017-11-28 11:26:15 +00:00
|
|
|
"fmt"
|
2018-11-07 00:24:49 +00:00
|
|
|
"os"
|
2018-04-18 06:04:30 +00:00
|
|
|
"strings"
|
2018-07-10 19:21:27 +00:00
|
|
|
"time"
|
2017-11-28 11:26:15 +00:00
|
|
|
|
|
|
|
"github.com/rancher/rke/cluster"
|
2018-07-10 19:21:27 +00:00
|
|
|
"github.com/rancher/rke/dind"
|
2017-12-11 18:28:08 +00:00
|
|
|
"github.com/rancher/rke/hosts"
|
2018-01-09 22:10:56 +00:00
|
|
|
"github.com/rancher/rke/log"
|
2017-11-28 11:26:15 +00:00
|
|
|
"github.com/rancher/rke/pki"
|
2017-12-16 03:38:15 +00:00
|
|
|
"github.com/rancher/types/apis/management.cattle.io/v3"
|
2018-11-07 00:24:49 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-11-28 11:26:15 +00:00
|
|
|
"github.com/urfave/cli"
|
2018-11-03 01:45:23 +00:00
|
|
|
"k8s.io/client-go/util/cert"
|
2017-11-28 11:26:15 +00:00
|
|
|
)
|
|
|
|
|
2018-07-10 19:21:27 +00:00
|
|
|
const DINDWaitTime = 3
|
|
|
|
|
2017-11-28 11:26:15 +00:00
|
|
|
func UpCommand() cli.Command {
|
|
|
|
upFlags := []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "config",
|
|
|
|
Usage: "Specify an alternate cluster YAML file",
|
2018-02-06 19:25:54 +00:00
|
|
|
Value: pki.ClusterConfig,
|
2017-11-28 11:26:15 +00:00
|
|
|
EnvVar: "RKE_CONFIG",
|
|
|
|
},
|
2017-12-22 01:01:53 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "local",
|
|
|
|
Usage: "Deploy Kubernetes cluster locally",
|
|
|
|
},
|
2018-07-10 19:21:27 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "dind",
|
|
|
|
Usage: "Deploy Kubernetes cluster in docker containers (experimental)",
|
|
|
|
},
|
2018-09-10 23:17:45 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "dind-storage-driver",
|
|
|
|
Usage: "Storage driver for the docker in docker containers (experimental)",
|
|
|
|
},
|
2018-03-20 12:56:49 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "update-only",
|
|
|
|
Usage: "Skip idempotent deployment of control and etcd plane",
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "disable-port-check",
|
|
|
|
Usage: "Disable port check validation between nodes",
|
|
|
|
},
|
2018-10-31 23:11:57 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "init",
|
2018-11-07 23:54:08 +00:00
|
|
|
Usage: "Initiate RKE cluster",
|
2018-10-31 23:11:57 +00:00
|
|
|
},
|
2017-11-28 11:26:15 +00:00
|
|
|
}
|
2018-03-06 00:52:43 +00:00
|
|
|
|
2018-05-15 17:35:52 +00:00
|
|
|
upFlags = append(upFlags, commonFlags...)
|
2018-03-06 00:52:43 +00:00
|
|
|
|
2017-11-28 11:26:15 +00:00
|
|
|
return cli.Command{
|
|
|
|
Name: "up",
|
|
|
|
Usage: "Bring the cluster up",
|
|
|
|
Action: clusterUpFromCli,
|
|
|
|
Flags: upFlags,
|
|
|
|
}
|
|
|
|
}
|
2018-11-07 23:54:08 +00:00
|
|
|
|
|
|
|
func doUpgradeLegacyCluster(ctx context.Context, kubeCluster *cluster.Cluster, fullState *cluster.FullState) error {
|
2018-11-07 00:24:49 +00:00
|
|
|
if _, err := os.Stat(kubeCluster.LocalKubeConfigPath); os.IsNotExist(err) {
|
|
|
|
// there is no kubeconfig. This is a new cluster
|
|
|
|
logrus.Debug("[state] local kubeconfig not found, this is a new cluster")
|
|
|
|
return nil
|
|
|
|
}
|
2018-11-07 23:54:08 +00:00
|
|
|
if _, err := os.Stat(kubeCluster.StateFilePath); err == nil {
|
2018-11-07 00:24:49 +00:00
|
|
|
// this cluster has a previous state, I don't need to upgrade!
|
|
|
|
logrus.Debug("[state] previous state found, this is not a legacy cluster")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
// We have a kubeconfig and no current state. This is a legacy cluster or a new cluster with old kubeconfig
|
|
|
|
// let's try to upgrade
|
|
|
|
log.Infof(ctx, "[state] Possible legacy cluster detected, trying to upgrade")
|
|
|
|
if err := cluster.RebuildKubeconfig(ctx, kubeCluster); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-11-07 23:54:08 +00:00
|
|
|
recoveredCluster, err := cluster.GetStateFromKubernetes(ctx, kubeCluster)
|
2018-11-07 00:24:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// if we found a recovered cluster, we will need override the current state
|
|
|
|
if recoveredCluster != nil {
|
2018-11-07 23:54:08 +00:00
|
|
|
recoveredCerts, err := cluster.GetClusterCertsFromKubernetes(ctx, kubeCluster)
|
2018-11-07 00:24:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fullState.CurrentState.RancherKubernetesEngineConfig = recoveredCluster.RancherKubernetesEngineConfig.DeepCopy()
|
2018-11-07 23:54:08 +00:00
|
|
|
fullState.CurrentState.CertificatesBundle = recoveredCerts
|
2017-11-28 11:26:15 +00:00
|
|
|
|
2018-11-07 00:24:49 +00:00
|
|
|
// we don't want to regenerate certificates
|
2018-11-07 23:54:08 +00:00
|
|
|
fullState.DesiredState.CertificatesBundle = recoveredCerts
|
|
|
|
return fullState.WriteStateFile(ctx, kubeCluster.StateFilePath)
|
2018-11-07 00:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-11-07 23:54:08 +00:00
|
|
|
func ClusterUp(ctx context.Context, dialersOptions hosts.DialersOptions, flags cluster.ExternalFlags) (string, string, string, string, map[string]pki.CertificatePKI, error) {
|
2017-11-28 11:26:15 +00:00
|
|
|
var APIURL, caCrt, clientCert, clientKey string
|
2018-11-02 05:53:29 +00:00
|
|
|
|
2018-11-07 23:54:08 +00:00
|
|
|
clusterState, err := cluster.ReadStateFile(ctx, cluster.GetStateFilePath(flags.ClusterFilePath, flags.ConfigDir))
|
2018-11-02 05:53:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
|
|
|
}
|
2018-11-03 01:45:23 +00:00
|
|
|
|
2018-11-07 23:54:08 +00:00
|
|
|
kubeCluster, err := cluster.InitClusterObject(ctx, clusterState.DesiredState.RancherKubernetesEngineConfig.DeepCopy(), flags)
|
2018-11-02 05:53:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
|
|
|
}
|
2018-12-20 22:01:42 +00:00
|
|
|
// check if rotate certificates is triggered
|
|
|
|
if kubeCluster.RancherKubernetesEngineConfig.RotateCertificates != nil {
|
|
|
|
return rebuildClusterWithRotatedCertificates(ctx, dialersOptions, flags)
|
|
|
|
}
|
2018-11-03 01:45:23 +00:00
|
|
|
|
2018-12-20 22:01:42 +00:00
|
|
|
log.Infof(ctx, "Building Kubernetes cluster")
|
2018-11-07 23:54:08 +00:00
|
|
|
err = kubeCluster.SetupDialers(ctx, dialersOptions)
|
2017-11-28 11:26:15 +00:00
|
|
|
if err != nil {
|
2018-04-02 11:02:00 +00:00
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
2017-11-28 11:26:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-07 23:54:08 +00:00
|
|
|
err = kubeCluster.TunnelHosts(ctx, flags)
|
2017-11-28 11:26:15 +00:00
|
|
|
if err != nil {
|
2018-04-02 11:02:00 +00:00
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
2017-11-28 11:26:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-07 23:54:08 +00:00
|
|
|
currentCluster, err := kubeCluster.GetClusterState(ctx, clusterState)
|
2018-01-18 20:41:04 +00:00
|
|
|
if err != nil {
|
2018-04-02 11:02:00 +00:00
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
2018-01-16 18:29:09 +00:00
|
|
|
}
|
2018-11-03 01:45:23 +00:00
|
|
|
|
2018-11-07 23:54:08 +00:00
|
|
|
if !flags.DisablePortCheck {
|
2018-03-20 12:56:49 +00:00
|
|
|
if err = kubeCluster.CheckClusterPorts(ctx, currentCluster); err != nil {
|
2018-04-02 11:02:00 +00:00
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
2018-03-20 12:56:49 +00:00
|
|
|
}
|
2017-11-28 11:26:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-03 01:45:23 +00:00
|
|
|
err = cluster.SetUpAuthentication(ctx, kubeCluster, currentCluster, clusterState)
|
2017-11-28 11:26:15 +00:00
|
|
|
if err != nil {
|
2018-04-02 11:02:00 +00:00
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
2017-11-28 11:26:15 +00:00
|
|
|
}
|
2018-11-03 01:45:23 +00:00
|
|
|
if len(kubeCluster.ControlPlaneHosts) > 0 {
|
|
|
|
APIURL = fmt.Sprintf("https://" + kubeCluster.ControlPlaneHosts[0].Address + ":6443")
|
|
|
|
}
|
|
|
|
clientCert = string(cert.EncodeCertPEM(kubeCluster.Certificates[pki.KubeAdminCertName].Certificate))
|
|
|
|
clientKey = string(cert.EncodePrivateKeyPEM(kubeCluster.Certificates[pki.KubeAdminCertName].Key))
|
|
|
|
caCrt = string(cert.EncodeCertPEM(kubeCluster.Certificates[pki.CACertName].Certificate))
|
2018-11-02 05:53:29 +00:00
|
|
|
|
2018-11-03 01:45:23 +00:00
|
|
|
// moved deploying certs before reconcile to remove all unneeded certs generation from reconcile
|
|
|
|
err = kubeCluster.SetUpHosts(ctx, false)
|
|
|
|
if err != nil {
|
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
|
|
|
}
|
2017-11-28 11:26:15 +00:00
|
|
|
|
2018-11-07 23:54:08 +00:00
|
|
|
err = cluster.ReconcileCluster(ctx, kubeCluster, currentCluster, flags)
|
2017-11-28 11:26:15 +00:00
|
|
|
if err != nil {
|
2018-04-02 11:02:00 +00:00
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
2017-11-28 11:26:15 +00:00
|
|
|
}
|
2018-10-10 17:19:21 +00:00
|
|
|
// update APIURL after reconcile
|
|
|
|
if len(kubeCluster.ControlPlaneHosts) > 0 {
|
|
|
|
APIURL = fmt.Sprintf("https://" + kubeCluster.ControlPlaneHosts[0].Address + ":6443")
|
|
|
|
}
|
2018-11-02 05:53:29 +00:00
|
|
|
|
2018-02-01 21:43:09 +00:00
|
|
|
if err := kubeCluster.PrePullK8sImages(ctx); err != nil {
|
2018-04-02 11:02:00 +00:00
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
2018-02-01 21:43:09 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 22:10:56 +00:00
|
|
|
err = kubeCluster.DeployControlPlane(ctx)
|
2017-11-28 11:26:15 +00:00
|
|
|
if err != nil {
|
2018-04-02 11:02:00 +00:00
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
2017-11-28 11:26:15 +00:00
|
|
|
}
|
|
|
|
|
2018-02-26 21:14:04 +00:00
|
|
|
// Apply Authz configuration after deploying controlplane
|
2018-11-07 23:54:08 +00:00
|
|
|
err = cluster.ApplyAuthzResources(ctx, kubeCluster.RancherKubernetesEngineConfig, flags, dialersOptions)
|
2018-02-26 21:14:04 +00:00
|
|
|
if err != nil {
|
2018-04-02 11:02:00 +00:00
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
2018-02-26 21:14:04 +00:00
|
|
|
}
|
|
|
|
|
2018-11-07 23:54:08 +00:00
|
|
|
err = kubeCluster.UpdateClusterCurrentState(ctx, clusterState)
|
2017-11-28 11:26:15 +00:00
|
|
|
if err != nil {
|
2018-04-02 11:02:00 +00:00
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
2017-11-28 11:26:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-07 23:54:08 +00:00
|
|
|
err = cluster.SaveFullStateToKubernetes(ctx, kubeCluster, clusterState)
|
2018-11-07 00:24:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
|
|
|
}
|
|
|
|
|
2018-01-09 22:10:56 +00:00
|
|
|
err = kubeCluster.DeployWorkerPlane(ctx)
|
2017-12-26 22:07:25 +00:00
|
|
|
if err != nil {
|
2018-04-02 11:02:00 +00:00
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
2017-12-26 22:07:25 +00:00
|
|
|
}
|
|
|
|
|
2018-03-21 17:20:58 +00:00
|
|
|
if err = kubeCluster.CleanDeadLogs(ctx); err != nil {
|
2018-04-02 11:02:00 +00:00
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
2018-03-21 17:20:58 +00:00
|
|
|
}
|
|
|
|
|
2018-09-26 23:26:20 +00:00
|
|
|
err = kubeCluster.SyncLabelsAndTaints(ctx, currentCluster)
|
2017-11-28 11:26:15 +00:00
|
|
|
if err != nil {
|
2018-04-02 11:02:00 +00:00
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
2017-11-28 11:26:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-07 23:54:08 +00:00
|
|
|
err = cluster.ConfigureCluster(ctx, kubeCluster.RancherKubernetesEngineConfig, kubeCluster.Certificates, flags, dialersOptions, false)
|
2017-11-28 11:26:15 +00:00
|
|
|
if err != nil {
|
2018-04-02 11:02:00 +00:00
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
2017-11-28 11:26:15 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 06:04:30 +00:00
|
|
|
if err := checkAllIncluded(kubeCluster); err != nil {
|
|
|
|
return APIURL, caCrt, clientCert, clientKey, nil, err
|
|
|
|
}
|
|
|
|
|
2018-01-09 22:10:56 +00:00
|
|
|
log.Infof(ctx, "Finished building Kubernetes cluster successfully")
|
2018-04-02 11:02:00 +00:00
|
|
|
return APIURL, caCrt, clientCert, clientKey, kubeCluster.Certificates, nil
|
2017-11-28 11:26:15 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 06:04:30 +00:00
|
|
|
func checkAllIncluded(cluster *cluster.Cluster) error {
|
|
|
|
if len(cluster.InactiveHosts) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var names []string
|
|
|
|
for _, host := range cluster.InactiveHosts {
|
|
|
|
names = append(names, host.Address)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("Provisioning incomplete, host(s) [%s] skipped because they could not be contacted", strings.Join(names, ","))
|
|
|
|
}
|
|
|
|
|
2017-11-28 11:26:15 +00:00
|
|
|
func clusterUpFromCli(ctx *cli.Context) error {
|
2018-01-15 04:36:28 +00:00
|
|
|
if ctx.Bool("local") {
|
|
|
|
return clusterUpLocal(ctx)
|
|
|
|
}
|
2018-07-10 19:21:27 +00:00
|
|
|
if ctx.Bool("dind") {
|
|
|
|
return clusterUpDind(ctx)
|
|
|
|
}
|
2017-12-16 03:38:15 +00:00
|
|
|
clusterFile, filePath, err := resolveClusterFile(ctx)
|
2017-11-28 11:26:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Failed to resolve cluster file: %v", err)
|
|
|
|
}
|
2017-12-16 03:38:15 +00:00
|
|
|
|
|
|
|
rkeConfig, err := cluster.ParseConfig(clusterFile)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Failed to parse cluster file: %v", err)
|
|
|
|
}
|
2018-03-06 00:52:43 +00:00
|
|
|
|
|
|
|
rkeConfig, err = setOptionsFromCLI(ctx, rkeConfig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-03-20 12:56:49 +00:00
|
|
|
updateOnly := ctx.Bool("update-only")
|
|
|
|
disablePortCheck := ctx.Bool("disable-port-check")
|
2018-11-07 23:54:08 +00:00
|
|
|
// setting up the flags
|
2018-11-12 23:24:59 +00:00
|
|
|
flags := cluster.GetExternalFlags(false, updateOnly, disablePortCheck, "", filePath)
|
2018-11-07 23:54:08 +00:00
|
|
|
|
2018-10-31 23:11:57 +00:00
|
|
|
if ctx.Bool("init") {
|
2018-11-07 23:54:08 +00:00
|
|
|
return ClusterInit(context.Background(), rkeConfig, hosts.DialersOptions{}, flags)
|
2018-10-31 23:11:57 +00:00
|
|
|
}
|
2018-11-07 23:54:08 +00:00
|
|
|
if err := ClusterInit(context.Background(), rkeConfig, hosts.DialersOptions{}, flags); err != nil {
|
2018-11-02 05:53:29 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-11-07 23:54:08 +00:00
|
|
|
|
|
|
|
_, _, _, _, _, err = ClusterUp(context.Background(), hosts.DialersOptions{}, flags)
|
2018-01-15 04:36:28 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func clusterUpLocal(ctx *cli.Context) error {
|
|
|
|
var rkeConfig *v3.RancherKubernetesEngineConfig
|
|
|
|
clusterFile, filePath, err := resolveClusterFile(ctx)
|
|
|
|
if err != nil {
|
|
|
|
log.Infof(context.Background(), "Failed to resolve cluster file, using default cluster instead")
|
|
|
|
rkeConfig = cluster.GetLocalRKEConfig()
|
|
|
|
} else {
|
|
|
|
rkeConfig, err = cluster.ParseConfig(clusterFile)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Failed to parse cluster file: %v", err)
|
|
|
|
}
|
2017-12-22 01:01:53 +00:00
|
|
|
rkeConfig.Nodes = []v3.RKEConfigNode{*cluster.GetLocalRKENodeConfig()}
|
|
|
|
}
|
2018-05-15 17:35:52 +00:00
|
|
|
|
|
|
|
rkeConfig.IgnoreDockerVersion = ctx.Bool("ignore-docker-version")
|
|
|
|
|
2018-11-07 23:54:08 +00:00
|
|
|
// setting up the dialers
|
|
|
|
dialers := hosts.GetDialerOptions(nil, hosts.LocalHealthcheckFactory, nil)
|
|
|
|
// setting up the flags
|
2018-11-12 23:24:59 +00:00
|
|
|
flags := cluster.GetExternalFlags(true, false, false, "", filePath)
|
2018-11-07 23:54:08 +00:00
|
|
|
|
|
|
|
if ctx.Bool("init") {
|
|
|
|
return ClusterInit(context.Background(), rkeConfig, dialers, flags)
|
|
|
|
}
|
|
|
|
if err := ClusterInit(context.Background(), rkeConfig, dialers, flags); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, _, _, _, _, err = ClusterUp(context.Background(), dialers, flags)
|
2017-11-28 11:26:15 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-07-10 19:21:27 +00:00
|
|
|
|
|
|
|
func clusterUpDind(ctx *cli.Context) error {
|
|
|
|
// get dind config
|
2018-11-07 23:54:08 +00:00
|
|
|
rkeConfig, disablePortCheck, dindStorageDriver, filePath, err := getDindConfig(ctx)
|
2018-07-10 19:21:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// setup dind environment
|
2018-09-10 23:17:45 +00:00
|
|
|
if err = createDINDEnv(context.Background(), rkeConfig, dindStorageDriver); err != nil {
|
2018-07-10 19:21:27 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-11-07 23:54:08 +00:00
|
|
|
|
|
|
|
// setting up the dialers
|
|
|
|
dialers := hosts.GetDialerOptions(hosts.DindConnFactory, hosts.DindHealthcheckConnFactory, nil)
|
|
|
|
// setting up flags
|
2018-11-12 23:24:59 +00:00
|
|
|
flags := cluster.GetExternalFlags(false, false, disablePortCheck, "", filePath)
|
2019-01-07 19:52:57 +00:00
|
|
|
flags.DinD = true
|
2018-11-07 23:54:08 +00:00
|
|
|
|
|
|
|
if ctx.Bool("init") {
|
|
|
|
return ClusterInit(context.Background(), rkeConfig, dialers, flags)
|
|
|
|
}
|
|
|
|
if err := ClusterInit(context.Background(), rkeConfig, dialers, flags); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-07-10 19:21:27 +00:00
|
|
|
// start cluster
|
2018-11-07 23:54:08 +00:00
|
|
|
_, _, _, _, _, err = ClusterUp(context.Background(), dialers, flags)
|
2018-07-10 19:21:27 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-11-07 23:54:08 +00:00
|
|
|
func getDindConfig(ctx *cli.Context) (*v3.RancherKubernetesEngineConfig, bool, string, string, error) {
|
2018-07-10 19:21:27 +00:00
|
|
|
disablePortCheck := ctx.Bool("disable-port-check")
|
2018-09-10 23:17:45 +00:00
|
|
|
dindStorageDriver := ctx.String("dind-storage-driver")
|
|
|
|
|
2018-07-10 19:21:27 +00:00
|
|
|
clusterFile, filePath, err := resolveClusterFile(ctx)
|
|
|
|
if err != nil {
|
2018-11-07 23:54:08 +00:00
|
|
|
return nil, disablePortCheck, "", "", fmt.Errorf("Failed to resolve cluster file: %v", err)
|
2018-07-10 19:21:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rkeConfig, err := cluster.ParseConfig(clusterFile)
|
|
|
|
if err != nil {
|
2018-11-07 23:54:08 +00:00
|
|
|
return nil, disablePortCheck, "", "", fmt.Errorf("Failed to parse cluster file: %v", err)
|
2018-07-10 19:21:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rkeConfig, err = setOptionsFromCLI(ctx, rkeConfig)
|
|
|
|
if err != nil {
|
2018-11-07 23:54:08 +00:00
|
|
|
return nil, disablePortCheck, "", "", err
|
2018-07-10 19:21:27 +00:00
|
|
|
}
|
|
|
|
// Setting conntrack max for kubeproxy to 0
|
|
|
|
if rkeConfig.Services.Kubeproxy.ExtraArgs == nil {
|
|
|
|
rkeConfig.Services.Kubeproxy.ExtraArgs = make(map[string]string)
|
|
|
|
}
|
|
|
|
rkeConfig.Services.Kubeproxy.ExtraArgs["conntrack-max-per-core"] = "0"
|
|
|
|
|
2018-11-07 23:54:08 +00:00
|
|
|
return rkeConfig, disablePortCheck, dindStorageDriver, filePath, nil
|
2018-07-10 19:21:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-10 23:17:45 +00:00
|
|
|
func createDINDEnv(ctx context.Context, rkeConfig *v3.RancherKubernetesEngineConfig, dindStorageDriver string) error {
|
2018-08-14 22:04:56 +00:00
|
|
|
for i := range rkeConfig.Nodes {
|
2018-09-10 23:17:45 +00:00
|
|
|
address, err := dind.StartUpDindContainer(ctx, rkeConfig.Nodes[i].Address, dind.DINDNetwork, dindStorageDriver)
|
2018-08-14 22:04:56 +00:00
|
|
|
if err != nil {
|
2018-07-10 19:21:27 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-08-14 22:04:56 +00:00
|
|
|
if rkeConfig.Nodes[i].HostnameOverride == "" {
|
|
|
|
rkeConfig.Nodes[i].HostnameOverride = rkeConfig.Nodes[i].Address
|
|
|
|
}
|
|
|
|
rkeConfig.Nodes[i].Address = address
|
2018-07-10 19:21:27 +00:00
|
|
|
}
|
|
|
|
time.Sleep(DINDWaitTime * time.Second)
|
|
|
|
return nil
|
|
|
|
}
|