-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
minikube.go
98 lines (76 loc) · 1.67 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
package minikube
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os/exec"
)
// Profile contains information about a minikube profile
type Profile struct {
Name string
IP string
Status Status
Driver string
IngressEnabled bool
IngressDNSEnabled bool
}
// Status represents the current state of a profile
type Status string
const (
// Running status of minikube profile
Running Status = "Running"
)
// GetProfile returns information about a minikube profile
func GetProfile(name string) (*Profile, error) {
mini, err := exec.LookPath("minikube")
if err != nil {
return nil, err
}
b := bytes.NewBufferString("")
c := exec.Command(mini, "profile", "list", "-o", "json")
c.Stdout = b
err = c.Run()
if err != nil {
return nil, err
}
data, err := ioutil.ReadAll(b)
if err != nil {
return nil, err
}
var m ProfileListResponse
_ = json.Unmarshal(data, &m)
var profile *Profile
for _, p := range m.Valid {
if p.Name == name {
profile = &Profile{
Name: p.Name,
IP: p.Config.Nodes[0].IP,
Status: Status(p.Status),
Driver: p.Config.Driver,
}
}
}
if profile == nil {
return nil, fmt.Errorf("can't find profile '%s' on minikube", name)
}
b = bytes.NewBufferString("")
c = exec.Command(mini, "addons", "list", "-o", "json", "-p", profile.Name)
c.Stdout = b
err = c.Run()
if err != nil {
return nil, err
}
data, err = ioutil.ReadAll(b)
if err != nil {
return nil, err
}
var a *AddonsResponse
_ = json.Unmarshal(data, &a)
if a == nil {
return profile, nil
}
profile.IngressDNSEnabled = a.IngressDNS.Status == "enabled"
profile.IngressEnabled = a.Ingress.Status == "enabled"
return profile, nil
}