Fix one pod to multiple PVC connection

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>
This commit is contained in:
Akash Srivastava
2019-01-09 16:14:19 +05:30
parent 5eaa094f2a
commit 60a1c66430
2 changed files with 22 additions and 14 deletions

View File

@@ -2,6 +2,7 @@ package kubernetes
import (
"strconv"
"strings"
"github.com/weaveworks/scope/report"
@@ -29,6 +30,7 @@ type Pod interface {
GetNode(probeID string) report.Node
RestartCount() uint
ContainerNames() []string
VolumeClaimNames() []string
}
type pod struct {
@@ -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 {
@@ -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 {

View File

@@ -2,6 +2,7 @@ package render
import (
"context"
"strings"
"github.com/weaveworks/scope/probe/kubernetes"
"github.com/weaveworks/scope/report"
@@ -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