When there are non-KubePlus pods that don't have a parent (bare pods) in the same namespace where KubePlus Pod is running, we see following stack tract in the helmer container:
Helmer NS:default
Before registering...
Inside checkResource...
2023/06/30 20:13:22 http: panic serving 127.0.0.1:42606: runtime error: index out of range [0] with length 0
goroutine 19 [running]:
net/http.(conn).serve.func1()
/usr/local/go/src/net/http/server.go:1825 +0xbf
panic({0x15ab080, 0xc000048750})
/usr/local/go/src/runtime/panic.go:844 +0x258
main.getKubePlusPod()
/home/vagrant/go/src/github.com/cloud-ark/kubeplus/platform-operator/helm-pod/main.go:221 +0x33e
main.checkResource(0xc0004637a0, 0xc000488620)
/home/vagrant/go/src/github.com/cloud-ark/kubeplus/platform-operator/helm-pod/main.go:404 +0xc5
github.com/emicklei/go-restful.(Container).dispatch(0xc00019a000, {0x1893a38, 0xc00019cee0}, 0xc0001dbf00)
/home/vagrant/go/pkg/mod/github.com/emicklei/go-restful@v2.15.0+incompatible/container.go:294 +0x590
net/http.HandlerFunc.ServeHTTP(0x7fc14d5efbe8?, {0x1893a38?, 0xc00019cee0?}, 0x40ef25?)
/usr/local/go/src/net/http/server.go:2084 +0x2f
net/http.(ServeMux).ServeHTTP(0xc0003ccf71?, {0x1893a38, 0xc00019cee0}, 0xc0001dbf00)
/usr/local/go/src/net/http/server.go:2462 +0x149
net/http.serverHandler.ServeHTTP({0xc0004635f0?}, {0x1893a38, 0xc00019cee0}, 0xc0001dbf00)
/usr/local/go/src/net/http/server.go:2916 +0x43b
net/http.(conn).serve(0xc0004699a0, {0x1894230, 0xc000463500})
/usr/local/go/src/net/http/server.go:1966 +0x5d7
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3071 +0x4db
This error arises in the getKubePlusPod() method in helmer's main.go:
for _, podObj := range podList.Items {
ownerRefObj := podObj.ObjectMeta.OwnerReferences[0]
podOwnerName := ownerRefObj.Name
if podOwnerName == replicaSetName {
podName = podObj.ObjectMeta.Name
//fmt.Printf("RSSetName:%s, PodName:%s\n", replicaSetName, podName)
break
}
}
We should add a check to verify that a Pod indeed has a OwnerReference and only then try to de-reference it.
When there are non-KubePlus pods that don't have a parent (bare pods) in the same namespace where KubePlus Pod is running, we see following stack tract in the helmer container:
Helmer NS:default Before registering... Inside checkResource... 2023/06/30 20:13:22 http: panic serving 127.0.0.1:42606: runtime error: index out of range [0] with length 0 goroutine 19 [running]: net/http.(conn).serve.func1() /usr/local/go/src/net/http/server.go:1825 +0xbf panic({0x15ab080, 0xc000048750}) /usr/local/go/src/runtime/panic.go:844 +0x258 main.getKubePlusPod() /home/vagrant/go/src/github.com/cloud-ark/kubeplus/platform-operator/helm-pod/main.go:221 +0x33e main.checkResource(0xc0004637a0, 0xc000488620) /home/vagrant/go/src/github.com/cloud-ark/kubeplus/platform-operator/helm-pod/main.go:404 +0xc5 github.com/emicklei/go-restful.(Container).dispatch(0xc00019a000, {0x1893a38, 0xc00019cee0}, 0xc0001dbf00) /home/vagrant/go/pkg/mod/github.com/emicklei/go-restful@v2.15.0+incompatible/container.go:294 +0x590 net/http.HandlerFunc.ServeHTTP(0x7fc14d5efbe8?, {0x1893a38?, 0xc00019cee0?}, 0x40ef25?) /usr/local/go/src/net/http/server.go:2084 +0x2f net/http.(ServeMux).ServeHTTP(0xc0003ccf71?, {0x1893a38, 0xc00019cee0}, 0xc0001dbf00) /usr/local/go/src/net/http/server.go:2462 +0x149 net/http.serverHandler.ServeHTTP({0xc0004635f0?}, {0x1893a38, 0xc00019cee0}, 0xc0001dbf00) /usr/local/go/src/net/http/server.go:2916 +0x43b net/http.(conn).serve(0xc0004699a0, {0x1894230, 0xc000463500}) /usr/local/go/src/net/http/server.go:1966 +0x5d7 created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:3071 +0x4db
This error arises in the getKubePlusPod() method in helmer's main.go: for _, podObj := range podList.Items { ownerRefObj := podObj.ObjectMeta.OwnerReferences[0] podOwnerName := ownerRefObj.Name if podOwnerName == replicaSetName { podName = podObj.ObjectMeta.Name //fmt.Printf("RSSetName:%s, PodName:%s\n", replicaSetName, podName) break } }
We should add a check to verify that a Pod indeed has a OwnerReference and only then try to de-reference it.