Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kubernetes service type and ports #3090

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions probe/kubernetes/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
Replicas = report.KubernetesReplicas
DesiredReplicas = report.KubernetesDesiredReplicas
NodeType = report.KubernetesNodeType
Type = report.KubernetesType
Ports = report.KubernetesPorts
)

// Exposed for testing
Expand All @@ -44,6 +46,8 @@ var (
PublicIP: {ID: PublicIP, Label: "Public IP", From: report.FromLatest, Datatype: report.IP, Priority: 4},
IP: {ID: IP, Label: "Internal IP", From: report.FromLatest, Datatype: report.IP, Priority: 5},
report.Pod: {ID: report.Pod, Label: "# Pods", From: report.FromCounters, Datatype: report.Number, Priority: 6},
Type: {ID: Type, Label: "Type", From: report.FromLatest, Priority: 7},
Ports: {ID: Ports, Label: "Ports", From: report.FromLatest, Priority: 8},
}

ServiceMetricTemplates = PodMetricTemplates
Expand Down
22 changes: 21 additions & 1 deletion probe/kubernetes/service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package kubernetes

import (
"fmt"

"github.com/weaveworks/scope/report"

apiv1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -37,11 +39,29 @@ func (s *service) Selector() labels.Selector {
return labels.SelectorFromSet(labels.Set(s.Spec.Selector))
}

// human-readable version of a Kubernetes ServicePort
func servicePortString(p apiv1.ServicePort) string {
if p.NodePort == 0 {
return fmt.Sprintf("%d/%s", p.Port, p.Protocol)
}
return fmt.Sprintf("%d:%d/%s", p.Port, p.NodePort, p.Protocol)
}

func (s *service) GetNode() report.Node {
latest := map[string]string{IP: s.Spec.ClusterIP}
latest := map[string]string{
IP: s.Spec.ClusterIP,
Type: string(s.Spec.Type),
}
if s.Spec.LoadBalancerIP != "" {
latest[PublicIP] = s.Spec.LoadBalancerIP
}
if len(s.Spec.Ports) != 0 {
portStr := ""
for _, p := range s.Spec.Ports {
portStr = portStr + servicePortString(p) + ","
}
latest[Ports] = portStr[:len(portStr)-1]
}
return s.MetaNode(report.MakeServiceNodeID(s.UID())).WithLatests(latest)
}

Expand Down
4 changes: 4 additions & 0 deletions report/map_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ const (
KubernetesLastScheduled = "kubernetes_last_scheduled"
KubernetesActiveJobs = "kubernetes_active_jobs"
KubernetesStateDeleted = "deleted"
KubernetesType = "kubernetes_type"
KubernetesPorts = "kubernetes_ports"
// probe/awsecs
ECSCluster = "ecs_cluster"
ECSCreatedAt = "ecs_created_at"
Expand Down Expand Up @@ -173,6 +175,8 @@ var commonKeys = map[string]string{
KubernetesSuspended: KubernetesSuspended,
KubernetesLastScheduled: KubernetesLastScheduled,
KubernetesActiveJobs: KubernetesActiveJobs,
KubernetesType: KubernetesType,
KubernetesPorts: KubernetesPorts,

ECSCluster: ECSCluster,
ECSCreatedAt: ECSCreatedAt,
Expand Down