Skip to content

Commit 476bdec

Browse files
committed
pkg/storage/azure: support private endpoint creation with custom network resource group
when users bring their our network, they will commonly have a dedicated resource group where the network resources are. vnet and subnet ids contain the resource group of where these resources exist in, so the operator needs to distinguish between the cluster resource group, and the user provided network resource group. this commit adds support for such use-case. note that it's importante that the private endpoint is created within the cluster resource group, which is managed by the installer. this is so that the private endpoint is guaranteed to be destroyed when the cluster itself is destroyed.
1 parent c2face0 commit 476bdec

File tree

4 files changed

+120
-105
lines changed

4 files changed

+120
-105
lines changed

pkg/storage/azure/azure.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,6 @@ func (d *driver) assurePrivateAccount(cfg *Azure, infra *configv1.Infrastructure
562562
ClientSecret: cfg.ClientSecret,
563563
FederatedTokenFile: cfg.FederatedTokenFile,
564564
SubscriptionID: cfg.SubscriptionID,
565-
ResourceGroupName: cfg.ResourceGroup,
566565
TagSet: tagset,
567566
})
568567
if err != nil {
@@ -581,24 +580,29 @@ func (d *driver) assurePrivateAccount(cfg *Azure, infra *configv1.Infrastructure
581580
privateEndpointName = generateAccountName(infra.Status.InfrastructureName)
582581
}
583582

583+
networkResourceGroup := cfg.ResourceGroup
584+
if internalConfig.NetworkResourceGroupName != "" {
585+
networkResourceGroup = internalConfig.NetworkResourceGroupName
586+
}
587+
584588
// the last step in this function is to disable public network for the
585589
// storage account - if we already did that, then none of the steps
586590
// below need to be executed.
587-
if azclient.IsStorageAccountPrivate(d.Context, accountName) {
591+
if azclient.IsStorageAccountPrivate(d.Context, cfg.ResourceGroup, accountName) {
588592
return privateEndpointName, nil
589593
}
590594

591595
if internalConfig.VNetName == "" {
592596
tagKey := fmt.Sprintf("kubernetes.io_cluster.%s", infra.Status.InfrastructureName)
593-
vnet, err := azclient.GetVNetByTag(d.Context, tagKey, "owned", "shared")
597+
vnet, err := azclient.GetVNetByTag(d.Context, networkResourceGroup, tagKey, "owned", "shared")
594598
if err != nil {
595599
return "", fmt.Errorf("failed to discover vnet name, please provide network details manually: %q", err)
596600
}
597601
internalConfig.VNetName = *vnet.Name
598602
}
599603

600604
if internalConfig.SubnetName == "" {
601-
subnet, err := azclient.GetSubnetsByVNet(d.Context, internalConfig.VNetName)
605+
subnet, err := azclient.GetSubnetsByVNet(d.Context, networkResourceGroup, internalConfig.VNetName)
602606
if err != nil {
603607
return "", fmt.Errorf("failed to discover subnet name, please provide network details manually: %q", err)
604608
}
@@ -609,11 +613,13 @@ func (d *driver) assurePrivateAccount(cfg *Azure, infra *configv1.Infrastructure
609613
pe, err := azclient.CreatePrivateEndpoint(
610614
d.Context,
611615
&azureclient.PrivateEndpointCreateOptions{
612-
Location: cfg.Region,
613-
VNetName: internalConfig.VNetName,
614-
SubnetName: internalConfig.SubnetName,
615-
PrivateEndpointName: privateEndpointName,
616-
StorageAccountName: accountName,
616+
Location: cfg.Region,
617+
ClusterResourceGroupName: cfg.ResourceGroup,
618+
NetworkResourceGroupName: networkResourceGroup,
619+
VNetName: internalConfig.VNetName,
620+
SubnetName: internalConfig.SubnetName,
621+
PrivateEndpointName: privateEndpointName,
622+
StorageAccountName: accountName,
617623
},
618624
)
619625
if err != nil {
@@ -623,14 +629,14 @@ func (d *driver) assurePrivateAccount(cfg *Azure, infra *configv1.Infrastructure
623629

624630
klog.V(3).Info("configuring private DNS...")
625631
if err := azclient.ConfigurePrivateDNS(
626-
d.Context, pe, internalConfig.VNetName, accountName,
632+
d.Context, pe, cfg.ResourceGroup, networkResourceGroup, internalConfig.VNetName, accountName,
627633
); err != nil {
628634
return privateEndpointName, err
629635
}
630636
klog.V(3).Info("private DNS configured")
631637

632638
klog.V(3).Infof("disabling public network access for storage account %q...", accountName)
633-
if err := azclient.UpdateStorageAccountNetworkAccess(d.Context, accountName, false); err != nil {
639+
if err := azclient.UpdateStorageAccountNetworkAccess(d.Context, cfg.ResourceGroup, accountName, false); err != nil {
634640
return privateEndpointName, err
635641
}
636642

@@ -952,7 +958,6 @@ func (d *driver) RemoveStorage(cr *imageregistryv1.Config) (retry bool, err erro
952958
ClientSecret: cfg.ClientSecret,
953959
FederatedTokenFile: cfg.FederatedTokenFile,
954960
SubscriptionID: cfg.SubscriptionID,
955-
ResourceGroupName: cfg.ResourceGroup,
956961
})
957962
if err != nil {
958963
util.UpdateCondition(
@@ -966,6 +971,7 @@ func (d *driver) RemoveStorage(cr *imageregistryv1.Config) (retry bool, err erro
966971
}
967972
if err := azclient.DestroyPrivateDNS(
968973
d.Context,
974+
cfg.ResourceGroup,
969975
d.Config.NetworkAccess.Internal.PrivateEndpointName,
970976
d.Config.NetworkAccess.Internal.VNetName,
971977
d.Config.AccountName,
@@ -980,7 +986,7 @@ func (d *driver) RemoveStorage(cr *imageregistryv1.Config) (retry bool, err erro
980986
return false, err
981987
}
982988
if err := azclient.DeletePrivateEndpoint(
983-
d.Context, d.Config.NetworkAccess.Internal.PrivateEndpointName,
989+
d.Context, cfg.ResourceGroup, d.Config.NetworkAccess.Internal.PrivateEndpointName,
984990
); err != nil {
985991
util.UpdateCondition(
986992
cr,

0 commit comments

Comments
 (0)