Skip to content

fix: return early in service reconciler when lb is nil#4725

Open
joey-jonko-paypal wants to merge 1 commit into
kubernetes-sigs:mainfrom
joey-jonko-paypal:fix/service-reconciler-nil-lb-fallthrough
Open

fix: return early in service reconciler when lb is nil#4725
joey-jonko-paypal wants to merge 1 commit into
kubernetes-sigs:mainfrom
joey-jonko-paypal:fix/service-reconciler-nil-lb-fallthrough

Conversation

@joey-jonko-paypal
Copy link
Copy Markdown

What does this PR do?

Fixes a nil pointer dereference panic in the service reconciler that fires when buildModel returns lb == nil — for example, when a ClusterIP-typed Service is reconciled (such as one created by Istio Gateway API via networking.istio.io/service-type: ClusterIP).

Root cause

In reconcile(), when lb == nil, the reconciler correctly enters the cleanup branch and calls cleanupLoadBalancerResources. However, on successful cleanup it falls through to reconcileLoadBalancerResources(ctx, svc, stack, lb, backendSGRequired) with lb still nil. This causes a nil pointer dereference inside reconcileLoadBalancerResources at:

lbDNS, err = lb.DNSName().Resolve(ctx) // panic: lb is nil

The panic is recovered by runtime.HandleReconcileError, so it manifests as repeated error log noise rather than a crash. Load balancer provisioning is unaffected.

Fix

Add return nil after the successful cleanup path when lb == nil, so the reconciler exits cleanly:

if lb == nil {
    // ... cleanup ...
    if err != nil {
        return ctrlerrors.NewErrorWithMetrics(...)
    }
    return nil // <-- added
}
return r.reconcileLoadBalancerResources(ctx, svc, stack, lb, backendSGRequired)

How to reproduce

  1. Install Istio with Gateway API support.
  2. Create a Gateway with networking.istio.io/service-type: ClusterIP (used to suppress NLB provisioning when an external ALB is managed separately via a Kubernetes Ingress resource).
  3. Observe repeated panic logs from the service reconciler for the <gateway-name>-istio ClusterIP service in the controller's namespace.

Testing

Existing unit tests pass. The code path is straightforward: the only change is the addition of return nil to prevent the fall-through.

Closes #4724


Release note:

Fix nil pointer dereference panic in service reconciler when reconciling a ClusterIP service (e.g. created by Istio Gateway API with networking.istio.io/service-type: ClusterIP) where buildModel returns lb == nil.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label May 5, 2026
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 5, 2026

CLA Not Signed

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @joey-jonko-paypal!

It looks like this is your first PR to kubernetes-sigs/aws-load-balancer-controller 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/aws-load-balancer-controller has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 5, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @joey-jonko-paypal. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 5, 2026
When buildModel returns lb == nil (e.g. for a ClusterIP service that
should not have a load balancer, such as one created by Istio Gateway
API with networking.istio.io/service-type: ClusterIP), the reconciler
correctly runs cleanupLoadBalancerResources but then falls through to
reconcileLoadBalancerResources with lb still nil. This causes a nil
pointer dereference panic at lb.DNSName().Resolve(ctx).

Add a return nil after successful cleanup when lb == nil so the
reconciler exits cleanly without entering the LB provisioning path.

Related: kubernetes-sigs#4724

Signed-off-by: Joey Jonko <joey.jonko@happyreturns.com>
@joey-jonko-paypal joey-jonko-paypal force-pushed the fix/service-reconciler-nil-lb-fallthrough branch from 77d7545 to b299b3d Compare May 5, 2026 18:40
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label May 5, 2026
@wweiwei-li
Copy link
Copy Markdown
Collaborator

Do you want to fix EasyCLA ? Else, I can submit a change for this.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 56.13%. Comparing base (22cdb42) to head (b299b3d).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
controllers/service/service_controller.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4725      +/-   ##
==========================================
+ Coverage   56.09%   56.13%   +0.03%     
==========================================
  Files         388      388              
  Lines       30932    30948      +16     
==========================================
+ Hits        17352    17373      +21     
+ Misses      12566    12564       -2     
+ Partials     1014     1011       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: joey-jonko-paypal, sandeep-rajan-glean
Once this PR has been reviewed and has the lgtm label, please assign zac-nixon for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nil pointer panic in service reconciler when reconciling ClusterIP service created by Istio Gateway API (networking.istio.io/service-type: ClusterIP)

5 participants