Skip to content

Commit

Permalink
Merge pull request #9506 from prezha/add-namespace-support
Browse files Browse the repository at this point in the history
new flag  --namespace
  • Loading branch information
medyagh authored Nov 6, 2020
2 parents 7747655 + 15c8fa9 commit 3bb967a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func showKubectlInfo(kcs *kubeconfig.Settings, k8sVersion string, machineName st
if kcs.KeepContext {
out.T(style.Kubectl, "To connect to this cluster, use: --context={{.name}}", out.V{"name": kcs.ClusterName})
} else {
out.T(style.Ready, `Done! kubectl is now configured to use "{{.name}}" by default`, out.V{"name": machineName})
out.T(style.Ready, `Done! kubectl is now configured to use "{{.name}}" cluster and "{{.ns}}" namespace by default`, out.V{"name": machineName, "ns": kcs.Namespace})
}
}()

Expand Down
7 changes: 7 additions & 0 deletions cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const (
forceSystemd = "force-systemd"
kicBaseImage = "base-image"
ports = "ports"
startNamespace = "namespace"
)

var (
Expand Down Expand Up @@ -156,6 +157,7 @@ func initMinikubeFlags() {
// initKubernetesFlags inits the commandline flags for Kubernetes related options
func initKubernetesFlags() {
startCmd.Flags().String(kubernetesVersion, "", fmt.Sprintf("The Kubernetes version that the minikube VM will use (ex: v1.2.3, 'stable' for %s, 'latest' for %s). Defaults to 'stable'.", constants.DefaultKubernetesVersion, constants.NewestKubernetesVersion))
startCmd.Flags().String(startNamespace, "default", "The named space to activate after start")
startCmd.Flags().Var(&config.ExtraOptions, "extra-config",
`A set of key=value pairs that describe configuration that may be passed to different components.
The key should be '.' separated, and the first part before the dot is the component to apply the configuration to.
Expand Down Expand Up @@ -327,6 +329,7 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
KubernetesConfig: config.KubernetesConfig{
KubernetesVersion: k8sVersion,
ClusterName: ClusterFlagValue(),
Namespace: viper.GetString(startNamespace),
APIServerName: viper.GetString(apiServerName),
APIServerNames: apiServerNames,
APIServerIPs: apiServerIPs,
Expand Down Expand Up @@ -548,6 +551,10 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterC
cc.KubernetesConfig.KubernetesVersion = getKubernetesVersion(existing)
}

if cmd.Flags().Changed(startNamespace) {
cc.KubernetesConfig.Namespace = viper.GetString(startNamespace)
}

if cmd.Flags().Changed(apiServerName) {
cc.KubernetesConfig.APIServerName = viper.GetString(apiServerName)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type ClusterConfig struct {
type KubernetesConfig struct {
KubernetesVersion string
ClusterName string
Namespace string
APIServerName string
APIServerNames []string
APIServerIPs []net.IP
Expand Down
4 changes: 4 additions & 0 deletions pkg/minikube/kubeconfig/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ type Settings struct {
// The name of the cluster for this context
ClusterName string

// The name of the namespace for this context
Namespace string

// ClusterServerAddress is the address of the Kubernetes cluster
ClusterServerAddress string

Expand Down Expand Up @@ -104,6 +107,7 @@ func PopulateFromSettings(cfg *Settings, apiCfg *api.Config) error {
contextName := cfg.ClusterName
context := api.NewContext()
context.Cluster = cfg.ClusterName
context.Namespace = cfg.Namespace
context.AuthInfo = userName
apiCfg.Contexts[contextName] = context

Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ func setupKubeconfig(h *host.Host, cc *config.ClusterConfig, n *config.Node, clu
}
kcs := &kubeconfig.Settings{
ClusterName: clusterName,
Namespace: cc.KubernetesConfig.Namespace,
ClusterServerAddress: addr,
ClientCertificate: localpath.ClientCert(cc.Name),
ClientKey: localpath.ClientKey(cc.Name),
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 @@ -75,6 +75,7 @@ minikube start [flags]
--memory string Amount of RAM to allocate to Kubernetes (format: <number>[<unit>], where unit = b, k, m or g).
--mount This will start the mount daemon and automatically mount files into minikube.
--mount-string string The argument to pass the minikube mount command on start.
--namespace string The named space to activate after start (default "default")
--nat-nic-type string NIC Type used for nat network. One of Am79C970A, Am79C973, 82540EM, 82543GC, 82545EM, or virtio (virtualbox driver only) (default "virtio")
--native-ssh Use native Golang SSH client (default true). Set to 'false' to use the command line 'ssh' command when accessing the docker machine. Useful for the machine drivers when they will not start with 'Waiting for SSH'. (default true)
--network-plugin string Kubelet network plug-in to use (default: auto)
Expand Down

0 comments on commit 3bb967a

Please sign in to comment.