@@ -40,6 +40,7 @@ import (
4040 utilerrors "k8s.io/apimachinery/pkg/util/errors"
4141
4242 "github.com/go-test/deep"
43+ metal3v1 "github.com/metal3-io/cluster-api-provider-metal3/api/v1beta1"
4344 machinev1applyconfigs "github.com/openshift/client-go/machine/applyconfigurations/machine/v1beta1"
4445 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4546 "k8s.io/apimachinery/pkg/fields"
7576 // errAssertingCAPIAWSMachineTemplate is returned when we encounter an issue asserting a client.Object into a AWSMachineTemplate.
7677 errAssertingCAPIAWSMachineTemplate = errors .New ("error asserting the CAPI AWSMachineTemplate object" )
7778
79+ // errAssertingCAPIMetal3MachineTemplate is returned when we encounter an issue asserting a client.Object into a Metal3MachineTemplate.
80+ errAssertingCAPIMetal3MachineTemplate = errors .New ("error asserting the CAPI Metal3MachineTemplate object" )
81+
7882 // errAssertingCAPIPowerVSMachineTemplate is returned when we encounter an issue asserting a client.Object into a IBMPowerVSMachineTemplate.
7983 errAssertingCAPIIBMPowerVSMachineTemplate = errors .New ("error asserting the CAPI IBMPowerVSMachineTemplate object" )
8084
@@ -665,6 +669,20 @@ func (r *MachineSetSyncReconciler) convertCAPIToMAPIMachineSet(capiMachineSet *c
665669 return capi2mapi .FromMachineSetAndAWSMachineTemplateAndAWSCluster ( //nolint: wrapcheck
666670 capiMachineSet , machineTemplate , cluster ,
667671 ).ToMachineSet ()
672+ case configv1 .BareMetalPlatformType :
673+ machineTemplate , ok := infraMachineTemplate .(* metal3v1.Metal3MachineTemplate )
674+ if ! ok {
675+ return nil , nil , fmt .Errorf ("%w, expected Metal3MachineTemplate, got %T" , errUnexpectedInfraMachineTemplateType , infraMachineTemplate )
676+ }
677+
678+ cluster , ok := infraCluster .(* metal3v1.Metal3Cluster )
679+ if ! ok {
680+ return nil , nil , fmt .Errorf ("%w, expected Metal3Cluster, got %T" , errUnexpectedInfraClusterType , infraCluster )
681+ }
682+
683+ return capi2mapi .FromMachineSetAndMetal3MachineTemplateAndMetal3Cluster ( //nolint: wrapcheck
684+ capiMachineSet , machineTemplate , cluster ,
685+ ).ToMachineSet ()
668686 case configv1 .OpenStackPlatformType :
669687 machineTemplate , ok := infraMachineTemplate .(* openstackv1.OpenStackMachineTemplate )
670688 if ! ok {
@@ -703,6 +721,8 @@ func (r *MachineSetSyncReconciler) convertMAPIToCAPIMachineSet(mapiMachineSet *m
703721 switch r .Platform {
704722 case configv1 .AWSPlatformType :
705723 return mapi2capi .FromAWSMachineSetAndInfra (mapiMachineSet , r .Infra ).ToMachineSetAndMachineTemplate () //nolint:wrapcheck
724+ case configv1 .BareMetalPlatformType :
725+ return mapi2capi .FromMetal3MachineSetAndInfra (mapiMachineSet , r .Infra ).ToMachineSetAndMachineTemplate () //nolint:wrapcheck
706726 case configv1 .OpenStackPlatformType :
707727 return mapi2capi .FromOpenStackMachineSetAndInfra (mapiMachineSet , r .Infra ).ToMachineSetAndMachineTemplate () //nolint:wrapcheck
708728 case configv1 .PowerVSPlatformType :
@@ -1302,6 +1322,8 @@ func initInfraMachineTemplateListAndInfraClusterListFromProvider(platform config
13021322 switch platform {
13031323 case configv1 .AWSPlatformType :
13041324 return & awsv1.AWSMachineTemplateList {}, & awsv1.AWSClusterList {}, nil
1325+ case configv1 .BareMetalPlatformType :
1326+ return & metal3v1.Metal3MachineTemplateList {}, & metal3v1.Metal3ClusterList {}, nil
13051327 case configv1 .OpenStackPlatformType :
13061328 return & openstackv1.OpenStackMachineTemplateList {}, & openstackv1.OpenStackClusterList {}, nil
13071329 case configv1 .PowerVSPlatformType :
@@ -1313,7 +1335,7 @@ func initInfraMachineTemplateListAndInfraClusterListFromProvider(platform config
13131335
13141336// compareCAPIInfraMachineTemplates compares CAPI infra machine templates a and b, and returns a list of differences, or none if there are none.
13151337//
1316- //nolint:funlen
1338+ //nolint:funlen,gocognit,cyclop
13171339func compareCAPIInfraMachineTemplates (platform configv1.PlatformType , infraMachineTemplate1 , infraMachineTemplate2 client.Object ) (map [string ]any , error ) {
13181340 switch platform {
13191341 case configv1 .AWSPlatformType :
@@ -1339,6 +1361,30 @@ func compareCAPIInfraMachineTemplates(platform configv1.PlatformType, infraMachi
13391361
13401362 // TODO: Evaluate if we want to add status comparison if needed in the future (e.g. for scale from zero capacity).
13411363
1364+ return diff , nil
1365+ case configv1 .BareMetalPlatformType :
1366+ typedInfraMachineTemplate1 , ok := infraMachineTemplate1 .(* metal3v1.Metal3MachineTemplate )
1367+ if ! ok {
1368+ return nil , errAssertingCAPIMetal3MachineTemplate
1369+ }
1370+
1371+ typedinfraMachineTemplate2 , ok := infraMachineTemplate2 .(* metal3v1.Metal3MachineTemplate )
1372+ if ! ok {
1373+ return nil , errAssertingCAPIMetal3MachineTemplate
1374+ }
1375+
1376+ diff := make (map [string ]any )
1377+
1378+ if diffSpec := deep .Equal (typedInfraMachineTemplate1 .Spec , typedinfraMachineTemplate2 .Spec ); len (diffSpec ) > 0 {
1379+ diff [".spec" ] = diffSpec
1380+ }
1381+
1382+ if diffObjectMeta := util .ObjectMetaEqual (typedInfraMachineTemplate1 .ObjectMeta , typedinfraMachineTemplate2 .ObjectMeta ); len (diffObjectMeta ) > 0 {
1383+ diff [".metadata" ] = diffObjectMeta
1384+ }
1385+
1386+ // TODO: Evaluate if we want to add status comparison if needed in the future (e.g. for scale from zero capacity).
1387+
13421388 return diff , nil
13431389 case configv1 .OpenStackPlatformType :
13441390 typedInfraMachineTemplate1 , ok := infraMachineTemplate1 .(* openstackv1.OpenStackMachineTemplate )
0 commit comments