forked from weaveworks/scope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
statefulset.go
56 lines (48 loc) · 1.31 KB
/
statefulset.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
package kubernetes
import (
"fmt"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"github.com/weaveworks/scope/report"
)
// StatefulSet represents a Kubernetes statefulset
type StatefulSet interface {
Meta
Selector() (labels.Selector, error)
GetNode(probeID string) report.Node
}
type statefulSet struct {
*appsv1.StatefulSet
Meta
}
// NewStatefulSet creates a new statefulset
func NewStatefulSet(s *appsv1.StatefulSet) StatefulSet {
return &statefulSet{
StatefulSet: s,
Meta: meta{s.ObjectMeta},
}
}
func (s *statefulSet) Selector() (labels.Selector, error) {
selector, err := metav1.LabelSelectorAsSelector(s.Spec.Selector)
if err != nil {
return nil, err
}
return selector, nil
}
func (s *statefulSet) GetNode(probeID string) report.Node {
desiredReplicas := 1
if s.Spec.Replicas != nil {
desiredReplicas = int(*s.Spec.Replicas)
}
latests := map[string]string{
NodeType: "StatefulSet",
DesiredReplicas: fmt.Sprint(desiredReplicas),
Replicas: fmt.Sprint(s.Status.Replicas),
report.ControlProbeID: probeID,
ObservedGeneration: fmt.Sprint(s.Status.ObservedGeneration),
}
return s.MetaNode(report.MakeStatefulSetNodeID(s.UID())).
WithLatests(latests).
WithLatestActiveControls(Describe)
}