forked from tsuru/tsuru
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.go
88 lines (74 loc) · 2.04 KB
/
node.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
// Copyright 2016 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package kubernetes
import (
tsuruNet "github.com/tsuru/tsuru/net"
"github.com/tsuru/tsuru/provision"
apiv1 "k8s.io/api/core/v1"
)
type kubernetesNodeWrapper struct {
node *apiv1.Node
prov *kubernetesProvisioner
cluster *ClusterClient
}
var (
_ provision.Node = &kubernetesNodeWrapper{}
)
func (n *kubernetesNodeWrapper) IaaSID() string {
return labelSetFromMeta(&n.node.ObjectMeta).NodeIaaSID()
}
func (n *kubernetesNodeWrapper) Pool() string {
return labelSetFromMeta(&n.node.ObjectMeta).NodePool()
}
func (n *kubernetesNodeWrapper) Address() string {
if n.node == nil {
return ""
}
for _, addr := range n.node.Status.Addresses {
if addr.Type == apiv1.NodeInternalIP {
return addr.Address
}
}
return n.node.Name
}
func (n *kubernetesNodeWrapper) Status() string {
for _, cond := range n.node.Status.Conditions {
if cond.Type == apiv1.NodeReady {
if cond.Status == apiv1.ConditionTrue {
return "Ready"
}
return cond.Message
}
}
return "Invalid"
}
func (n *kubernetesNodeWrapper) Metadata() map[string]string {
return labelSetFromMeta(&n.node.ObjectMeta).NodeMetadata()
}
func (n *kubernetesNodeWrapper) MetadataNoPrefix() map[string]string {
return labelSetFromMeta(&n.node.ObjectMeta).NodeMetadataNoPrefix()
}
func (n *kubernetesNodeWrapper) ExtraData() map[string]string {
var clusterName string
if n.cluster != nil {
clusterName = n.cluster.Name
}
return labelSetFromMeta(&n.node.ObjectMeta).NodeExtraData(clusterName)
}
func (n *kubernetesNodeWrapper) Units() ([]provision.Unit, error) {
pods, err := appPodsFromNode(n.cluster, n.node.Name)
if err != nil {
return nil, err
}
return n.prov.podsToUnits(n.cluster, pods, nil, n.node)
}
func (n *kubernetesNodeWrapper) Provisioner() provision.NodeProvisioner {
return n.prov
}
func (n *kubernetesNodeWrapper) ip() string {
if n.node == nil {
return ""
}
return tsuruNet.URLToHost(n.Address())
}