From 98580734e5e6adaadd8b1586b766a2b021efdc88 Mon Sep 17 00:00:00 2001 From: Tanmay Satam Date: Fri, 1 Nov 2024 09:00:00 -0400 Subject: [PATCH] Fix AdminAPI representation of PreconfiguredNSG status (#3933) * Fix spelling of preconfiguredNSG JSON tag * Copy PreconfiguredNSG property during internal->admin conversion * Fix nil pointer dereference when converting workload identity cluster doc to adminapi representation * Update admin openshiftcluster_putorpatch tests to expect property for PreconfiguredNSG --- pkg/api/admin/openshiftcluster.go | 2 +- pkg/api/admin/openshiftcluster_convert.go | 2 + .../openshiftcluster_putorpatch_test.go | 51 ++++++++++++------- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/pkg/api/admin/openshiftcluster.go b/pkg/api/admin/openshiftcluster.go index 17739dedf94..15b01ff2c64 100644 --- a/pkg/api/admin/openshiftcluster.go +++ b/pkg/api/admin/openshiftcluster.go @@ -230,7 +230,7 @@ type NetworkProfile struct { APIServerPrivateEndpointIP string `json:"privateEndpointIp,omitempty"` GatewayPrivateEndpointIP string `json:"gatewayPrivateEndpointIp,omitempty"` GatewayPrivateLinkID string `json:"gatewayPrivateLinkId,omitempty"` - PreconfiguredNSG PreconfiguredNSG `json:"preconfigureNSG,omitempty"` + PreconfiguredNSG PreconfiguredNSG `json:"preconfiguredNSG,omitempty"` LoadBalancerProfile *LoadBalancerProfile `json:"loadBalancerProfile,omitempty"` } diff --git a/pkg/api/admin/openshiftcluster_convert.go b/pkg/api/admin/openshiftcluster_convert.go index 10de0898f9b..af629b500a8 100644 --- a/pkg/api/admin/openshiftcluster_convert.go +++ b/pkg/api/admin/openshiftcluster_convert.go @@ -54,6 +54,7 @@ func (c openShiftClusterConverter) ToExternal(oc *api.OpenShiftCluster) interfac APIServerPrivateEndpointIP: oc.Properties.NetworkProfile.APIServerPrivateEndpointIP, GatewayPrivateEndpointIP: oc.Properties.NetworkProfile.GatewayPrivateEndpointIP, GatewayPrivateLinkID: oc.Properties.NetworkProfile.GatewayPrivateLinkID, + PreconfiguredNSG: PreconfiguredNSG(oc.Properties.NetworkProfile.PreconfiguredNSG), }, MasterProfile: MasterProfile{ VMSize: VMSize(oc.Properties.MasterProfile.VMSize), @@ -178,6 +179,7 @@ func (c openShiftClusterConverter) ToExternal(oc *api.OpenShiftCluster) interfac } if oc.Identity != nil { + out.Identity = &ManagedServiceIdentity{} out.Identity.Type = ManagedServiceIdentityType(oc.Identity.Type) out.Identity.UserAssignedIdentities = make(map[string]UserAssignedIdentity, len(oc.Identity.UserAssignedIdentities)) for k := range oc.Identity.UserAssignedIdentities { diff --git a/pkg/frontend/openshiftcluster_putorpatch_test.go b/pkg/frontend/openshiftcluster_putorpatch_test.go index 7c4a9bc1426..30e4926efe9 100644 --- a/pkg/frontend/openshiftcluster_putorpatch_test.go +++ b/pkg/frontend/openshiftcluster_putorpatch_test.go @@ -146,7 +146,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { }, MaintenanceTask: admin.MaintenanceTaskEverything, NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1, @@ -245,7 +246,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { LastProvisioningState: admin.ProvisioningStateSucceeded, MaintenanceTask: admin.MaintenanceTaskOperator, NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1, @@ -343,7 +345,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { LastProvisioningState: admin.ProvisioningStateSucceeded, MaintenanceTask: admin.MaintenanceTaskEverything, NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1, @@ -442,7 +445,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { }, MaintenanceTask: admin.MaintenanceTaskOperator, NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1, @@ -551,7 +555,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { LastProvisioningState: admin.ProvisioningStateSucceeded, MaintenanceTask: admin.MaintenanceTaskOperator, NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1, @@ -654,7 +659,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { }, MaintenanceTask: admin.MaintenanceTaskOperator, NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1, @@ -835,7 +841,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { }, MaintenanceTask: "", NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1, @@ -935,7 +942,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { }, MaintenanceTask: "", NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1, @@ -1034,7 +1042,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { }, MaintenanceTask: admin.MaintenanceTaskEverything, NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1, @@ -1134,7 +1143,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { }, MaintenanceTask: "", NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1, @@ -1234,7 +1244,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { }, MaintenanceTask: "", NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1, @@ -1332,7 +1343,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { }, MaintenanceTask: admin.MaintenanceTaskEverything, NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1, @@ -1433,7 +1445,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { FipsValidatedModules: admin.FipsValidatedModulesDisabled, }, NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1, @@ -1535,7 +1548,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { FipsValidatedModules: admin.FipsValidatedModulesDisabled, }, NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1, @@ -1637,7 +1651,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { FipsValidatedModules: admin.FipsValidatedModulesDisabled, }, NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1, @@ -1739,7 +1754,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { FipsValidatedModules: admin.FipsValidatedModulesDisabled, }, NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1, @@ -1842,7 +1858,8 @@ func TestPutOrPatchOpenShiftClusterAdminAPI(t *testing.T) { FipsValidatedModules: admin.FipsValidatedModulesDisabled, }, NetworkProfile: admin.NetworkProfile{ - OutboundType: admin.OutboundTypeLoadbalancer, + OutboundType: admin.OutboundTypeLoadbalancer, + PreconfiguredNSG: admin.PreconfiguredNSGDisabled, LoadBalancerProfile: &admin.LoadBalancerProfile{ ManagedOutboundIPs: &admin.ManagedOutboundIPs{ Count: 1,