Files
weave-scope/probe/kubernetes/service.go
Matthias Radestock 1f2247a8c4 move node metadata keys into report package
Both the probe and the app (for rendering) need to know about them.
2017-12-11 20:26:08 +00:00

51 lines
1.0 KiB
Go

package kubernetes
import (
"github.com/weaveworks/scope/report"
"k8s.io/apimachinery/pkg/labels"
apiv1 "k8s.io/client-go/pkg/api/v1"
)
// These constants are keys used in node metadata
const (
PublicIP = report.KubernetesPublicIP
)
// Service represents a Kubernetes service
type Service interface {
Meta
GetNode() report.Node
Selector() labels.Selector
ClusterIP() string
}
type service struct {
*apiv1.Service
Meta
}
// NewService creates a new Service
func NewService(s *apiv1.Service) Service {
return &service{Service: s, Meta: meta{s.ObjectMeta}}
}
func (s *service) Selector() labels.Selector {
if s.Spec.Selector == nil {
return labels.Nothing()
}
return labels.SelectorFromSet(labels.Set(s.Spec.Selector))
}
func (s *service) GetNode() report.Node {
latest := map[string]string{IP: s.Spec.ClusterIP}
if s.Spec.LoadBalancerIP != "" {
latest[PublicIP] = s.Spec.LoadBalancerIP
}
return s.MetaNode(report.MakeServiceNodeID(s.UID())).WithLatests(latest)
}
func (s *service) ClusterIP() string {
return s.Spec.ClusterIP
}