Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ARO-15009] fix: add logic to skip subnet update under certain conditions #4087

Merged
merged 3 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions pkg/cluster/deploybaseresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,27 @@ func (m *manager) setMasterSubnetPolicies(ctx context.Context) error {
s.SubnetPropertiesFormat = &mgmtnetwork.SubnetPropertiesFormat{}
}

// we need to track whether or not we need to send an update to the AzureRM API based on whether
// or not our private endpoint network policies or private link service network policies
// already match a desired condition of 'Disabled' or not.
var needsUpdate bool

if m.doc.OpenShiftCluster.Properties.FeatureProfile.GatewayEnabled {
s.SubnetPropertiesFormat.PrivateEndpointNetworkPolicies = to.StringPtr("Disabled")
if s.SubnetPropertiesFormat.PrivateEndpointNetworkPolicies == nil || *s.SubnetPropertiesFormat.PrivateEndpointNetworkPolicies != "Disabled" {
needsUpdate = true
s.SubnetPropertiesFormat.PrivateEndpointNetworkPolicies = to.StringPtr("Disabled")
}
}

if s.SubnetPropertiesFormat.PrivateLinkServiceNetworkPolicies == nil || *s.SubnetPropertiesFormat.PrivateLinkServiceNetworkPolicies != "Disabled" {
needsUpdate = true
s.SubnetPropertiesFormat.PrivateLinkServiceNetworkPolicies = to.StringPtr("Disabled")
}

// return if we do not need to update the subnet
if !needsUpdate {
return nil
}
s.SubnetPropertiesFormat.PrivateLinkServiceNetworkPolicies = to.StringPtr("Disabled")

err = m.subnet.CreateOrUpdate(ctx, subnetId, s)

Expand Down
24 changes: 24 additions & 0 deletions pkg/cluster/deploybaseresources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,30 @@ func TestSetMasterSubnetPolicies(t *testing.T) {
},
gatewayEnabled: true,
},
{
name: "ok, skipCreateOrUpdate, !gatewayEnabled",
mocks: func(subnet *mock_subnet.MockManager) {
subnet.EXPECT().Get(ctx, "subnetID").Return(&mgmtnetwork.Subnet{
SubnetPropertiesFormat: &mgmtnetwork.SubnetPropertiesFormat{
PrivateLinkServiceNetworkPolicies: to.StringPtr("Disabled"),
},
}, nil)
subnet.EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
},
},
{
name: "ok, skipCreateOrUpdate, gatewayEnabled",
mocks: func(subnet *mock_subnet.MockManager) {
subnet.EXPECT().Get(ctx, "subnetID").Return(&mgmtnetwork.Subnet{
SubnetPropertiesFormat: &mgmtnetwork.SubnetPropertiesFormat{
PrivateEndpointNetworkPolicies: to.StringPtr("Disabled"),
PrivateLinkServiceNetworkPolicies: to.StringPtr("Disabled"),
},
}, nil)
subnet.EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
},
gatewayEnabled: true,
},
{
name: "error",
mocks: func(subnet *mock_subnet.MockManager) {
Expand Down
Loading