Skip to content

Commit d9f7070

Browse files
committed
add replicaset to avoid panic
1 parent ecaef57 commit d9f7070

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ It then inspects all of the volumes in the containers and looks for any volume w
2424
Supported workload types:
2525

2626
* Pods
27+
* ReplicaSets
2728
* Deployments
2829
* StatefulSets
2930
* DaemonSets

main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ func printResources(namespace corev1.Namespace, clientset *kubernetes.Clientset,
158158

159159
namespaceName := namespace.ObjectMeta.Name
160160

161+
nsReplicasets := make(map[string]*appsv1.ReplicaSet)
161162
nsDeployments := make(map[string]*appsv1.Deployment)
162163
nsDaemonsets := make(map[string]*appsv1.DaemonSet)
163164
nsStatefulsets := make(map[string]*appsv1.StatefulSet)
@@ -197,6 +198,11 @@ func printResources(namespace corev1.Namespace, clientset *kubernetes.Clientset,
197198
continue
198199
}
199200

201+
if len(replica.OwnerReferences) == 0 {
202+
nsReplicasets[replica.Name] = replica
203+
continue
204+
}
205+
200206
deployment, deployErr := clientset.AppsV1().Deployments(namespace.Name).Get(context.TODO(), replica.OwnerReferences[0].Name, metav1.GetOptions{})
201207
if deployErr != nil {
202208
errorList = append(errorList, deployErr)
@@ -274,6 +280,15 @@ func printResources(namespace corev1.Namespace, clientset *kubernetes.Clientset,
274280
}
275281
}
276282
}
283+
284+
// loop through all the unique ReplicaSets in the namespace
285+
for _, replica := range nsReplicasets {
286+
found := printVolumes(w, replica.Spec.Template.Spec.Volumes, namespaceName, "replicaset", replica.Name, verbose)
287+
if found {
288+
sockFound = true
289+
}
290+
}
291+
277292
// loop through all the unique deployments we found for volumes
278293
for _, deploy := range nsDeployments {
279294
found := printVolumes(w, deploy.Spec.Template.Spec.Volumes, namespaceName, "deployment", deploy.Name, verbose)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: ReplicaSet
4+
metadata:
5+
name: replicaset-docker-volume
6+
labels:
7+
app: rs
8+
spec:
9+
replicas: 3
10+
selector:
11+
matchLabels:
12+
app: rs
13+
template:
14+
metadata:
15+
labels:
16+
app: rs
17+
spec:
18+
containers:
19+
- name: pause
20+
image: public.ecr.aws/eks-distro/kubernetes/pause:v1.21.5-eks-1-21-8
21+
ports:
22+
- containerPort: 80
23+
volumeMounts:
24+
- name: dockersock
25+
mountPath: "/var/run/docker.sock"
26+
volumes:
27+
- name: dockersock
28+
hostPath:
29+
path: /var/run/docker.sock

0 commit comments

Comments
 (0)