Skip to content

Commit 4987d7f

Browse files
weizhoubluejoestringer
authored andcommitted
Fix dedicated Ingress reconciliation panic on invalid TLS passthrough rules
Signed-off-by: weizhou.lan@daocloud.io <weizhou.lan@daocloud.io>
1 parent e189003 commit 4987d7f

2 files changed

Lines changed: 65 additions & 2 deletions

File tree

operator/pkg/ingress/ingress_reconcile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ func (r *ingressReconciler) buildDedicatedResources(ctx context.Context, ingress
259259
m := &model.Model{}
260260

261261
if annotations.GetAnnotationTLSPassthroughEnabled(ingress) {
262-
m.TLSPassthrough = append(m.TLSPassthrough, ingestion.IngressPassthrough(nil, *ingress, passthroughPort)...)
262+
m.TLSPassthrough = append(m.TLSPassthrough, ingestion.IngressPassthrough(scopedLog, *ingress, passthroughPort)...)
263263
} else {
264-
m.HTTP = append(m.HTTP, ingestion.Ingress(nil, *ingress, r.defaultSecretNamespace, r.defaultSecretName, r.enforcedHTTPS, insecureHTTPPort, secureHTTPPort, r.defaultRequestTimeout)...)
264+
m.HTTP = append(m.HTTP, ingestion.Ingress(scopedLog, *ingress, r.defaultSecretNamespace, r.defaultSecretName, r.enforcedHTTPS, insecureHTTPPort, secureHTTPPort, r.defaultRequestTimeout)...)
265265
}
266266

267267
cec, svc, err := r.dedicatedTranslator.Translate(m)

operator/pkg/ingress/ingress_reconcile_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,69 @@ func TestReconcile(t *testing.T) {
11211121
assert.Len(t, dedicatedIngressTranslator.model.HTTP, 1)
11221122
assert.Equal(t, uint32(55555), dedicatedIngressTranslator.model.HTTP[0].Port)
11231123
})
1124+
1125+
t.Run("Reconcile of dedicated TLS passthrough Ingress with a non-root path skips invalid rules without panicking", func(t *testing.T) {
1126+
pathType := networkingv1.PathTypePrefix
1127+
1128+
fakeClient := fake.NewClientBuilder().
1129+
WithScheme(testScheme()).
1130+
WithObjects(
1131+
&networkingv1.Ingress{
1132+
ObjectMeta: metav1.ObjectMeta{
1133+
Namespace: "test",
1134+
Name: "test",
1135+
Annotations: map[string]string{
1136+
"ingress.cilium.io/loadbalancer-mode": "dedicated",
1137+
"ingress.cilium.io/tls-passthrough": "true",
1138+
},
1139+
},
1140+
Spec: networkingv1.IngressSpec{
1141+
IngressClassName: ptr.To("cilium"),
1142+
Rules: []networkingv1.IngressRule{
1143+
{
1144+
Host: "example.com",
1145+
IngressRuleValue: networkingv1.IngressRuleValue{
1146+
HTTP: &networkingv1.HTTPIngressRuleValue{
1147+
Paths: []networkingv1.HTTPIngressPath{
1148+
{
1149+
Path: "/api/webhook",
1150+
PathType: &pathType,
1151+
Backend: networkingv1.IngressBackend{
1152+
Service: &networkingv1.IngressServiceBackend{
1153+
Name: "test",
1154+
Port: networkingv1.ServiceBackendPort{
1155+
Number: 8080,
1156+
},
1157+
},
1158+
},
1159+
},
1160+
},
1161+
},
1162+
},
1163+
},
1164+
},
1165+
},
1166+
},
1167+
).
1168+
Build()
1169+
1170+
cecTranslator := &fakeCECTranslator{}
1171+
dedicatedIngressTranslator := &fakeDedicatedIngressTranslator{}
1172+
1173+
reconciler := newIngressReconciler(logger, fakeClient, cecTranslator, dedicatedIngressTranslator, testCiliumNamespace, []string{}, testDefaultLoadbalancingServiceName, "dedicated", testDefaultSecretNamespace, testDefaultSecretName, false, testIngressDefaultRequestTimeout, false, 0, 0, 0, 0)
1174+
1175+
result, err := reconciler.Reconcile(t.Context(), reconcile.Request{
1176+
NamespacedName: types.NamespacedName{
1177+
Namespace: "test",
1178+
Name: "test",
1179+
},
1180+
})
1181+
require.NoError(t, err)
1182+
require.NotNil(t, result)
1183+
1184+
assert.Empty(t, dedicatedIngressTranslator.model.TLSPassthrough)
1185+
assert.Empty(t, dedicatedIngressTranslator.model.HTTP)
1186+
})
11241187
}
11251188

11261189
var _ translation.CECTranslator = &fakeCECTranslator{}

0 commit comments

Comments
 (0)