Skip to content

Commit

Permalink
Proxy cli params to minikube (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaper87 authored and k8s-ci-robot committed Oct 16, 2018
1 parent 438fe67 commit 19551f1
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
14 changes: 9 additions & 5 deletions cmd/clusterctl/clusterdeployer/bootstrap/minikube/minikube.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ import (

type Minikube struct {
kubeconfigpath string
vmDriver string
options []string
// minikubeExec implemented as function variable for testing hooks
minikubeExec func(env []string, args ...string) (string, error)
}

func New(vmDriver string) *Minikube {
func New() *Minikube {
return WithOptions([]string{})
}

func WithOptions(options []string) *Minikube {
return &Minikube{
minikubeExec: minikubeExec,
vmDriver: vmDriver,
options: options,
// Arbitrary file name. Can potentially be randomly generated.
kubeconfigpath: "minikube.kubeconfig",
}
Expand All @@ -56,8 +60,8 @@ var minikubeExec = func(env []string, args ...string) (string, error) {

func (m *Minikube) Create() error {
args := []string{"start", "--bootstrapper=kubeadm"}
if m.vmDriver != "" {
args = append(args, fmt.Sprintf("--vm-driver=%v", m.vmDriver))
for _, opt := range m.options {
args = append(args, fmt.Sprintf("--%v", opt))
}
_, err := m.exec(args...)
return err
Expand Down
35 changes: 32 additions & 3 deletions cmd/clusterctl/clusterdeployer/bootstrap/minikube/minikube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,36 @@ func TestCreate(t *testing.T) {
}
for _, testcase := range testcases {
t.Run(testcase.name, func(t *testing.T) {
m := New("")
m := New()
m.minikubeExec = func(env []string, args ...string) (string, error) {
return "", testcase.execError
}
err := m.Create()
if (testcase.expectErr && err == nil) || (!testcase.expectErr && err != nil) {
t.Fatalf("Unexpected returned error. Got: %v, Want Err: %v", err, testcase.expectErr)
}
})
}
}

func TestCreateOptions(t *testing.T) {
var testcases = []struct {
name string
execError error
expectErr bool
}{
{
name: "success",
},
{
name: "exec fail",
execError: fmt.Errorf("test error"),
expectErr: true,
},
}
for _, testcase := range testcases {
t.Run(testcase.name, func(t *testing.T) {
m := WithOptions([]string{"vm-driver=kvm2", "insecure-registry='172.16.0.1'"})
m.minikubeExec = func(env []string, args ...string) (string, error) {
return "", testcase.execError
}
Expand Down Expand Up @@ -69,7 +98,7 @@ func TestDelete(t *testing.T) {
}
for _, testcase := range testcases {
t.Run(testcase.name, func(t *testing.T) {
m := New("")
m := New()
m.minikubeExec = func(env []string, args ...string) (string, error) {
return "", testcase.execError
}
Expand All @@ -83,7 +112,7 @@ func TestDelete(t *testing.T) {

func TestGetKubeconfig(t *testing.T) {
const contents = "dfserfafaew"
m := New("")
m := New()
f, err := createTempFile(contents)
if err != nil {
t.Fatal("Unable to create test file.")
Expand Down
8 changes: 7 additions & 1 deletion cmd/clusterctl/cmd/create_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type CreateOptions struct {
ProviderComponents string
AddonComponents string
CleanupBootstrapCluster bool
MiniKube []string
VmDriver string
Provider string
KubeconfigOutput string
Expand Down Expand Up @@ -83,7 +84,11 @@ func RunCreate(co *CreateOptions) error {
return err
}
} else {
bootstrapProvider = minikube.New(co.VmDriver)
if co.VmDriver != "" {
co.MiniKube = append(co.MiniKube, fmt.Sprintf("vm-driver=%s", co.VmDriver))
}

bootstrapProvider = minikube.WithOptions(co.MiniKube)

}

Expand Down Expand Up @@ -123,6 +128,7 @@ func init() {
// Optional flags
createClusterCmd.Flags().StringVarP(&co.AddonComponents, "addon-components", "a", "", "A yaml file containing cluster addons to apply to the internal cluster")
createClusterCmd.Flags().BoolVarP(&co.CleanupBootstrapCluster, "cleanup-bootstrap-cluster", "", true, "Whether to cleanup the bootstrap cluster after bootstrap")
createClusterCmd.Flags().StringSliceVarP(&co.MiniKube, "minikube", "", []string{}, "Minikube options")
createClusterCmd.Flags().StringVarP(&co.VmDriver, "vm-driver", "", "", "Which vm driver to use for minikube")
createClusterCmd.Flags().StringVarP(&co.KubeconfigOutput, "kubeconfig-out", "", "kubeconfig", "Where to output the kubeconfig for the provisioned cluster")
createClusterCmd.Flags().StringVarP(&co.ExistingClusterKubeconfigPath, "existing-bootstrap-cluster-kubeconfig", "", "", "Path to an existing cluster's kubeconfig for bootstrapping (intead of using minikube)")
Expand Down
5 changes: 4 additions & 1 deletion cmd/clusterctl/cmd/delete_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ func RunDelete() error {
return fmt.Errorf("error when creating cluster client: %v", err)
}
defer clusterClient.Close()
mini := minikube.New(do.VmDriver)
if co.VmDriver != "" {
co.MiniKube = append(co.MiniKube, fmt.Sprintf("vm-driver=%s", co.VmDriver))
}
mini := minikube.WithOptions(co.MiniKube)
deployer := clusterdeployer.New(mini,
clusterclient.NewFactory(),
providerComponents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Flags:
-h, --help help for cluster
--kubeconfig-out string Where to output the kubeconfig for the provisioned cluster (default "kubeconfig")
-m, --machines string A yaml file containing machine object definition(s)
--minikube strings Minikube options
--provider string Which provider deployment logic to use (google/vsphere/azure)
-p, --provider-components string A yaml file containing cluster api provider controllers and supporting objects
--vm-driver string Which vm driver to use for minikube
Expand Down
1 change: 1 addition & 0 deletions cmd/clusterctl/testdata/create-cluster-no-args.golden
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Flags:
-h, --help help for cluster
--kubeconfig-out string Where to output the kubeconfig for the provisioned cluster (default "kubeconfig")
-m, --machines string A yaml file containing machine object definition(s)
--minikube strings Minikube options
--provider string Which provider deployment logic to use (google/vsphere/azure)
-p, --provider-components string A yaml file containing cluster api provider controllers and supporting objects
--vm-driver string Which vm driver to use for minikube
Expand Down

0 comments on commit 19551f1

Please sign in to comment.