Closed 1337andre closed 1 year ago
Hi @karl-johan-grahn I'd like to work on this enhancement. I have gone through the relevant code and my analysis is as follows.
Cause of this panic
In https://github.com/stakater/Forecastle/blob/53888ad5e54279585c9b6cde43651fe806dfcae0/pkg/kube/wrappers/ingress.go#L103 the Hosts
slice is empty and therefore attempting to access Hosts[0]
causes the runtime panic.
What can be done to make this access safe
Add a new method getTLSHosts
on the IngressWrapper
:
func (iw *IngressWrapper) getTLSHosts() []string {
if iw.supportsTLS() {
return iw.ingress.Spec.TLS[0].Hosts
}
return []string{}
}
Similarly change the method tryGetTLSHost
to:
func (iw *IngressWrapper) tryGetTLSHost() (string, bool) {
if iw.supportsTLS() && len(iw.getTLSHosts()) > 0 {
return "https://" + iw.ingress.Spec.TLS[0].Hosts[0], true
}
return "", false
}
Test cases In https://github.com/stakater/Forecastle/blob/master/pkg/testutil/kube.go add the following function to simulate a case where TLS hosts is empty:
func CreateIngressWithHostAndEmptyTLSHost(name string, host string) *v1.Ingress {
ingress := CreateIngressWithHost(name, host)
ingress.Spec.TLS = []v1.IngressTLS{
{
Hosts: []string{},
},
}
return ingress
}
Add the following test case in https://github.com/stakater/Forecastle/blob/53888ad5e54279585c9b6cde43651fe806dfcae0/pkg/kube/wrappers/ingress_test.go#L251
{
name: "IngressWithTLSAndNoHosts",
fields: fields{
ingress: testutil.CreateIngressWithHostAndEmptyTLSHost("someIngress", "google.com"),
},
want: "",
want1: false,
},
Let me know what do you think about this.
Hi folks,
thanks for this project!
For reasons we have a strange ingress deployment, which causes unfavourable behaviour of forcastle. In my option, forecastle should crash, when it runs into panic error. Now, it's still running with error logs, but empty page.
maybe it would be possible to skip strange ingress with some detailed error messages, so that all other valid ingress are still available?
basically it looks like this:
logs:
image/version: stakater/forecastle:v1.0.125