@@ -23,24 +23,37 @@ const (
2323 genV2Suffix string = "-gen2"
2424)
2525
26+ // MachineInput defines the inputs needed to generate a machine asset.
27+ type MachineInput struct {
28+ Subnet string
29+ Role string
30+ UserDataSecret string
31+ HyperVGen string
32+ UseImageGallery bool
33+ Private bool
34+ UserTags map [string ]string
35+ Platform * azure.Platform
36+ Pool * types.MachinePool
37+ }
38+
2639// GenerateMachines returns manifests and runtime objects to provision the control plane (including bootstrap, if applicable) nodes using CAPI.
27- func GenerateMachines (platform * azure. Platform , pool * types. MachinePool , userDataSecret string , clusterID string , role string , capabilities map [ string ] string , useImageGallery bool , userTags map [ string ] string , hyperVGen string , subnet string , resourceGroup string , subscriptionID string ) ([]* asset.RuntimeFile , error ) {
28- if poolPlatform := pool .Platform .Name (); poolPlatform != azure .Name {
40+ func GenerateMachines (clusterID , resourceGroup , subscriptionID string , in * MachineInput ) ([]* asset.RuntimeFile , error ) {
41+ if poolPlatform := in . Pool .Platform .Name (); poolPlatform != azure .Name {
2942 return nil , fmt .Errorf ("non-Azure machine-pool: %q" , poolPlatform )
3043 }
31- mpool := pool .Platform .Azure
44+ mpool := in . Pool .Platform .Azure
3245
3346 total := int64 (1 )
34- if pool .Replicas != nil {
35- total = * pool .Replicas
47+ if in . Pool .Replicas != nil {
48+ total = * in . Pool .Replicas
3649 }
3750
3851 if len (mpool .Zones ) == 0 {
3952 // if no azs are given we set to []string{""} for convenience over later operations.
4053 // It means no-zoned for the machine API
4154 mpool .Zones = []string {"" }
4255 }
43- tags , err := CapzTagsFromUserTags (clusterID , userTags )
56+ tags , err := CapzTagsFromUserTags (clusterID , in . UserTags )
4457 if err != nil {
4558 return nil , fmt .Errorf ("failed to create machineapi.TagSpecifications from UserTags: %w" , err )
4659 }
@@ -64,17 +77,17 @@ func GenerateMachines(platform *azure.Platform, pool *types.MachinePool, userDat
6477 ThirdPartyImage : osImage .Plan != azure .ImageNoPurchasePlan ,
6578 },
6679 }
67- case useImageGallery :
80+ case in . UseImageGallery :
6881 // image gallery names cannot have dashes
6982 id := clusterID
70- if hyperVGen == "V2" {
83+ if in . HyperVGen == "V2" {
7184 id += genV2Suffix
7285 }
7386 imageID := fmt .Sprintf ("/resourceGroups/%s/providers/Microsoft.Compute/galleries/gallery_%s/images/%s/versions/latest" , resourceGroup , galleryName , id )
7487 image = & capz.Image {ID : & imageID }
7588 default :
7689 imageID := fmt .Sprintf ("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/galleries/gallery_%s/images/%s" , subscriptionID , resourceGroup , galleryName , clusterID )
77- if hyperVGen == "V2" && platform .CloudName != azure .StackCloud {
90+ if in . HyperVGen == "V2" && in . Platform .CloudName != azure .StackCloud {
7891 imageID += genV2Suffix
7992 }
8093 image = & capz.Image {ID : & imageID }
@@ -92,7 +105,7 @@ func GenerateMachines(platform *azure.Platform, pool *types.MachinePool, userDat
92105 additionalCapabilities := & capz.AdditionalCapabilities {
93106 UltraSSDEnabled : & ultrassd ,
94107 }
95- if pool .Platform .Azure .DiskEncryptionSet != nil {
108+ if in . Pool .Platform .Azure .DiskEncryptionSet != nil {
96109 osDisk .ManagedDisk .DiskEncryptionSet = & capz.DiskEncryptionSetParameters {
97110 ID : mpool .OSDisk .DiskEncryptionSet .ToID (),
98111 }
@@ -120,7 +133,7 @@ func GenerateMachines(platform *azure.Platform, pool *types.MachinePool, userDat
120133 zone := mpool .Zones [int (idx )% len (mpool .Zones )]
121134 azureMachine := & capz.AzureMachine {
122135 ObjectMeta : metav1.ObjectMeta {
123- Name : fmt .Sprintf ("%s-%s-%d" , clusterID , pool .Name , idx ),
136+ Name : fmt .Sprintf ("%s-%s-%d" , clusterID , in . Pool .Name , idx ),
124137 Labels : map [string ]string {
125138 "cluster.x-k8s.io/control-plane" : "" ,
126139 "cluster.x-k8s.io/cluster-name" : clusterID ,
@@ -139,7 +152,7 @@ func GenerateMachines(platform *azure.Platform, pool *types.MachinePool, userDat
139152 SecurityProfile : securityProfile ,
140153 NetworkInterfaces : []capz.NetworkInterface {
141154 {
142- SubnetName : subnet ,
155+ SubnetName : in . Subnet ,
143156 AcceleratedNetworking : ptr .To (mpool .VMNetworkingType == string (azure .VMnetworkingTypeAccelerated ) || mpool .VMNetworkingType == string (azure .AcceleratedNetworkingEnabled )),
144157 },
145158 },
@@ -167,7 +180,7 @@ func GenerateMachines(platform *azure.Platform, pool *types.MachinePool, userDat
167180 Spec : capi.MachineSpec {
168181 ClusterName : clusterID ,
169182 Bootstrap : capi.Bootstrap {
170- DataSecretName : ptr .To (fmt .Sprintf ("%s-%s" , clusterID , role )),
183+ DataSecretName : ptr .To (fmt .Sprintf ("%s-%s" , clusterID , in . Role )),
171184 },
172185 InfrastructureRef : v1.ObjectReference {
173186 APIVersion : capz .GroupVersion .String (),
@@ -200,7 +213,7 @@ func GenerateMachines(platform *azure.Platform, pool *types.MachinePool, userDat
200213 OSDisk : osDisk ,
201214 AdditionalTags : tags ,
202215 DisableExtensionOperations : ptr .To (true ),
203- AllocatePublicIP : true ,
216+ AllocatePublicIP : ! in . Private ,
204217 AdditionalCapabilities : additionalCapabilities ,
205218 SecurityProfile : securityProfile ,
206219 Identity : capz .VMIdentityUserAssigned ,
0 commit comments