@@ -14,6 +14,7 @@ import (
1414 "github.com/openshift/installer/pkg/asset/installconfig"
1515 "github.com/openshift/installer/pkg/asset/manifests/capiutils"
1616 "github.com/openshift/installer/pkg/asset/manifests/capiutils/cidr"
17+ "github.com/openshift/installer/pkg/types"
1718)
1819
1920// GenerateClusterAssets generates the manifests for the cluster-api.
@@ -41,8 +42,13 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
4142
4243 resourceGroup := installConfig .Config .Platform .Azure .ClusterResourceGroupName (clusterID .InfraID )
4344 controlPlaneSubnet := installConfig .Config .Platform .Azure .ControlPlaneSubnetName (clusterID .InfraID )
44- networkSecurityGroup := installConfig .Config .Platform .Azure .NetworkSecurityGroupName (clusterID .InfraID )
4545 computeSubnet := installConfig .Config .Platform .Azure .ComputeSubnetName (clusterID .InfraID )
46+ networkSecurityGroup := installConfig .Config .Platform .Azure .NetworkSecurityGroupName (clusterID .InfraID )
47+
48+ source := "*"
49+ if installConfig .Config .Publish == types .InternalPublishingStrategy {
50+ source = mainCIDR .String ()
51+ }
4652
4753 securityGroup := capz.SecurityGroup {
4854 Name : networkSecurityGroup ,
@@ -55,14 +61,13 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
5561 Priority : 101 ,
5662 SourcePorts : ptr .To ("*" ),
5763 DestinationPorts : ptr .To ("6443" ),
58- Source : ptr .To ("*" ),
64+ Source : ptr .To (source ),
5965 Destination : ptr .To ("*" ),
6066 Action : capz .SecurityRuleActionAllow ,
6167 },
6268 },
6369 },
6470 }
65-
6671 azureCluster := & capz.AzureCluster {
6772 ObjectMeta : metav1.ObjectMeta {
6873 Name : clusterID .InfraID ,
@@ -86,6 +91,13 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
8691 PrivateDNSZoneName : installConfig .Config .ClusterDomain (),
8792 },
8893 Vnet : capz.VnetSpec {
94+ ResourceGroup : installConfig .Config .Azure .NetworkResourceGroupName ,
95+ Name : installConfig .Config .Azure .VirtualNetwork ,
96+ // The ID is set to virtual network here for existing vnets here. This is to force CAPZ to consider this resource as
97+ // "not managed" which would prevent the creation of an additional nsg and route table in the network resource group.
98+ // The ID field is not used for any other purpose in CAPZ except to set the "managed" status.
99+ // See https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/main/azure/scope/cluster.go#L585
100+ // https://github.com/kubernetes-sigs/cluster-api-provider-azure/commit/0f321e4089a3f4dc37f8420bf2ef6762c398c400
89101 ID : installConfig .Config .Azure .VirtualNetwork ,
90102 VnetClassSpec : capz.VnetClassSpec {
91103 CIDRBlocks : []string {
0 commit comments