Skip to content

Commit

Permalink
Fix one pod to multiple PVC connection
Browse files Browse the repository at this point in the history
Read all the PVC source from a pod spec
and add adjacency between the pod and its PVCs.

Signed-off-by: Akash Srivastava <akashsrivastava4927@gmail.com>
  • Loading branch information
qiell committed Jan 13, 2019
1 parent 5eaa094 commit 60a1c66
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
17 changes: 10 additions & 7 deletions probe/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kubernetes

import (
"strconv"
"strings"

"github.com/weaveworks/scope/report"

Expand Down Expand Up @@ -29,6 +30,7 @@ type Pod interface {
GetNode(probeID string) report.Node
RestartCount() uint
ContainerNames() []string
VolumeClaimNames() []string
}

type pod struct {
Expand Down Expand Up @@ -75,15 +77,14 @@ func (p *pod) RestartCount() uint {
return count
}

func (p *pod) VolumeClaimName() string {
var claimName string
func (p *pod) VolumeClaimNames() []string {
var claimNames []string
for _, volume := range p.Spec.Volumes {
if volume.VolumeSource.PersistentVolumeClaim != nil {
claimName = volume.VolumeSource.PersistentVolumeClaim.ClaimName
break
claimNames = append(claimNames, volume.VolumeSource.PersistentVolumeClaim.ClaimName)
}
}
return claimName
return claimNames
}

func (p *pod) GetNode(probeID string) report.Node {
Expand All @@ -94,8 +95,10 @@ func (p *pod) GetNode(probeID string) report.Node {
RestartCount: strconv.FormatUint(uint64(p.RestartCount()), 10),
}

if p.VolumeClaimName() != "" {
latests[VolumeClaim] = p.VolumeClaimName()
if len(p.VolumeClaimNames()) > 0 {
// PVC name consist of lower case alphanumeric characters, "-" or "."
// and must start and end with an alphanumeric character.
latests[VolumeClaim] = strings.Join(p.VolumeClaimNames(), report.ScopeDelim)
}

if p.Pod.Spec.HostNetwork {
Expand Down
19 changes: 12 additions & 7 deletions render/persistentvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package render

import (
"context"
"strings"

"github.com/weaveworks/scope/probe/kubernetes"
"github.com/weaveworks/scope/report"
Expand Down Expand Up @@ -53,17 +54,21 @@ type podToVolumesRenderer struct{}
func (v podToVolumesRenderer) Render(ctx context.Context, rpt report.Report) Nodes {
nodes := make(report.Nodes)
for podID, podNode := range rpt.Pod.Nodes {
ClaimName, found := podNode.Latest.Lookup(kubernetes.VolumeClaim)
claimNames, found := podNode.Latest.Lookup(kubernetes.VolumeClaim)
if !found {
continue
}
podNamespace, _ := podNode.Latest.Lookup(kubernetes.Namespace)
for _, pvcNode := range rpt.PersistentVolumeClaim.Nodes {
pvcName, _ := pvcNode.Latest.Lookup(kubernetes.Name)
pvcNamespace, _ := pvcNode.Latest.Lookup(kubernetes.Namespace)
if (pvcName == ClaimName) && (podNamespace == pvcNamespace) {
podNode.Adjacency = podNode.Adjacency.Add(pvcNode.ID)
podNode.Children = podNode.Children.Add(pvcNode)
claimNameList := strings.Split(claimNames, report.ScopeDelim)
for _, ClaimName := range claimNameList {
for _, pvcNode := range rpt.PersistentVolumeClaim.Nodes {
pvcName, _ := pvcNode.Latest.Lookup(kubernetes.Name)
pvcNamespace, _ := pvcNode.Latest.Lookup(kubernetes.Namespace)
if (pvcName == ClaimName) && (podNamespace == pvcNamespace) {
podNode.Adjacency = podNode.Adjacency.Add(pvcNode.ID)
podNode.Children = podNode.Children.Add(pvcNode)
break
}
}
}
nodes[podID] = podNode
Expand Down

0 comments on commit 60a1c66

Please sign in to comment.