Skip to content

Commit 8383bdc

Browse files
committed
k8s: add storage links and add test scenario
1 parent ddc21c0 commit 8383bdc

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
@@ -629,8 +629,8 @@ var TopologyComponent = {
629629
self.addFilterK8sTypes(filter, "service", ["cluster", "container", "endpoints", "ingress", "namespace", "networkpolicy", "pod", "service"]);
630630
self.addFilterK8sTypes(highlight, "service", ["endpoints", "ingress", "service"]);
631631

632-
self.addFilterK8sTypes(filter, "storage", ["cluster", "namespace", "persistentvolume", "persistentvolumeclaim", "storageclass"]);
633-
self.addFilterK8sTypes(highlight, "storage", ["persistentvolume", "persistentvolumeclaim", "storageclass"]);
632+
self.addFilterK8sTypes(filter, "storage", ["cluster", "container", "namespace", "persistentvolume", "persistentvolumeclaim", "pod", "storageclass"]);
633+
self.addFilterK8sTypes(highlight, "storage", ["container", "persistentvolume", "persistentvolumeclaim", "pod", "storageclass"]);
634634
}
635635

636636
var default_filter = app.getConfigValue('topology.default_filter');

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
@@ -555,3 +555,61 @@ func TestK8sServicePodScenario(t *testing.T) {
555555
},
556556
)
557557
}
558+
559+
func TestStorageScenario(t *testing.T) {
560+
storage := "./k8s/storage.sh"
561+
testRunner(
562+
t,
563+
[]Cmd{
564+
{storage + " start", true},
565+
},
566+
[]Cmd{
567+
{storage + " stop", false},
568+
},
569+
[]CheckFunction{
570+
func(c *CheckContext) error {
571+
// check nodes exist
572+
sc, err := checkNodeCreation(t, c, k8s.Manager, "storageclass", "standard")
573+
if err != nil {
574+
return err
575+
}
576+
577+
pv, err := checkNodeCreation(t, c, k8s.Manager, "persistentvolume", "task-pv-volume")
578+
if err != nil {
579+
return err
580+
}
581+
582+
pvc, err := checkNodeCreation(t, c, k8s.Manager, "persistentvolumeclaim", "task-pv-claim")
583+
if err != nil {
584+
return err
585+
}
586+
587+
pod, err := checkNodeCreation(t, c, k8s.Manager, "pod", "task-pv-pod")
588+
if err != nil {
589+
return err
590+
}
591+
592+
// check edges exist
593+
if err = checkEdge(t, c, sc, pv, "storageclass"); err != nil {
594+
return err
595+
}
596+
597+
// FIXME: works when stepping with debugger
598+
// if err = checkEdge(t, c, sc, pvc, "storageclass"); err != nil {
599+
// return err
600+
// }
601+
602+
if err = checkEdge(t, c, pod, pvc, "pod"); err != nil {
603+
return err
604+
}
605+
606+
// FIXME: works when stepping with debugger
607+
// if err = checkEdge(t, c, pvc, pv, "persistentvolumeclaim"); err != nil {
608+
// return err
609+
// }
610+
611+
return nil
612+
},
613+
},
614+
)
615+
}

topology/probes/k8s/k8s.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
9696
newServiceEndpointsLinker,
9797
newServicePodLinker,
9898
newStatefulSetPodLinker,
99+
newPodPVCLinker,
100+
newPVPVCLinker,
101+
newStorageClassPVCLinker,
102+
newStorageClassPVLinker,
99103
}
100104

101105
linkers := InitLinkers(linkerHandlers, g)
@@ -106,7 +110,6 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
106110
"namespace",
107111
"node",
108112
"persistentvolume",
109-
"persistentvolumeclaim",
110113
"storageclass",
111114
)
112115

@@ -119,6 +122,7 @@ func NewK8sProbe(g *graph.Graph) (*Probe, error) {
119122
"job",
120123
"networkpolicy",
121124
"pod",
125+
"persistentvolumeclaim",
122126
"replicaset",
123127
"replicationcontroller",
124128
"service",

0 commit comments

Comments
 (0)