Skip to content

Conversation

@pkieszcz
Copy link

@pkieszcz pkieszcz commented Jan 19, 2026

What type of PR is this?

/kind bug

What this PR does / why we need it:

Fixes two nil pointer dereference issues when creating/reconciling private GKE clusters with PSC (Private Service Connect) mode - i.e., when enablePrivateEndpoint: true without specifying controlPlaneCidrBlock.

Fix 1: Creation path (related to #1503)

In createCluster, cluster.NetworkConfig.DefaultEnablePrivateNodes was accessed before NetworkConfig was initialized.

Changes:

  • Initialize NetworkConfig before accessing DefaultEnablePrivateNodes
  • Set EnablePrivateNodes on PrivateClusterConfig to match (GCP SDK requires both fields to have the same value)

Fix 2: Reconciliation path

In checkDiffAndPrepareUpdate, clusterUpdate.DesiredControlPlaneEndpointsConfig.IpEndpointsConfig.AuthorizedNetworksConfig was assigned without initializing the parent structs.

Changes:

  • Initialize DesiredControlPlaneEndpointsConfig and IpEndpointsConfig before assigning AuthorizedNetworksConfig

Which issue(s) this PR fixes:
Fixes #1497

Special notes for your reviewer:

This PR combines the fix from #1503 (which was closed) with an additional fix for the reconciliation path. Both issues have the same root cause and affect private cluster functionality.

Reproduction steps:

  1. Create a GKE cluster with enablePrivateEndpoint: true and no controlPlaneCidrBlock (PSC mode)
  2. Fix 1: Controller panics during cluster creation
  3. Fix 2: If cluster is created successfully, controller panics during reconciliation when master_authorized_networks_config differs

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests

Release note:

Fix nil pointer dereferences when creating/reconciling private GKE clusters with PSC mode

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Jan 19, 2026
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pkieszcz
Once this PR has been reviewed and has the lgtm label, please assign enxebre 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

@netlify
Copy link

netlify bot commented Jan 19, 2026

Deploy Preview for kubernetes-sigs-cluster-api-gcp ready!

Name Link
🔨 Latest commit b42c715
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-sigs-cluster-api-gcp/deploys/696e1dae078a1b0008dcddf0
😎 Deploy Preview https://deploy-preview-1591--kubernetes-sigs-cluster-api-gcp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot k8s-ci-robot requested review from cpanato and dims January 19, 2026 09:46
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 19, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: pkieszcz / name: Piotr Kieszczyński (b42c715)

@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 Jan 19, 2026
@k8s-ci-robot
Copy link
Contributor

Welcome @pkieszcz!

It looks like this is your first PR to kubernetes-sigs/cluster-api-provider-gcp 🎉. 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/cluster-api-provider-gcp 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
Copy link
Contributor

Hi @pkieszcz. 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 Jan 19, 2026
@pkieszcz pkieszcz force-pushed the fix-checkdiffandprepareupdate-nil-pointer branch from fb148d8 to 12954c9 Compare January 19, 2026 09:48
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 19, 2026
@pkieszcz pkieszcz changed the title fix: nil pointer in checkDiffAndPrepareUpdate for MasterAuthorizedNetworksConfig fix: nil pointer dereferences in private cluster creation and reconciliation Jan 19, 2026
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jan 19, 2026
Copy link
Contributor

@salasberryfin salasberryfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 19, 2026
Fixes two nil pointer dereference issues when creating/reconciling
private GKE clusters:

1. Creation path: Initialize NetworkConfig before accessing
   DefaultEnablePrivateNodes. Also set EnablePrivateNodes on
   PrivateClusterConfig to match (GCP SDK requires both to be equal).

2. Reconciliation path: Initialize DesiredControlPlaneEndpointsConfig
   and IpEndpointsConfig before assigning AuthorizedNetworksConfig
   in checkDiffAndPrepareUpdate.

Both issues occur when using private clusters with PSC (Private Service
Connect) mode, i.e., enablePrivateEndpoint: true without specifying
controlPlaneCidrBlock.

Signed-off-by: Piotr Kieszczyński <piotr.kieszczynski@gmail.com>
@pkieszcz pkieszcz force-pushed the fix-checkdiffandprepareupdate-nil-pointer branch from 12954c9 to b42c715 Compare January 19, 2026 12:03
Copy link
Contributor

@salasberryfin salasberryfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pkieszcz. It would also be nice to have a test for this specific reconcile loop, as it would make it easy to spot simple errors like this one.

// DesiredMasterAuthorizedNetworksConfig
// When desiredMasterAuthorizedNetworksConfig is nil, it means that the user wants to disable the feature.
desiredMasterAuthorizedNetworksConfig := convertToSdkMasterAuthorizedNetworksConfig(s.scope.GCPManagedControlPlane.Spec.MasterAuthorizedNetworksConfig)
if !compareMasterAuthorizedNetworksConfig(desiredMasterAuthorizedNetworksConfig, existingCluster.GetControlPlaneEndpointsConfig().GetIpEndpointsConfig().GetAuthorizedNetworksConfig()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably worth changing this too:

existingCluster.GetControlPlaneEndpointsConfig().GetIpEndpointsConfig().GetAuthorizedNetworksConfig()

compareMasterAuthorizedNetworksConfig() deals with nil values and it's safe to use but what if any of the intermediate methods on existingCluster returns nil?

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

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gcpmanagedcontrolplane panics on nil pointer dereference for PrivateClusters

3 participants