Skip to content

Commit

Permalink
Add --control-planes to start
Browse files Browse the repository at this point in the history
Signed-off-by: Ling Samuel <lingsamuelgrace@gmail.com>
  • Loading branch information
lingsamuel committed Dec 24, 2020
1 parent 1c3e096 commit 03176dd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
3 changes: 1 addition & 2 deletions cmd/minikube/cmd/node_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/spf13/viper"
"k8s.io/minikube/pkg/minikube/cni"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/mustload"
Expand Down Expand Up @@ -68,7 +67,7 @@ var nodeAddCmd = &cobra.Command{
}

if n.ControlPlane {
n.Port = constants.APIServerPort
n.Port = cc.KubernetesConfig.NodePort
}

// Make sure to decrease the default amount of memory we use per VM if this is the first worker node
Expand Down
12 changes: 12 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ func platform() string {
func runStart(cmd *cobra.Command, args []string) {
register.SetEventLogPath(localpath.EventLog(ClusterFlagValue()))

controlPlanesNum := viper.GetInt(controlPlanes)
nodesNum := viper.GetInt(nodes)
if controlPlanesNum > nodesNum {
out.WarningT(fmt.Sprintf("control planes number %v larger than nodes number %v, enlarge nodes to %v.", controlPlanesNum, nodesNum, controlPlanesNum))
viper.Set(nodes, controlPlanesNum)
}

out.SetJSON(outputFormat == "json")
if err := pkgtrace.Initialize(viper.GetString(trace)); err != nil {
exit.Message(reason.Usage, "error initializing tracing: {{.Error}}", out.V{"Error": err.Error()})
Expand Down Expand Up @@ -359,6 +366,7 @@ func startWithDriver(cmd *cobra.Command, starter node.Starter, existing *config.
}
}

numControlPlanes := viper.GetInt(controlPlanes)
numNodes := viper.GetInt(nodes)
if existing != nil {
if numNodes > 1 {
Expand All @@ -381,6 +389,10 @@ func startWithDriver(cmd *cobra.Command, starter node.Starter, existing *config.
PrimaryControlPlane: false,
KubernetesVersion: starter.Cfg.KubernetesConfig.KubernetesVersion,
}
if i < numControlPlanes {
n.ControlPlane = true
n.Port = starter.Cfg.KubernetesConfig.NodePort
}
out.Ln("") // extra newline for clarity on the command line
err := node.Add(starter.Cfg, n, viper.GetBool(deleteOnFailure))
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const (
hostOnlyNicType = "host-only-nic-type"
natNicType = "nat-nic-type"
nodes = "nodes"
controlPlanes = "control-planes"
preload = "preload"
deleteOnFailure = "delete-on-failure"
forceSystemd = "force-systemd"
Expand Down Expand Up @@ -150,6 +151,7 @@ func initMinikubeFlags() {
startCmd.Flags().Bool(autoUpdate, true, "If set, automatically updates drivers to the latest version. Defaults to true.")
startCmd.Flags().Bool(installAddons, true, "If set, install addons. Defaults to true.")
startCmd.Flags().IntP(nodes, "n", 1, "The number of nodes to spin up. Defaults to 1.")
startCmd.Flags().Int(controlPlanes, 1, "The number of control planes to spin up. Defaults to 1.")
startCmd.Flags().Bool(preload, true, "If set, download tarball of preloaded images if available to improve start time. Defaults to true.")
startCmd.Flags().Bool(deleteOnFailure, false, "If set, delete the current cluster if start fails and try again. Defaults to false.")
startCmd.Flags().Bool(forceSystemd, false, "If set, force the container runtime to use sytemd as cgroup manager. Currently available for docker and crio. Defaults to false.")
Expand Down
1 change: 1 addition & 0 deletions site/content/en/docs/commands/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ minikube start [flags]
--cache-images If true, cache docker images for the current bootstrapper and load them into the machine. Always false with --driver=none. (default true)
--cni string CNI plug-in to use. Valid options: auto, bridge, calico, cilium, flannel, kindnet, or path to a CNI manifest (default: auto)
--container-runtime string The container runtime to be used (docker, cri-o, containerd). (default "docker")
--control-planes int The number of control planes to spin up. Defaults to 1. (default 1)
--cpus int Number of CPUs allocated to Kubernetes. (default 2)
--cri-socket string The cri socket path to be used.
--delete-on-failure If set, delete the current cluster if start fails and try again. Defaults to false.
Expand Down

0 comments on commit 03176dd

Please sign in to comment.