mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-04 02:30:45 +00:00
This namely involved importing new libraries and using the new Clientset. Changes worth mentioning: * The new kubernetes library doesn't provide StoreToLister wrappers, so now I am going the casting directly. * Deleting the pods and getting their logs is done in a cleaner way (using the Clientset instead of the lower-level RESTclient).
51 lines
1.0 KiB
Go
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 = "kubernetes_public_ip"
|
|
)
|
|
|
|
// 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
|
|
}
|