@@ -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" 
7778	// errAssertingCAPIAWSMachineTemplate is returned when we encounter an issue asserting a client.Object into a AWSMachineTemplate. 
7879	errAssertingCAPIAWSMachineTemplate  =  errors .New ("error asserting the CAPI AWSMachineTemplate object" )
7980
81+ 	// errAssertingCAPIMetal3MachineTemplate is returned when we encounter an issue asserting a client.Object into a Metal3MachineTemplate. 
82+ 	errAssertingCAPIMetal3MachineTemplate  =  errors .New ("error asserting the CAPI Metal3MachineTemplate object" )
83+ 
8084	// errAssertingCAPIPowerVSMachineTemplate is returned when we encounter an issue asserting a client.Object into a IBMPowerVSMachineTemplate. 
8185	errAssertingCAPIIBMPowerVSMachineTemplate  =  errors .New ("error asserting the CAPI IBMPowerVSMachineTemplate object" )
8286
@@ -667,6 +671,20 @@ func (r *MachineSetSyncReconciler) convertCAPIToMAPIMachineSet(capiMachineSet *c
667671		return  capi2mapi .FromMachineSetAndAWSMachineTemplateAndAWSCluster ( //nolint: wrapcheck 
668672			capiMachineSet , machineTemplate , cluster ,
669673		).ToMachineSet ()
674+ 	case  configv1 .BareMetalPlatformType :
675+ 		machineTemplate , ok  :=  infraMachineTemplate .(* metal3v1.Metal3MachineTemplate )
676+ 		if  ! ok  {
677+ 			return  nil , nil , fmt .Errorf ("%w, expected Metal3MachineTemplate, got %T" , errUnexpectedInfraMachineTemplateType , infraMachineTemplate )
678+ 		}
679+ 
680+ 		cluster , ok  :=  infraCluster .(* metal3v1.Metal3Cluster )
681+ 		if  ! ok  {
682+ 			return  nil , nil , fmt .Errorf ("%w, expected Metal3Cluster, got %T" , errUnexpectedInfraClusterType , infraCluster )
683+ 		}
684+ 
685+ 		return  capi2mapi .FromMachineSetAndMetal3MachineTemplateAndMetal3Cluster ( //nolint: wrapcheck 
686+ 			capiMachineSet , machineTemplate , cluster ,
687+ 		).ToMachineSet ()
670688	case  configv1 .OpenStackPlatformType :
671689		machineTemplate , ok  :=  infraMachineTemplate .(* openstackv1.OpenStackMachineTemplate )
672690		if  ! ok  {
@@ -705,6 +723,8 @@ func (r *MachineSetSyncReconciler) convertMAPIToCAPIMachineSet(mapiMachineSet *m
705723	switch  r .Platform  {
706724	case  configv1 .AWSPlatformType :
707725		return  mapi2capi .FromAWSMachineSetAndInfra (mapiMachineSet , r .Infra ).ToMachineSetAndMachineTemplate () //nolint:wrapcheck 
726+ 	case  configv1 .BareMetalPlatformType :
727+ 		return  mapi2capi .FromMetal3MachineSetAndInfra (mapiMachineSet , r .Infra ).ToMachineSetAndMachineTemplate () //nolint:wrapcheck 
708728	case  configv1 .OpenStackPlatformType :
709729		return  mapi2capi .FromOpenStackMachineSetAndInfra (mapiMachineSet , r .Infra ).ToMachineSetAndMachineTemplate () //nolint:wrapcheck 
710730	case  configv1 .PowerVSPlatformType :
@@ -1307,6 +1327,8 @@ func initInfraMachineTemplateListAndInfraClusterListFromProvider(platform config
13071327	switch  platform  {
13081328	case  configv1 .AWSPlatformType :
13091329		return  & awsv1.AWSMachineTemplateList {}, & awsv1.AWSClusterList {}, nil 
1330+ 	case  configv1 .BareMetalPlatformType :
1331+ 		return  & metal3v1.Metal3MachineTemplateList {}, & metal3v1.Metal3ClusterList {}, nil 
13101332	case  configv1 .OpenStackPlatformType :
13111333		return  & openstackv1.OpenStackMachineTemplateList {}, & openstackv1.OpenStackClusterList {}, nil 
13121334	case  configv1 .PowerVSPlatformType :
@@ -1318,7 +1340,7 @@ func initInfraMachineTemplateListAndInfraClusterListFromProvider(platform config
13181340
13191341// compareCAPIInfraMachineTemplates compares CAPI infra machine templates a and b, and returns a list of differences, or none if there are none. 
13201342// 
1321- //nolint:funlen 
1343+ //nolint:funlen,gocognit,cyclop  
13221344func  compareCAPIInfraMachineTemplates (platform  configv1.PlatformType , infraMachineTemplate1 , infraMachineTemplate2  client.Object ) (map [string ]any , error ) {
13231345	switch  platform  {
13241346	case  configv1 .AWSPlatformType :
@@ -1344,6 +1366,30 @@ func compareCAPIInfraMachineTemplates(platform configv1.PlatformType, infraMachi
13441366
13451367		// TODO: Evaluate if we want to add status comparison if needed in the future (e.g. for scale from zero capacity). 
13461368
1369+ 		return  diff , nil 
1370+ 	case  configv1 .BareMetalPlatformType :
1371+ 		typedInfraMachineTemplate1 , ok  :=  infraMachineTemplate1 .(* metal3v1.Metal3MachineTemplate )
1372+ 		if  ! ok  {
1373+ 			return  nil , errAssertingCAPIMetal3MachineTemplate 
1374+ 		}
1375+ 
1376+ 		typedinfraMachineTemplate2 , ok  :=  infraMachineTemplate2 .(* metal3v1.Metal3MachineTemplate )
1377+ 		if  ! ok  {
1378+ 			return  nil , errAssertingCAPIMetal3MachineTemplate 
1379+ 		}
1380+ 
1381+ 		diff  :=  make (map [string ]any )
1382+ 
1383+ 		if  diffSpec  :=  deep .Equal (typedInfraMachineTemplate1 .Spec , typedinfraMachineTemplate2 .Spec ); len (diffSpec ) >  0  {
1384+ 			diff [".spec" ] =  diffSpec 
1385+ 		}
1386+ 
1387+ 		if  diffObjectMeta  :=  util .ObjectMetaEqual (typedInfraMachineTemplate1 .ObjectMeta , typedinfraMachineTemplate2 .ObjectMeta ); len (diffObjectMeta ) >  0  {
1388+ 			diff [".metadata" ] =  diffObjectMeta 
1389+ 		}
1390+ 
1391+ 		// TODO: Evaluate if we want to add status comparison if needed in the future (e.g. for scale from zero capacity). 
1392+ 
13471393		return  diff , nil 
13481394	case  configv1 .OpenStackPlatformType :
13491395		typedInfraMachineTemplate1 , ok  :=  infraMachineTemplate1 .(* openstackv1.OpenStackMachineTemplate )
0 commit comments