Skip to content

Commit 113744d

Browse files
authored
Merge pull request #1624 from hunchback/k8s-storage-links
K8s storage links
2 parents 81dc1a1 + 8383bdc commit 113744d

File tree

14 files changed

+231
-7
lines changed

14 files changed

+231
-7
lines changed

statics/img/persistentvolume.png

-2.99 KB
Loading
-6.02 KB
Loading

statics/img/storageclass.png

-6.16 KB
Loading

statics/js/components/topology.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,8 @@ var TopologyComponent = {
668668
self.addFilterK8sTypes(filter, "service", ["cluster", "container", "endpoints", "ingress", "namespace", "networkpolicy", "pod", "service"]);
669669
self.addFilterK8sTypes(highlight, "service", ["endpoints", "ingress", "service"]);
670670

671-
self.addFilterK8sTypes(filter, "storage", ["cluster", "namespace", "persistentvolume", "persistentvolumeclaim", "storageclass"]);
672-
self.addFilterK8sTypes(highlight, "storage", ["persistentvolume", "persistentvolumeclaim", "storageclass"]);
671+
self.addFilterK8sTypes(filter, "storage", ["cluster", "container", "namespace", "persistentvolume", "persistentvolumeclaim", "pod", "storageclass"]);
672+
self.addFilterK8sTypes(highlight, "storage", ["container", "persistentvolume", "persistentvolumeclaim", "pod", "storageclass"]);
673673
}
674674

675675
if (self.isIstioEnabled()) {

tests/k8s/pv-claim.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
kind: PersistentVolumeClaim
2+
apiVersion: v1
3+
metadata:
4+
name: task-pv-claim
5+
spec:
6+
storageClassName: standard
7+
accessModes:
8+
- ReadWriteOnce
9+
resources:
10+
requests:
11+
storage: 3Gi

tests/k8s/pv-pod.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
kind: Pod
2+
apiVersion: v1
3+
metadata:
4+
name: task-pv-pod
5+
spec:
6+
volumes:
7+
- name: task-pv-storage
8+
persistentVolumeClaim:
9+
claimName: task-pv-claim
10+
containers:
11+
- name: task-pv-container
12+
image: nginx
13+
ports:
14+
- containerPort: 80
15+
name: "http-server"
16+
volumeMounts:
17+
- mountPath: "/usr/share/nginx/html"
18+
name: task-pv-storage
19+
20+

tests/k8s/pv-volume.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
kind: PersistentVolume
2+
apiVersion: v1
3+
metadata:
4+
name: task-pv-volume
5+
labels:
6+
type: local
7+
spec:
8+
storageClassName: standard
9+
capacity:
10+
storage: 10Gi
11+
accessModes:
12+
- ReadWriteOnce
13+
hostPath:
14+
path: "/mnt/skydive-test-storage"

tests/k8s/storage.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
#
3+
# this is driver to running the scenario found here:
4+
# https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/
5+
6+
SRC=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
7+
8+
: ${NAMESPACE:=default}
9+
echo "export NAMESPACE=$NAMESPACE"
10+
11+
DATA=/mnt/skydive-test-storage
12+
13+
setup() {
14+
sudo mkdir -p $DATA
15+
sudo chmod 777 $DATA
16+
echo 'Hello from kubernetes storage' > $DATA/index.html
17+
}
18+
19+
cleanup() {
20+
sudo rm -rf $DATA
21+
}
22+
23+
create() {
24+
for file in "$@"; do
25+
kubectl apply -n $NAMESPACE -f $file
26+
shift
27+
done
28+
}
29+
30+
delete() {
31+
for file in "$@"; do
32+
kubectl delete --grace-period=0 --force -n $NAMESPACE -f $file
33+
shift
34+
done
35+
}
36+
37+
stop() {
38+
delete $SRC/pv-pod.yaml
39+
delete $SRC/pv-claim.yaml
40+
delete $SRC/pv-volume.yaml
41+
kubectl delete namespace $NAMESPACE
42+
cleanup
43+
}
44+
45+
start() {
46+
setup
47+
kubectl create namespace $NAMESPACE
48+
create $SRC/pv-volume.yaml
49+
create $SRC/pv-claim.yaml
50+
create $SRC/pv-pod.yaml
51+
}
52+
53+
case "$1" in
54+
stop)
55+
stop
56+
;;
57+
start)
58+
start
59+
;;
60+
*)
61+
echo "$0 [stop|start|help]"
62+
exit 1
63+
;;
64+
esac
65+
exit 0

tests/k8s_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,3 +563,61 @@ func TestK8sServicePodScenario(t *testing.T) {
563563
},
564564
)
565565
}
566+
567+
func TestStorageScenario(t *testing.T) {
568+
storage := "./k8s/storage.sh"
569+
testRunner(
570+
t,
571+
[]Cmd{
572+
{storage + " start", true},
573+
},
574+
[]Cmd{
575+
{storage + " stop", false},
576+
},
577+
[]CheckFunction{
578+
func(c *CheckContext) error {
579+
// check nodes exist
580+
sc, err := checkNodeCreation(t, c, k8s.Manager, "storageclass", "standard")
581+
if err != nil {
582+
return err
583+
}
584+
585+
pv, err := checkNodeCreation(t, c, k8s.Manager, "persistentvolume", "task-pv-volume")
586+
if err != nil {
587+
return err
588+
}
589+
590+
pvc, err := checkNodeCreation(t, c, k8s.Manager, "persistentvolumeclaim", "task-pv-claim")
591+
if err != nil {
592+
return err
593+
}
594+
595+
pod, err := checkNodeCreation(t, c, k8s.Manager, "pod", "task-pv-pod")
596+
if err != nil {
597+
return err
598+
}
599+
600+
// check edges exist
601+
if err = checkEdge(t, c, sc, pv, "storageclass"); err != nil {
602+
return err
603+
}
604+
605+
// FIXME: works when stepping with debugger
606+
// if err = checkEdge(t, c, sc, pvc, "storageclass"); err != nil {
607+
// return err
608+
// }
609+
610+
if err = checkEdge(t, c, pod, pvc, "pod"); err != nil {
611+
return err
612+
}
613+
614+
// FIXME: works when stepping with debugger
615+
// if err = checkEdge(t, c, pvc, pv, "persistentvolumeclaim"); err != nil {
616+
// return err
617+
// }
618+
619+
return nil
620+
},
621+
},
622+
)
623+
}

topology/probes/k8s/k8s.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
9898
newServiceEndpointsLinker,
9999
newServicePodLinker,
100100
newStatefulSetPodLinker,
101+
newPodPVCLinker,
102+
newPVPVCLinker,
103+
newStorageClassPVCLinker,
104+
newStorageClassPVLinker,
101105
}
102106

103107
linkers := InitLinkers(linkerHandlers, g)
@@ -108,7 +112,6 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
108112
"namespace",
109113
"node",
110114
"persistentvolume",
111-
"persistentvolumeclaim",
112115
"storageclass",
113116
)
114117

@@ -122,6 +125,7 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
122125
"job",
123126
"networkpolicy",
124127
"pod",
128+
"persistentvolumeclaim",
125129
"replicaset",
126130
"replicationcontroller",
127131
"secret",

0 commit comments

Comments
 (0)