mirror of
https://github.com/weaveworks/scope.git
synced 2026-05-19 23:57:15 +00:00
* Refactor: func has already access to probeID * Allow controls for more k8s topologies Controls for nodes generally need to know about the probe that is in control of them. This PR appends the probe ID info to k8s topologies CronJob, DaemonSet, Service, and StatefulSet. Therefore allowing plugins to append controls. * Remove superfluous error check * Add some tests to verify controls allowance
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package kubernetes
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"k8s.io/api/apps/v1beta1"
|
|
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 {
|
|
*v1beta1.StatefulSet
|
|
Meta
|
|
}
|
|
|
|
// NewStatefulSet creates a new statefulset
|
|
func NewStatefulSet(s *v1beta1.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,
|
|
}
|
|
if s.Status.ObservedGeneration != nil {
|
|
latests[ObservedGeneration] = fmt.Sprint(*s.Status.ObservedGeneration)
|
|
}
|
|
return s.MetaNode(report.MakeStatefulSetNodeID(s.UID())).WithLatests(latests)
|
|
}
|