@@ -154,10 +154,11 @@ func runCluster(requestedNamespace string, w *tabwriter.Writer, verbose int) (bo
154154
155155func printResources (namespace corev1.Namespace , clientset * kubernetes.Clientset , w * tabwriter.Writer , verbose int ) (bool , error ) {
156156
157- var sockFoundPod , sockFoundDeploy , sockFoundStatefulSet , sockFoundJob , sockFoundCron bool
157+ sockFound := false
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 )
@@ -267,13 +273,28 @@ func printResources(namespace corev1.Namespace, clientset *kubernetes.Clientset,
267273 }
268274 } else {
269275 // Look up raw pods for volumes here
270- sockFoundPod = printVolumes (w , p .Spec .Volumes , namespaceName , "pod" , p .Name , verbose )
276+ found := printVolumes (w , p .Spec .Volumes , namespaceName , "pod" , p .Name , verbose )
277+ if found {
278+ sockFound = true
279+ }
271280 }
272281 }
273282 }
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+
274292 // loop through all the unique deployments we found for volumes
275293 for _ , deploy := range nsDeployments {
276- sockFoundDeploy = printVolumes (w , deploy .Spec .Template .Spec .Volumes , namespaceName , "deployment" , deploy .Name , verbose )
294+ found := printVolumes (w , deploy .Spec .Template .Spec .Volumes , namespaceName , "deployment" , deploy .Name , verbose )
295+ if found {
296+ sockFound = true
297+ }
277298 }
278299
279300 // loop through all the unique DaemonSets in the namespace
@@ -284,6 +305,7 @@ func printResources(namespace corev1.Namespace, clientset *kubernetes.Clientset,
284305 // fmt.Printf("testing %s\n", v.VolumeSource.HostPath.Path)
285306 if containsDockerSock (v .VolumeSource .HostPath .Path ) {
286307 fmt .Fprintf (w , "%s\t %s\t %s\t %s\t \n " , namespaceName , "daemonset" , daemonset .Name , "mounted" )
308+ sockFound = true
287309 break
288310 }
289311 }
@@ -296,27 +318,32 @@ func printResources(namespace corev1.Namespace, clientset *kubernetes.Clientset,
296318
297319 // loop through all the unique StatefulSets in the namespace
298320 for _ , statefulset := range nsStatefulsets {
299- sockFoundStatefulSet = printVolumes (w , statefulset .Spec .Template .Spec .Volumes , namespaceName , "statefulset" , statefulset .Name , verbose )
321+ found := printVolumes (w , statefulset .Spec .Template .Spec .Volumes , namespaceName , "statefulset" , statefulset .Name , verbose )
322+ if found {
323+ sockFound = true
324+ }
300325 }
301326
302327 // loop through all the unique Jobs in the namespace
303328 for _ , job := range nsJobs {
304- sockFoundJob = printVolumes (w , job .Spec .Template .Spec .Volumes , namespaceName , "job" , job .Name , verbose )
329+ found := printVolumes (w , job .Spec .Template .Spec .Volumes , namespaceName , "job" , job .Name , verbose )
330+ if found {
331+ sockFound = true
332+ }
305333 }
306334
307335 // loop through all the unique CronJobs in the namespace
308336 for _ , cron := range nsCronJobs {
309- sockFoundCron = printVolumes (w , cron .Spec .JobTemplate .Spec .Template .Spec .Volumes , namespaceName , "cron" , cron .Name , verbose )
337+ found := printVolumes (w , cron .Spec .JobTemplate .Spec .Template .Spec .Volumes , namespaceName , "cron" , cron .Name , verbose )
338+ if found {
339+ sockFound = true
340+ }
310341 }
311342
312343 if len (errorList ) > 0 {
313344 return false , utilerrors .NewAggregate (errorList )
314345 }
315- if sockFoundPod || sockFoundDeploy || sockFoundStatefulSet || sockFoundJob || sockFoundCron {
316- return true , nil
317- } else {
318- return false , nil
319- }
346+ return sockFound , nil
320347}
321348
322349func containsDockerSock (s string ) bool {
0 commit comments