Skip to content

Commit fb148d8

Browse files
committed
fix: nil pointer in checkDiffAndPrepareUpdate for MasterAuthorizedNetworksConfig
Initialize DesiredControlPlaneEndpointsConfig and IpEndpointsConfig before assigning AuthorizedNetworksConfig to prevent nil pointer dereference during cluster reconciliation. When reconciling a GKE cluster, checkDiffAndPrepareUpdate compares the desired MasterAuthorizedNetworksConfig with the existing one. If they differ, it attempts to set clusterUpdate.DesiredControlPlaneEndpointsConfig .IpEndpointsConfig.AuthorizedNetworksConfig without first initializing the parent structs, causing a nil pointer dereference. This is related to issue #1497 but affects the update/reconciliation path rather than the creation path addressed in PR #1503. Signed-off-by: Piotr Kieszczyński <piotr.kieszczynski@gmail.com>
1 parent e6e3646 commit fb148d8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

cloud/services/container/clusters/reconcile.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,12 @@ func (s *Service) checkDiffAndPrepareUpdate(existingCluster *containerpb.Cluster
516516
desiredMasterAuthorizedNetworksConfig := convertToSdkMasterAuthorizedNetworksConfig(s.scope.GCPManagedControlPlane.Spec.MasterAuthorizedNetworksConfig)
517517
if !compareMasterAuthorizedNetworksConfig(desiredMasterAuthorizedNetworksConfig, existingCluster.GetControlPlaneEndpointsConfig().GetIpEndpointsConfig().GetAuthorizedNetworksConfig()) {
518518
needUpdate = true
519+
if clusterUpdate.DesiredControlPlaneEndpointsConfig == nil {
520+
clusterUpdate.DesiredControlPlaneEndpointsConfig = &containerpb.ControlPlaneEndpointsConfig{}
521+
}
522+
if clusterUpdate.DesiredControlPlaneEndpointsConfig.IpEndpointsConfig == nil {
523+
clusterUpdate.DesiredControlPlaneEndpointsConfig.IpEndpointsConfig = &containerpb.ControlPlaneEndpointsConfig_IPEndpointsConfig{}
524+
}
519525
clusterUpdate.DesiredControlPlaneEndpointsConfig.IpEndpointsConfig.AuthorizedNetworksConfig = desiredMasterAuthorizedNetworksConfig
520526
log.V(2).Info("Master authorized networks config update required", "current", existingCluster.GetControlPlaneEndpointsConfig().GetIpEndpointsConfig().GetAuthorizedNetworksConfig(), "desired", desiredMasterAuthorizedNetworksConfig)
521527
}

0 commit comments

Comments
 (0)