Files
weave-scope/probe/kubernetes/meta.go
Alfonso Acosta 8bbbf25809 Migrate probe to new new kubernetes go-client
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).
2017-07-03 20:20:27 +00:00

61 lines
1.2 KiB
Go

package kubernetes
import (
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/weaveworks/scope/report"
)
// These constants are keys used in node metadata
const (
Name = "kubernetes_name"
Namespace = "kubernetes_namespace"
Created = "kubernetes_created"
LabelPrefix = "kubernetes_labels_"
)
// Meta represents a metadata information about a Kubernetes object
type Meta interface {
UID() string
Name() string
Namespace() string
Created() string
Labels() map[string]string
MetaNode(id string) report.Node
}
type meta struct {
ObjectMeta metav1.ObjectMeta
}
func (m meta) UID() string {
return string(m.ObjectMeta.UID)
}
func (m meta) Name() string {
return m.ObjectMeta.Name
}
func (m meta) Namespace() string {
return m.ObjectMeta.Namespace
}
func (m meta) Created() string {
return m.ObjectMeta.CreationTimestamp.Format(time.RFC3339Nano)
}
func (m meta) Labels() map[string]string {
return m.ObjectMeta.Labels
}
// MetaNode gets the node metadata
func (m meta) MetaNode(id string) report.Node {
return report.MakeNodeWith(id, map[string]string{
Name: m.Name(),
Namespace: m.Namespace(),
Created: m.Created(),
}).AddPrefixPropertyList(LabelPrefix, m.Labels())
}