Skip to content

Commit e4a3069

Browse files
authored
fix: nil pointer dereference in btp configmap indexer (#6921)
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
1 parent cab067a commit e4a3069

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

internal/provider/kubernetes/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ func (r *gatewayAPIReconciler) processBtpConfigMapRefs(
12671267
) error {
12681268
for _, policy := range resourceTree.BackendTrafficPolicies {
12691269
for _, ro := range policy.Spec.ResponseOverride {
1270-
if ro.Response.Body != nil && ro.Response.Body.ValueRef != nil && string(ro.Response.Body.ValueRef.Kind) == resource.KindConfigMap {
1270+
if ro.Response != nil && ro.Response.Body != nil && ro.Response.Body.ValueRef != nil && string(ro.Response.Body.ValueRef.Kind) == resource.KindConfigMap {
12711271
configMap := new(corev1.ConfigMap)
12721272
err := r.client.Get(ctx,
12731273
types.NamespacedName{Namespace: policy.Namespace, Name: string(ro.Response.Body.ValueRef.Name)},

internal/provider/kubernetes/indexers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ func configMapBtpIndexFunc(rawObj client.Object) []string {
837837
var configMapReferences []string
838838

839839
for _, ro := range btp.Spec.ResponseOverride {
840-
if ro.Response.Body != nil && ro.Response.Body.ValueRef != nil {
840+
if ro.Response != nil && ro.Response.Body != nil && ro.Response.Body.ValueRef != nil {
841841
if string(ro.Response.Body.ValueRef.Kind) == resource.KindConfigMap {
842842
configMapReferences = append(configMapReferences,
843843
types.NamespacedName{

internal/provider/kubernetes/predicates_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,42 @@ func TestValidateConfigMapForReconcile(t *testing.T) {
286286
}
287287
}
288288

289+
// TestValidateBackendTrafficPolicyForReconcileWithRedirectResponseOverride tests the validateBackendTrafficPolicyForReconcile
290+
// predicate function with a redirect response override.
291+
func TestValidateBackendTrafficPolicyForReconcileWithRedirectResponseOverride(t *testing.T) {
292+
btpWithRedirect := &egv1a1.BackendTrafficPolicy{
293+
ObjectMeta: metav1.ObjectMeta{
294+
Name: "response-override",
295+
Namespace: "envoy-gateway-system",
296+
},
297+
Spec: egv1a1.BackendTrafficPolicySpec{
298+
ResponseOverride: []*egv1a1.ResponseOverride{
299+
{
300+
Match: egv1a1.CustomResponseMatch{
301+
StatusCodes: []egv1a1.StatusCodeMatch{
302+
{
303+
Type: &[]egv1a1.StatusCodeValueType{egv1a1.StatusCodeValueTypeRange}[0],
304+
Range: &egv1a1.StatusCodeRange{
305+
Start: 500,
306+
End: 511,
307+
},
308+
},
309+
},
310+
},
311+
// Using redirect instead of response causes ro.Response to be nil
312+
Redirect: &egv1a1.CustomRedirect{
313+
Hostname: &[]gwapiv1.PreciseHostname{"custom-errors.example.com"}[0],
314+
StatusCode: &[]int{302}[0],
315+
Scheme: &[]string{"https"}[0],
316+
},
317+
},
318+
},
319+
},
320+
}
321+
result := configMapBtpIndexFunc(btpWithRedirect)
322+
require.Empty(t, result)
323+
}
324+
289325
// TestValidateSecretForReconcile tests the validateSecretForReconcile
290326
// predicate function.
291327
func TestValidateSecretForReconcile(t *testing.T) {

release-notes/current.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ bug fixes: |
1717
Fixed log formatting of improper key-value pairs to avoid DPANIC in controller-runtime logger.
1818
Fixed handling of context-related transient errors to prevent incorrect state reconciliation and unintended behavior.
1919
Fixed the controller cannot read the EnvoyProxy attached gatewayclass only.
20+
Fixed indexer and controller crashing when BackendTrafficPolicy has a redirect response override.
2021
2122
# Enhancements that improve performance.
2223
performance improvements: |

0 commit comments

Comments
 (0)