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

Fix one pod to multiple PVC connection #3553

Merged
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
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