提交 d28cea77 编写于 作者: B Brandon L. Gauthier

Added --keep-context flag for 'minikube start'

上级 e52833a1
......@@ -50,6 +50,7 @@ const (
networkPlugin = "network-plugin"
hypervVirtualSwitch = "hyperv-virtual-switch"
kvmNetwork = "kvm-network"
keepContext = "keep-context"
)
var (
......@@ -136,15 +137,21 @@ func runStart(cmd *cobra.Command, args []string) {
kubeHost = strings.Replace(kubeHost, ":2376", ":"+strconv.Itoa(constants.APIServerPort), -1)
// setup kubeconfig
keepContext := viper.GetBool(keepContext)
name := constants.MinikubeContext
certAuth := constants.MakeMiniPath("ca.crt")
clientCert := constants.MakeMiniPath("apiserver.crt")
clientKey := constants.MakeMiniPath("apiserver.key")
if err := setupKubeconfig(name, kubeHost, certAuth, clientCert, clientKey); err != nil {
if err := setupKubeconfig(name, kubeHost, certAuth, clientCert, clientKey, keepContext); err != nil {
glog.Errorln("Error setting up kubeconfig: ", err)
cmdUtil.MaybeReportErrorAndExit(err)
}
fmt.Println("Kubectl is now configured to use the cluster.")
if keepContext {
fmt.Printf("The local Kubernetes cluster has started. The kubectl context has not been alterted, kubectl will require \"--context=%s\" to use the local Kubernetes cluster.\n", name)
} else {
fmt.Println("Kubectl is now configured to use the cluster.")
}
}
func calculateDiskSizeInMB(humanReadableDiskSize string) int {
......@@ -158,7 +165,7 @@ func calculateDiskSizeInMB(humanReadableDiskSize string) int {
// setupKubeconfig reads config from disk, adds the minikube settings, and writes it back.
// activeContext is true when minikube is the CurrentContext
// If no CurrentContext is set, the given name will be used.
func setupKubeconfig(name, server, certAuth, cliCert, cliKey string) error {
func setupKubeconfig(name, server, certAuth, cliCert, cliKey string, keepContext bool) error {
configEnv := os.Getenv(constants.KubeconfigEnvVar)
var configFile string
......@@ -196,8 +203,10 @@ func setupKubeconfig(name, server, certAuth, cliCert, cliKey string) error {
context.AuthInfo = userName
config.Contexts[contextName] = context
// Always set current context to minikube.
config.CurrentContext = contextName
// Only set current context to minikube if the user has not used the keepContext flag
if keepContext != true {
config.CurrentContext = contextName
}
// write back to disk
if err := kubeconfig.WriteConfig(config, configFile); err != nil {
......@@ -207,6 +216,7 @@ func setupKubeconfig(name, server, certAuth, cliCert, cliKey string) error {
}
func init() {
startCmd.Flags().Bool(keepContext, constants.DefaultKeepContext, "This will keep the existing kubectl context and will create a minikube context.")
startCmd.Flags().String(isoURL, constants.DefaultIsoUrl, "Location of the minikube iso")
startCmd.Flags().String(vmDriver, constants.DefaultVMDriver, fmt.Sprintf("VM driver is one of: %v", constants.SupportedVMDrivers))
startCmd.Flags().Int(memory, constants.DefaultMemory, "Amount of RAM allocated to the minikube VM")
......
......@@ -825,6 +825,8 @@ _minikube_start()
local_nonpersistent_flags+=("--insecure-registry=")
flags+=("--iso-url=")
local_nonpersistent_flags+=("--iso-url=")
flags+=("--keep-context")
local_nonpersistent_flags+=("--keep-context")
flags+=("--kubernetes-version=")
local_nonpersistent_flags+=("--kubernetes-version=")
flags+=("--kvm-network=")
......
......@@ -26,6 +26,7 @@ minikube start
--hyperv-virtual-switch string The hyperv virtual switch name. Defaults to first found. (only supported with HyperV driver)
--insecure-registry stringSlice Insecure Docker registries to pass to the Docker daemon
--iso-url string Location of the minikube iso (default "https://storage.googleapis.com/minikube/iso/minikube-v1.0.1.iso")
--keep-context This will keep the existing kubectl context and will create a minikube context.
--kubernetes-version string The kubernetes version that the minikube VM will use (ex: v1.2.3)
OR a URI which contains a localkube binary (ex: https://storage.googleapis.com/minikube/k8sReleases/v1.3.0/localkube-linux-amd64) (default "v1.5.1")
--kvm-network string The KVM network name. (only supported with KVM driver) (default "default")
......
......@@ -59,6 +59,7 @@ var LogFlags = [...]string{
}
const (
DefaultKeepContext = false
DefaultIsoUrl = "https://storage.googleapis.com/minikube/iso/minikube-v1.0.1.iso"
ShaSuffix = ".sha256"
DefaultIsoShaUrl = DefaultIsoUrl + ShaSuffix
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册