Skip to content

Commit

Permalink
Removed kubelet port flag. Node name now always need from env/flag
Browse files Browse the repository at this point in the history
  • Loading branch information
CiMaol committed Mar 10, 2020
1 parent e6eaf11 commit 19fae5b
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 257 deletions.
37 changes: 0 additions & 37 deletions probe/kubernetes/kubelet.go

This file was deleted.

127 changes: 0 additions & 127 deletions probe/kubernetes/kubelet_pods.json

This file was deleted.

48 changes: 0 additions & 48 deletions probe/kubernetes/kubelet_test.go

This file was deleted.

27 changes: 5 additions & 22 deletions probe/kubernetes/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package kubernetes

import (
"fmt"

"k8s.io/apimachinery/pkg/labels"

log "github.com/sirupsen/logrus"
"github.com/weaveworks/common/mtime"
"github.com/weaveworks/scope/probe"
"github.com/weaveworks/scope/probe/controls"
Expand Down Expand Up @@ -195,11 +193,10 @@ type Reporter struct {
hostID string
handlerRegistry *controls.HandlerRegistry
nodeName string
kubeletPort uint
}

// NewReporter makes a new Reporter
func NewReporter(client Client, pipes controls.PipeClient, probeID string, hostID string, probe *probe.Probe, handlerRegistry *controls.HandlerRegistry, nodeName string, kubeletPort uint) *Reporter {
func NewReporter(client Client, pipes controls.PipeClient, probeID string, hostID string, probe *probe.Probe, handlerRegistry *controls.HandlerRegistry, nodeName string) *Reporter {
reporter := &Reporter{
client: client,
pipes: pipes,
Expand All @@ -208,7 +205,6 @@ func NewReporter(client Client, pipes controls.PipeClient, probeID string, hostI
hostID: hostID,
handlerRegistry: handlerRegistry,
nodeName: nodeName,
kubeletPort: kubeletPort,
}
reporter.registerControls()
client.WatchPods(reporter.podEvent)
Expand Down Expand Up @@ -658,26 +654,13 @@ func (r *Reporter) podTopology(services []Service, deployments []Deployment, dae
))
}
}

var localPodUIDs map[string]struct{}
if r.nodeName == "" && r.kubeletPort != 0 {
// We don't know the node name: fall back to obtaining the local pods from kubelet
var err error
localPodUIDs, err = GetLocalPodUIDs(fmt.Sprintf("127.0.0.1:%d", r.kubeletPort))
if err != nil {
log.Warnf("No node name and cannot obtain local pods, reporting all (which may impact performance): %v", err)
}
// filter out non-local pods: we only want to report local ones for performance reasons.
if r.nodeName == "" {
return pods, fmt.Errorf("pod topology failure: no node name given for reporter")
}
err := r.client.WalkPods(func(p Pod) error {
// filter out non-local pods: we only want to report local ones for performance reasons.
if r.nodeName != "" {
if p.NodeName() != r.nodeName {
if p.NodeName() != r.nodeName {
return nil
}
} else if localPodUIDs != nil {
if _, ok := localPodUIDs[p.UID()]; !ok {
return nil
}
}
for _, selector := range selectors {
selector(p)
Expand Down
22 changes: 3 additions & 19 deletions probe/kubernetes/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,21 +219,11 @@ func (c mockPipeClient) PipeClose(appID, id string) error {
}

func TestReporter(t *testing.T) {
oldGetNodeName := kubernetes.GetLocalPodUIDs
defer func() { kubernetes.GetLocalPodUIDs = oldGetNodeName }()
kubernetes.GetLocalPodUIDs = func(string) (map[string]struct{}, error) {
uids := map[string]struct{}{
pod1UID: {},
pod2UID: {},
}
return uids, nil
}

pod1ID := report.MakePodNodeID(pod1UID)
pod2ID := report.MakePodNodeID(pod2UID)
serviceID := report.MakeServiceNodeID(serviceUID)
hr := controls.NewDefaultHandlerRegistry()
rpt, _ := kubernetes.NewReporter(newMockClient(), nil, "probe-id", "foo", nil, hr, "", 0).Report()
rpt, _ := kubernetes.NewReporter(newMockClient(), nil, "probe-id", "foo", nil, hr, nodeName).Report()

// Reporter should have added the following pods
for _, pod := range []struct {
Expand Down Expand Up @@ -337,7 +327,7 @@ func BenchmarkReporter(b *testing.B) {
}
mockK8s.deployments = append(mockK8s.deployments, kubernetes.NewDeployment(&deployment))
}
reporter := kubernetes.NewReporter(mockK8s, nil, "probe-id", "foo", nil, hr, nodeName, 0)
reporter := kubernetes.NewReporter(mockK8s, nil, "probe-id", "foo", nil, hr, nodeName)

b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand Down Expand Up @@ -400,16 +390,10 @@ type callbackReadCloser struct {
func (c *callbackReadCloser) Close() error { return c.close() }

func TestReporterGetLogs(t *testing.T) {
oldGetNodeName := kubernetes.GetLocalPodUIDs
defer func() { kubernetes.GetLocalPodUIDs = oldGetNodeName }()
kubernetes.GetLocalPodUIDs = func(string) (map[string]struct{}, error) {
return map[string]struct{}{}, nil
}

client := newMockClient()
pipes := mockPipeClient{}
hr := controls.NewDefaultHandlerRegistry()
reporter := kubernetes.NewReporter(client, pipes, "", "", nil, hr, "", 0)
reporter := kubernetes.NewReporter(client, pipes, "", "", nil, hr, nodeName)

// Should error on invalid IDs
{
Expand Down
2 changes: 0 additions & 2 deletions prog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ type probeFlags struct {
kubernetesRole string
kubernetesNodeName string
kubernetesClientConfig kubernetes.ClientConfig
kubernetesKubeletPort uint

ecsEnabled bool
ecsCacheSize int
Expand Down Expand Up @@ -343,7 +342,6 @@ func setupFlags(flags *flags) {
flag.StringVar(&flags.probe.kubernetesClientConfig.User, "probe.kubernetes.user", "", "The name of the kubeconfig user to use")
flag.StringVar(&flags.probe.kubernetesClientConfig.Username, "probe.kubernetes.username", "", "Username for basic authentication to the API server")
flag.StringVar(&flags.probe.kubernetesNodeName, "probe.kubernetes.node-name", "", "Name of this node, for filtering pods")
flag.UintVar(&flags.probe.kubernetesKubeletPort, "probe.kubernetes.kubelet-port", 10255, "Node-local TCP port for contacting kubelet (zero to disable)")

// AWS ECS
flag.BoolVar(&flags.probe.ecsEnabled, "probe.ecs", false, "Collect ecs-related attributes for containers on this node")
Expand Down
3 changes: 1 addition & 2 deletions prog/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ func probeMain(flags probeFlags, targets []appclient.Target) {
case kubernetesRoleHost:
flags.kubernetesEnabled = true
case kubernetesRoleCluster:
flags.kubernetesKubeletPort = 0
flags.kubernetesEnabled = true
flags.spyProcs = false
flags.procEnabled = false
Expand Down Expand Up @@ -319,7 +318,7 @@ func probeMain(flags probeFlags, targets []appclient.Target) {
if flags.kubernetesEnabled && flags.kubernetesRole != kubernetesRoleHost {
if client, err := kubernetes.NewClient(flags.kubernetesClientConfig); err == nil {
defer client.Stop()
reporter := kubernetes.NewReporter(client, clients, probeID, hostID, p, handlerRegistry, flags.kubernetesNodeName, flags.kubernetesKubeletPort)
reporter := kubernetes.NewReporter(client, clients, probeID, hostID, p, handlerRegistry, flags.kubernetesNodeName)
defer reporter.Stop()
p.AddReporter(reporter)
} else {
Expand Down

0 comments on commit 19fae5b

Please sign in to comment.