-
Notifications
You must be signed in to change notification settings - Fork 10
/
minikube.go
161 lines (145 loc) · 4.63 KB
/
minikube.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
(c) Copyright 2018, Gemalto. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package minikube
import (
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"github.com/gemalto/gokube/pkg/download"
"github.com/gemalto/gokube/pkg/utils"
)
const (
DEFAULT_URL = "https://storage.googleapis.com/minikube/releases/%s/minikube-windows-amd64.exe"
LOCAL_EXECUTABLE_NAME = "minikube.exe"
)
// Start ...
func Start(memory int16, cpus int16, diskSize string, httpProxy string, httpsProxy string, noProxy string, insecureRegistry string, kubernetesVersion string, cache bool, dnsProxy bool, hostDNSResolver bool, dnsDomain string, containerRuntime string, force bool, verbose bool) error {
var args = []string{"start", "--kubernetes-version", kubernetesVersion, "--insecure-registry", insecureRegistry, "--memory", strconv.FormatInt(int64(memory), 10), "--cpus", strconv.FormatInt(int64(cpus), 10), "--disk-size", diskSize, "--driver=virtualbox", "--host-only-cidr=192.168.99.1/24"}
if len(httpProxy) > 0 {
args = append(args, "--docker-env=http_proxy="+httpProxy)
}
if len(httpsProxy) > 0 {
args = append(args, "--docker-env=https_proxy="+httpsProxy)
}
if len(noProxy) > 0 {
args = append(args, "--docker-env=no_proxy="+noProxy)
}
if !cache {
args = append(args, "--cache-images=false")
}
if dnsProxy {
args = append(args, "--dns-proxy")
}
if !hostDNSResolver {
args = append(args, "--host-dns-resolver=false")
}
if len(dnsDomain) > 0 {
args = append(args, "--dns-domain="+dnsDomain)
}
if len(containerRuntime) > 0 {
args = append(args, "--container-runtime="+containerRuntime)
}
if force {
args = append(args, "--force")
}
if verbose {
args = append(args, "--alsologtostderr", "--v=1")
}
cmd := exec.Command("minikube", args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
// Restart ...
func Restart(kubernetesVersion string, containerRuntime string, force bool, verbose bool) error {
var args = []string{"start", "--kubernetes-version", kubernetesVersion}
if len(containerRuntime) > 0 {
args = append(args, "--container-runtime="+containerRuntime)
}
if force {
args = append(args, "--force")
}
if verbose {
args = append(args, "--alsologtostderr", "--v=1")
}
cmd := exec.Command("minikube", args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
// Stop ...
func Stop() error {
cmd := exec.Command("minikube", "stop")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
// Delete ...
func Delete() error {
cmd := exec.Command("minikube", "delete")
// cmd.Stdout = os.Stdout
// cmd.Stderr = os.Stderr
return cmd.Run()
}
// AddonsEnable ...
func AddonsEnable(addon string) error {
cmd := exec.Command("minikube", "addons", "enable", addon)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
// ConfigSet ...
func ConfigSet(key string, value string) error {
cmd := exec.Command("minikube", "config", "set", key, value)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
// Version ...
func Version() error {
cmd := exec.Command("minikube", "version")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
// Ip ...
func Ip() (string, error) {
out, err := exec.Command("minikube", "ip").Output()
if err != nil {
return "", err
}
return strings.TrimRight(string(out), "\r\n"), nil
}
// DownloadExecutable ...
func DownloadExecutable(minikubeURL string, minikubeVersion string) error {
localFile := utils.GetBinDir("gokube") + string(os.PathSeparator) + LOCAL_EXECUTABLE_NAME
if _, err := os.Stat(localFile); os.IsNotExist(err) {
fileMap := &download.FileMap{Src: "minikube-windows-amd64.exe", Dst: LOCAL_EXECUTABLE_NAME}
_, err = download.FromUrl(minikubeURL, minikubeVersion, "minikube", []*download.FileMap{fileMap}, filepath.Dir(localFile))
if err != nil {
return err
}
}
return nil
}
// DeleteExecutable ...
func DeleteExecutable() error {
localFile := utils.GetBinDir("gokube") + string(os.PathSeparator) + LOCAL_EXECUTABLE_NAME
return os.RemoveAll(localFile)
}
// DeleteWorkingDirectory ...
func DeleteWorkingDirectory() error {
return utils.CleanDir(utils.GetUserHome() + string(os.PathSeparator) + ".minikube")
}