From f8a4b09c6efcbac5cb0cdafd0aa61a7b15a0e2b1 Mon Sep 17 00:00:00 2001 From: vr4manta Date: Thu, 11 Sep 2025 13:48:05 -0400 Subject: [PATCH] Fixed "null" value for vSphere api and ingress VIP in UPI scenario --- .../infrastructureconfig/sync_specstatus.go | 6 +++ .../sync_specstatus_test.go | 47 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/pkg/controller/infrastructureconfig/sync_specstatus.go b/pkg/controller/infrastructureconfig/sync_specstatus.go index 22fc166646..1675d167eb 100644 --- a/pkg/controller/infrastructureconfig/sync_specstatus.go +++ b/pkg/controller/infrastructureconfig/sync_specstatus.go @@ -182,6 +182,12 @@ func syncVips(spec *[]configv1.IP, status *[]string) error { if spec == nil || status == nil { return fmt.Errorf("passed nil value as spec or status vip") } + + // If status is not initialized, it will cause issues when committing "null" value to update + if *status == nil { + *status = []string{} + } + // `spec` is empty, `status` with value: copy status to spec if len(*spec) == 0 { *spec = ip.StringsToIPs(*status) diff --git a/pkg/controller/infrastructureconfig/sync_specstatus_test.go b/pkg/controller/infrastructureconfig/sync_specstatus_test.go index 6d7cafdab6..572fd666c6 100644 --- a/pkg/controller/infrastructureconfig/sync_specstatus_test.go +++ b/pkg/controller/infrastructureconfig/sync_specstatus_test.go @@ -911,6 +911,53 @@ func Test_SpecStatusSynchronizer(t *testing.T) { }, }, }, + { + name: "should handle vSphere UPI: empty unset apiServerInternalIPs and ingressIPs", + givenInfra: configv1.Infrastructure{ + ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, + Spec: configv1.InfrastructureSpec{ + PlatformSpec: configv1.PlatformSpec{ + VSphere: &configv1.VSpherePlatformSpec{ + APIServerInternalIPs: []configv1.IP{}, + IngressIPs: []configv1.IP{}, + MachineNetworks: []configv1.CIDR{"224.0.0.1/24", "224.0.1.1/24"}, + }, + }, + }, + Status: configv1.InfrastructureStatus{ + Platform: configv1.VSpherePlatformType, + PlatformStatus: &configv1.PlatformStatus{ + Type: "VSphere", + VSphere: &configv1.VSpherePlatformStatus{ + MachineNetworks: []configv1.CIDR{"224.0.0.1/24", "224.0.1.1/24"}, + }, + }, + }, + }, + wantedInfra: configv1.Infrastructure{ + ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, + Spec: configv1.InfrastructureSpec{ + PlatformSpec: configv1.PlatformSpec{ + VSphere: &configv1.VSpherePlatformSpec{ + APIServerInternalIPs: []configv1.IP{}, + IngressIPs: []configv1.IP{}, + MachineNetworks: []configv1.CIDR{"224.0.0.1/24", "224.0.1.1/24"}, + }, + }, + }, + Status: configv1.InfrastructureStatus{ + Platform: configv1.VSpherePlatformType, + PlatformStatus: &configv1.PlatformStatus{ + Type: "VSphere", + VSphere: &configv1.VSpherePlatformStatus{ + APIServerInternalIPs: []string{}, + IngressIPs: []string{}, + MachineNetworks: []configv1.CIDR{"224.0.0.1/24", "224.0.1.1/24"}, + }, + }, + }, + }, + }, } for _, tt := range tests {