aws-containers / kubectl-detector-for-docker-socket

A Kubectl plugin that can detect if any of your workloads or manifest files are mounting the docker.sock volume
Apache License 2.0
175 stars 21 forks source link

panic occurs when directly using ReplicaSet #10

Closed konoui closed 1 year ago

konoui commented 1 year ago

I found that panic occurs when directly using ReplicaSet. DDS does not support ReplicaSet but I want to avoid the panic.

$ kubectl dds

NAMESPACE       TYPE    NAME    STATUS
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.printResources({{{0x0, 0x0}, {0x0, 0x0}}, {{0x140004756c0, 0x7}, {0x0, 0x0}, {0x0, 0x0}, ...}, ...}, ...)
        /Users/tanaka/dev/src/github.com/konoui/kubectl-detector-for-docker-socket/main.go:200 +0x1478
main.runCluster({0x101f4d9aa, 0x3}, 0x1400012c008?, 0x2)
        /Users/tanaka/dev/src/github.com/konoui/kubectl-detector-for-docker-socket/main.go:142 +0x4ac
main.main()
        /Users/tanaka/dev/src/github.com/konoui/kubectl-detector-for-docker-socket/main.go:62 +0x270
---
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: replicaset-docker-volume
  labels:
    app: rs
spec:
  replicas: 3
  selector:
    matchLabels:
      app: rs
  template:
    metadata:
      labels:
        app: rs
    spec:
      containers:
      - name: pause
        image: public.ecr.aws/eks-distro/kubernetes/pause:v1.21.5-eks-1-21-8
        ports:
        - containerPort: 80
        volumeMounts:
        - name: dockersock
          mountPath: "/var/run/docker.sock"
      volumes:
      - name: dockersock
        hostPath:
          path: /var/run/docker.sock