@@ -8,12 +8,8 @@ import (
88
99 "github.com/pkg/errors"
1010 "github.com/sirupsen/logrus"
11- v1 "k8s.io/api/core/v1"
12- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1311 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1412 "k8s.io/utils/ptr"
15- capa "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
16- capi "sigs.k8s.io/cluster-api/api/v1beta1"
1713 "sigs.k8s.io/controller-runtime/pkg/client"
1814 "sigs.k8s.io/yaml"
1915
@@ -31,6 +27,7 @@ import (
3127 "github.com/openshift/installer/pkg/asset/rhcos"
3228 "github.com/openshift/installer/pkg/clusterapi"
3329 rhcosutils "github.com/openshift/installer/pkg/rhcos"
30+ "github.com/openshift/installer/pkg/types"
3431 awstypes "github.com/openshift/installer/pkg/types/aws"
3532 awsdefaults "github.com/openshift/installer/pkg/types/aws/defaults"
3633 azuretypes "github.com/openshift/installer/pkg/types/azure"
@@ -145,89 +142,39 @@ func (c *ClusterAPI) Generate(dependencies asset.Parents) error {
145142 }
146143 }
147144
145+ tags , err := aws .CapaTagsFromUserTags (clusterID .InfraID , installConfig .Config .Platform .AWS .UserTags )
146+ if err != nil {
147+ return fmt .Errorf ("failed to create CAPA tags from UserTags: %w" , err )
148+ }
149+
148150 pool .Platform .AWS = & mpool
149- awsMachines , err := aws .GenerateMachines (
150- clusterID .InfraID ,
151- installConfig .Config .Platform .AWS .Region ,
152- subnets ,
153- & pool ,
154- "master" ,
155- installConfig .Config .Platform .AWS .UserTags ,
156- )
151+ awsMachines , err := aws .GenerateMachines (clusterID .InfraID , & aws.MachineInput {
152+ Role : "master" ,
153+ Pool : & pool ,
154+ Subnets : subnets ,
155+ Tags : tags ,
156+ PublicIP : false ,
157+ })
157158 if err != nil {
158159 return errors .Wrap (err , "failed to create master machine objects" )
159160 }
160161 c .FileList = append (c .FileList , awsMachines ... )
161162
162- // TODO(vincepri): The following code is almost duplicated from aws.AWSMachines.
163- // Refactor and generalize around a bootstrap pool, with a single machine and
164- // a custom openshift label to determine the bootstrap machine role, so we can
165- // delete the machine when the stage is complete.
166- bootstrapAWSMachine := & capa.AWSMachine {
167- ObjectMeta : metav1.ObjectMeta {
168- Name : capiutils .GenerateBoostrapMachineName (clusterID .InfraID ),
169- Labels : map [string ]string {
170- "cluster.x-k8s.io/control-plane" : "" ,
171- "install.openshift.io/bootstrap" : "" ,
172- },
173- },
174- Spec : capa.AWSMachineSpec {
175- Ignition : & capa.Ignition {Version : "3.2" },
176- UncompressedUserData : ptr .To (true ),
177- InstanceType : mpool .InstanceType ,
178- AMI : capa.AMIReference {ID : ptr .To (mpool .AMIID )},
179- SSHKeyName : ptr .To ("" ),
180- IAMInstanceProfile : fmt .Sprintf ("%s-master-profile" , clusterID .InfraID ),
181- PublicIP : ptr .To (true ),
182- RootVolume : & capa.Volume {
183- Size : int64 (mpool .EC2RootVolume .Size ),
184- Type : capa .VolumeType (mpool .EC2RootVolume .Type ),
185- IOPS : int64 (mpool .EC2RootVolume .IOPS ),
186- Encrypted : ptr .To (true ),
187- EncryptionKey : mpool .KMSKeyARN ,
188- },
189- },
190- }
191- bootstrapAWSMachine .SetGroupVersionKind (capa .GroupVersion .WithKind ("AWSMachine" ))
192-
193- // Handle additional security groups.
194- for _ , sg := range mpool .AdditionalSecurityGroupIDs {
195- bootstrapAWSMachine .Spec .AdditionalSecurityGroups = append (
196- bootstrapAWSMachine .Spec .AdditionalSecurityGroups ,
197- capa.AWSResourceReference {ID : ptr .To (sg )},
198- )
199- }
200-
201- c .FileList = append (c .FileList , & asset.RuntimeFile {
202- File : asset.File {Filename : fmt .Sprintf ("10_inframachine_%s.yaml" , bootstrapAWSMachine .Name )},
203- Object : bootstrapAWSMachine ,
163+ pool := * ic .ControlPlane
164+ pool .Name = "bootstrap"
165+ pool .Replicas = ptr.To [int64 ](1 )
166+ pool .Platform .AWS = & mpool
167+ bootstrapAWSMachine , err := aws .GenerateMachines (clusterID .InfraID , & aws.MachineInput {
168+ Role : "bootstrap" ,
169+ Subnets : nil , // let CAPA pick one
170+ Pool : & pool ,
171+ Tags : tags ,
172+ PublicIP : installConfig .Config .Publish == types .ExternalPublishingStrategy ,
204173 })
205-
206- bootstrapMachine := & capi.Machine {
207- ObjectMeta : metav1.ObjectMeta {
208- Name : bootstrapAWSMachine .Name ,
209- Labels : map [string ]string {
210- "cluster.x-k8s.io/control-plane" : "" ,
211- },
212- },
213- Spec : capi.MachineSpec {
214- ClusterName : clusterID .InfraID ,
215- Bootstrap : capi.Bootstrap {
216- DataSecretName : ptr .To (fmt .Sprintf ("%s-%s" , clusterID .InfraID , "bootstrap" )),
217- },
218- InfrastructureRef : v1.ObjectReference {
219- APIVersion : capa .GroupVersion .String (),
220- Kind : "AWSMachine" ,
221- Name : bootstrapAWSMachine .Name ,
222- },
223- },
174+ if err != nil {
175+ return fmt .Errorf ("failed to create bootstrap machine object: %w" , err )
224176 }
225- bootstrapMachine .SetGroupVersionKind (capi .GroupVersion .WithKind ("Machine" ))
226-
227- c .FileList = append (c .FileList , & asset.RuntimeFile {
228- File : asset.File {Filename : fmt .Sprintf ("10_machine_%s.yaml" , bootstrapMachine .Name )},
229- Object : bootstrapMachine ,
230- })
177+ c .FileList = append (c .FileList , bootstrapAWSMachine ... )
231178 case azuretypes .Name :
232179 mpool := defaultAzureMachinePoolPlatform ()
233180 mpool .InstanceType = azuredefaults .ControlPlaneInstanceType (
0 commit comments