@@ -471,21 +471,49 @@ func addFirewallRules(
471471 return nil
472472}
473473
474- func addAirgapNetworkSettings (ctx context.Context , clusterModel * armcontainerservice.ManagedCluster , privateACRName , location string ) error {
475- toolkit .Logf (ctx , "Adding network settings for airgap cluster %s in rg %s" , * clusterModel .Name , * clusterModel .Properties .NodeResourceGroup )
474+ func addPrivateAzureContainerRegistry (ctx context.Context , cluster * armcontainerservice.ManagedCluster , kube * Kubeclient , resourceGroupName string , kubeletIdentity * armcontainerservice.UserAssignedIdentity , isNonAnonymousPull bool ) error {
475+ if cluster == nil || kube == nil || kubeletIdentity == nil {
476+ return errors .New ("cluster, kubeclient, and kubeletIdentity cannot be nil when adding Private Azure Container Registry" )
477+ }
478+ if err := createPrivateAzureContainerRegistry (ctx , cluster , resourceGroupName , isNonAnonymousPull ); err != nil {
479+ return fmt .Errorf ("failed to create private acr: %w" , err )
480+ }
481+
482+ if err := createPrivateAzureContainerRegistryPullSecret (ctx , cluster , kube , resourceGroupName , isNonAnonymousPull ); err != nil {
483+ return fmt .Errorf ("create private acr pull secret: %w" , err )
484+ }
485+ vnet , err := getClusterVNet (ctx , * cluster .Properties .NodeResourceGroup )
486+ if err != nil {
487+ return err
488+ }
489+
490+ err = addPrivateEndpointForACR (ctx , * cluster .Properties .NodeResourceGroup , config .GetPrivateACRName (isNonAnonymousPull , * cluster .Location ), vnet , * cluster .Location )
491+ if err != nil {
492+ return err
493+ }
494+
495+ if err := assignACRPullToIdentity (ctx , config .GetPrivateACRName (isNonAnonymousPull , * cluster .Location ), * kubeletIdentity .ObjectID , * cluster .Location ); err != nil {
496+ return fmt .Errorf ("assigning acr pull permissions to kubelet identity: %w" , err )
497+ }
498+
499+ return nil
500+ }
501+
502+ func addNetworkIsolatedSettings (ctx context.Context , clusterModel * armcontainerservice.ManagedCluster , location string ) error {
503+ defer toolkit .LogStepCtx (ctx , fmt .Sprintf ("Adding network settings for network isolated cluster %s in rg %s" , * clusterModel .Name , * clusterModel .Properties .NodeResourceGroup ))
476504
477505 vnet , err := getClusterVNet (ctx , * clusterModel .Properties .NodeResourceGroup )
478506 if err != nil {
479507 return err
480508 }
481509 subnetId := vnet .subnetId
482510
483- nsgParams , err := airGapSecurityGroup (location , * clusterModel .Properties .Fqdn )
511+ nsgParams , err := networkIsolatedSecurityGroup (location , * clusterModel .Properties .Fqdn )
484512 if err != nil {
485513 return err
486514 }
487515
488- nsg , err := createAirgapSecurityGroup (ctx , clusterModel , nsgParams , nil )
516+ nsg , err := createNetworkIsolatedSecurityGroup (ctx , clusterModel , nsgParams , nil )
489517 if err != nil {
490518 return err
491519 }
@@ -503,19 +531,14 @@ func addAirgapNetworkSettings(ctx context.Context, clusterModel *armcontainerser
503531 return err
504532 }
505533
506- err = addPrivateEndpointForACR (ctx , * clusterModel .Properties .NodeResourceGroup , privateACRName , vnet , location )
507- if err != nil {
508- return err
509- }
510-
511- toolkit .Logf (ctx , "updated cluster %s subnet with airgap settings" , * clusterModel .Name )
534+ toolkit .Logf (ctx , "updated cluster %s subnet with network isolated cluster settings" , * clusterModel .Name )
512535 return nil
513536}
514537
515- func airGapSecurityGroup (location , clusterFQDN string ) (armnetwork.SecurityGroup , error ) {
538+ func networkIsolatedSecurityGroup (location , clusterFQDN string ) (armnetwork.SecurityGroup , error ) {
516539 requiredRules , err := getRequiredSecurityRules (clusterFQDN )
517540 if err != nil {
518- return armnetwork.SecurityGroup {}, fmt .Errorf ("failed to get required security rules for airgap resource group: %w" , err )
541+ return armnetwork.SecurityGroup {}, fmt .Errorf ("failed to get required security rules for network isolated resource group: %w" , err )
519542 }
520543
521544 allowVnet := & armnetwork.SecurityRule {
@@ -550,7 +573,7 @@ func airGapSecurityGroup(location, clusterFQDN string) (armnetwork.SecurityGroup
550573
551574 return armnetwork.SecurityGroup {
552575 Location : & location ,
553- Name : & config .Config .AirgapNSGName ,
576+ Name : & config .Config .NetworkIsolatedNSGName ,
554577 Properties : & armnetwork.SecurityGroupPropertiesFormat {SecurityRules : rules },
555578 }, nil
556579}
@@ -559,7 +582,7 @@ func addPrivateEndpointForACR(ctx context.Context, nodeResourceGroup, privateACR
559582 toolkit .Logf (ctx , "Checking if private endpoint for private container registry is in rg %s" , nodeResourceGroup )
560583 var err error
561584 var privateEndpoint * armnetwork.PrivateEndpoint
562- privateEndpointName := "PE-for-ABE2ETests"
585+ privateEndpointName := fmt . Sprintf ( "PE-for-%s" , privateACRName )
563586 if privateEndpoint , err = createPrivateEndpoint (ctx , nodeResourceGroup , privateEndpointName , privateACRName , vnet , location ); err != nil {
564587 return err
565588 }
@@ -718,7 +741,7 @@ func deletePrivateAzureContainerRegistry(ctx context.Context, resourceGroup, pri
718741 return nil
719742}
720743
721- // if the ACR needs to be recreated so does the airgap k8s cluster
744+ // if the ACR needs to be recreated so does the network isolated k8s cluster
722745func shouldRecreateACR (ctx context.Context , resourceGroup , privateACRName string ) (error , bool ) {
723746 toolkit .Logf (ctx , "Checking if private Azure Container Registry cache rules are correct in rg %s" , resourceGroup )
724747
@@ -1010,8 +1033,8 @@ func getSecurityRule(name, destinationAddressPrefix string, priority int32) *arm
10101033 }
10111034}
10121035
1013- func createAirgapSecurityGroup (ctx context.Context , cluster * armcontainerservice.ManagedCluster , nsgParams armnetwork.SecurityGroup , options * armnetwork.SecurityGroupsClientBeginCreateOrUpdateOptions ) (* armnetwork.SecurityGroupsClientCreateOrUpdateResponse , error ) {
1014- poller , err := config .Azure .SecurityGroup .BeginCreateOrUpdate (ctx , * cluster .Properties .NodeResourceGroup , config .Config .AirgapNSGName , nsgParams , options )
1036+ func createNetworkIsolatedSecurityGroup (ctx context.Context , cluster * armcontainerservice.ManagedCluster , nsgParams armnetwork.SecurityGroup , options * armnetwork.SecurityGroupsClientBeginCreateOrUpdateOptions ) (* armnetwork.SecurityGroupsClientCreateOrUpdateResponse , error ) {
1037+ poller , err := config .Azure .SecurityGroup .BeginCreateOrUpdate (ctx , * cluster .Properties .NodeResourceGroup , config .Config .NetworkIsolatedNSGName , nsgParams , options )
10151038 if err != nil {
10161039 return nil , err
10171040 }
0 commit comments