Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: panic at empty http spec #1660

Merged
merged 3 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/providers/ingress/translation/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ func (t *translator) translateIngressV1(ing *networkingv1.Ingress, skipVerify bo
ns = ingress.ServiceNamespace
}
for _, rule := range ing.Spec.Rules {
if rule.HTTP == nil {
continue
}
for _, pathRule := range rule.HTTP.Paths {
var (
ups *apisixv1.Upstream
Expand Down
33 changes: 33 additions & 0 deletions test/e2e/suite-ingress/suite-ingress-resource/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,39 @@ spec:
// Mismatched host
_ = s.NewAPISIXClient().GET("/anything/aaa/ok").WithHeader("Host", "a.httpbin.org").Expect().Status(http.StatusNotFound)
})

ginkgo.It("v1 ingress with empty http spec", func() {
backendSvc, backendPort := s.DefaultHTTPBackend()
ing := fmt.Sprintf(`
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: apisix
name: ingress-v1
spec:
rules:
- host: empty.httpbin.org
- host: httpbin.org
http:
paths:
- path: /status
pathType: Prefix
backend:
service:
name: %s
port:
number: %d
`, backendSvc, backendPort[0])
assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ing), "creating ingress")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1))

_ = s.NewAPISIXClient().GET("/status/500").WithHeader("Host", "httpbin.org").Expect().Status(http.StatusInternalServerError)
_ = s.NewAPISIXClient().GET("/status/504").WithHeader("Host", "httpbin.org").Expect().Status(http.StatusGatewayTimeout)
_ = s.NewAPISIXClient().GET("/statusaaa").WithHeader("Host", "httpbin.org").Expect().Status(http.StatusNotFound).Body().Contains("404 Route Not Found")
// Mismatched host
_ = s.NewAPISIXClient().GET("/status/200").WithHeader("Host", "empty.httpbin.org").Expect().Status(http.StatusNotFound)
})
})

var _ = ginkgo.Describe("suite-ingress-resource: support ingress.networking/v1beta1", func() {
Expand Down