Files
weave-scope/probe/kubernetes/daemonset.go
Bryan Boreham 17c1aaa131 chore(probe): for Kubernetes 1.16 move to 'v1' APIs
Scope will no longer work with Kubernetes 1.8 and below.

For CronJob there is no 'v1' as yet, but we can remove the alpha
version.
2019-09-21 15:52:34 +00:00

55 lines
1.3 KiB
Go

package kubernetes
import (
"fmt"
apiv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"github.com/weaveworks/scope/report"
)
// These constants are keys used in node metadata
const (
MisscheduledReplicas = report.KubernetesMisscheduledReplicas
)
// DaemonSet represents a Kubernetes daemonset
type DaemonSet interface {
Meta
Selector() (labels.Selector, error)
GetNode(probeID string) report.Node
}
type daemonSet struct {
*apiv1.DaemonSet
Meta
}
// NewDaemonSet creates a new daemonset
func NewDaemonSet(d *apiv1.DaemonSet) DaemonSet {
return &daemonSet{
DaemonSet: d,
Meta: meta{d.ObjectMeta},
}
}
func (d *daemonSet) Selector() (labels.Selector, error) {
selector, err := metav1.LabelSelectorAsSelector(d.Spec.Selector)
if err != nil {
return nil, err
}
return selector, nil
}
func (d *daemonSet) GetNode(probeID string) report.Node {
return d.MetaNode(report.MakeDaemonSetNodeID(d.UID())).WithLatests(map[string]string{
DesiredReplicas: fmt.Sprint(d.Status.DesiredNumberScheduled),
Replicas: fmt.Sprint(d.Status.CurrentNumberScheduled),
MisscheduledReplicas: fmt.Sprint(d.Status.NumberMisscheduled),
NodeType: "DaemonSet",
report.ControlProbeID: probeID,
}).WithLatestActiveControls(Describe)
}