Skip to content

Commit

Permalink
ingress: handle ingress rule without HTTPIngressRule
Browse files Browse the repository at this point in the history
Currently, defining an `Ingress` without an `HTTPIngressRule`
(e.g. only Host set) results in a panic in the Cilium Operator.

Therefore, this commit changes the ingress ingestion to process
the HTTP paths only if the HTTPIngressRule is set on the rule.

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
  • Loading branch information
mhofstetter authored and aditighag committed Aug 30, 2023
1 parent 8e381b9 commit 953e83e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions operator/pkg/model/ingestion/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ func Ingress(ing slim_networkingv1.Ingress, defaultSecretNamespace, defaultSecre
}

l.Hostname = host
if rule.HTTP == nil {
log.WithField(logfields.Ingress, ing.Namespace+"/"+ing.Name).
Warn("Invalid Ingress rule without spec.rules.HTTP defined, skipping rule")
continue
}

for _, path := range rule.HTTP.Paths {

route := model.HTTPRoute{}
Expand Down
20 changes: 19 additions & 1 deletion operator/pkg/model/ingestion/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1270,14 +1270,28 @@ func useDefaultListenersTLSsecret(listeners []model.HTTPListener) []model.HTTPLi
return ret
}

func removeIngressHTTPRuleValues(ing slim_networkingv1.Ingress) slim_networkingv1.Ingress {
var rules []slim_networkingv1.IngressRule

for _, r := range ing.Spec.Rules {
r.HTTP = nil
rules = append(rules, r)
}

ret := slim_networkingv1.Ingress{}
ing.DeepCopyInto(&ret)
ret.Spec.Rules = rules

return ret
}

type testcase struct {
ingress slim_networkingv1.Ingress
defaultSecret bool
want []model.HTTPListener
}

func TestIngress(t *testing.T) {

tests := map[string]testcase{
"conformance default backend test": {
ingress: defaultBackend,
Expand All @@ -1291,6 +1305,10 @@ func TestIngress(t *testing.T) {
ingress: defaultBackendLegacyOverride,
want: defaultBackendListeners,
},
"cilium test ingress without http rules": {
ingress: removeIngressHTTPRuleValues(hostRules),
want: []model.HTTPListener{},
},
"conformance host rules test": {
ingress: hostRules,
want: hostRulesListeners,
Expand Down

0 comments on commit 953e83e

Please sign in to comment.