-
Notifications
You must be signed in to change notification settings - Fork 179
/
instance.go
77 lines (61 loc) · 1.66 KB
/
instance.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
package k8s
import (
"fmt"
"io"
"github.com/convox/rack/pkg/helpers"
"github.com/convox/rack/pkg/structs"
ac "k8s.io/api/core/v1"
am "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func (p *Provider) InstanceKeyroll() error {
return fmt.Errorf("unimplemented")
}
func (p *Provider) InstanceList() (structs.Instances, error) {
ns, err := p.Cluster.CoreV1().Nodes().List(am.ListOptions{})
if err != nil {
return nil, err
}
// ms, err := p.Metrics.Metrics().NodeMetricses().List(am.ListOptions{})
// if err != nil {
// return nil, err
// }
// fmt.Printf("ms = %+v\n", ms)
is := structs.Instances{}
for _, n := range ns.Items {
pds, err := p.Cluster.CoreV1().Pods("").List(am.ListOptions{FieldSelector: fmt.Sprintf("spec.nodeName=%s", n.ObjectMeta.Name)})
if err != nil {
return nil, err
}
status := "pending"
for _, c := range n.Status.Conditions {
if c.Type == "Ready" && c.Status == "True" {
status = "running"
}
}
private := ""
public := ""
for _, na := range n.Status.Addresses {
switch na.Type {
case ac.NodeExternalIP:
public = na.Address
case ac.NodeInternalIP:
private = na.Address
}
}
is = append(is, structs.Instance{
Id: helpers.CoalesceString(n.Spec.ProviderID, n.ObjectMeta.Name),
PrivateIp: private,
Processes: len(pds.Items),
PublicIp: public,
Started: n.CreationTimestamp.Time,
Status: status,
})
}
return is, nil
}
func (p *Provider) InstanceShell(id string, rw io.ReadWriter, opts structs.InstanceShellOptions) (int, error) {
return 0, fmt.Errorf("unimplemented")
}
func (p *Provider) InstanceTerminate(id string) error {
return fmt.Errorf("unimplemented")
}