diff --git a/pkg/asset/machines/master.go b/pkg/asset/machines/master.go index f195421f51..68c4c66796 100644 --- a/pkg/asset/machines/master.go +++ b/pkg/asset/machines/master.go @@ -487,7 +487,7 @@ func (m *Master) Generate(dependencies asset.Parents) error { pool.Platform.Nutanix = &mpool templateName := nutanixtypes.RHCOSImageName(clusterID.InfraID) - machines, err = nutanix.Machines(clusterID.InfraID, ic, &pool, templateName, "master", masterUserDataSecretName) + machines, controlPlaneMachineSet, err = nutanix.Machines(clusterID.InfraID, ic, &pool, templateName, "master", masterUserDataSecretName) if err != nil { return errors.Wrap(err, "failed to create master machine objects") } diff --git a/pkg/asset/machines/nutanix/machines.go b/pkg/asset/machines/nutanix/machines.go index 7313ac4af6..3ca544c5ab 100644 --- a/pkg/asset/machines/nutanix/machines.go +++ b/pkg/asset/machines/nutanix/machines.go @@ -4,7 +4,6 @@ package nutanix import ( "fmt" - "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -17,12 +16,12 @@ import ( ) // Machines returns a list of machines for a machinepool. -func Machines(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string) ([]machineapi.Machine, error) { +func Machines(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string) ([]machineapi.Machine, *machinev1.ControlPlaneMachineSet, error) { if configPlatform := config.Platform.Name(); configPlatform != nutanix.Name { - return nil, fmt.Errorf("non nutanix configuration: %q", configPlatform) + return nil, nil, fmt.Errorf("non nutanix configuration: %q", configPlatform) } if poolPlatform := pool.Platform.Name(); poolPlatform != nutanix.Name { - return nil, fmt.Errorf("non-nutanix machine-pool: %q", poolPlatform) + return nil, nil, fmt.Errorf("non-nutanix machine-pool: %q", poolPlatform) } platform := config.Platform.Nutanix mpool := pool.Platform.Nutanix @@ -32,11 +31,12 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine total = *pool.Replicas } var machines []machineapi.Machine + machineSetProvider := &machinev1.NutanixMachineProviderConfig{} for idx := int64(0); idx < total; idx++ { provider, err := provider(clusterID, platform, mpool, osImage, userDataSecret) if err != nil { - return nil, errors.Wrap(err, "failed to create provider") + return nil, nil, fmt.Errorf("failed to create provider: %w", err) } machine := machineapi.Machine{ TypeMeta: metav1.TypeMeta{ @@ -59,9 +59,54 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine // we don't need to set Versions, because we control those via operators. }, } + *machineSetProvider = *provider machines = append(machines, machine) } - return machines, nil + + replicas := int32(total) + controlPlaneMachineSet := &machinev1.ControlPlaneMachineSet{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "machine.openshift.io/v1", + Kind: "ControlPlaneMachineSet", + }, + ObjectMeta: metav1.ObjectMeta{ + Namespace: "openshift-machine-api", + Name: "cluster", + Labels: map[string]string{ + "machine.openshift.io/cluster-api-cluster": clusterID, + }, + }, + Spec: machinev1.ControlPlaneMachineSetSpec{ + Replicas: &replicas, + State: machinev1.ControlPlaneMachineSetStateActive, + Selector: metav1.LabelSelector{ + MatchLabels: map[string]string{ + "machine.openshift.io/cluster-api-machine-role": role, + "machine.openshift.io/cluster-api-machine-type": role, + "machine.openshift.io/cluster-api-cluster": clusterID, + }, + }, + Template: machinev1.ControlPlaneMachineSetTemplate{ + MachineType: machinev1.OpenShiftMachineV1Beta1MachineType, + OpenShiftMachineV1Beta1Machine: &machinev1.OpenShiftMachineV1Beta1MachineTemplate{ + ObjectMeta: machinev1.ControlPlaneMachineSetTemplateObjectMeta{ + Labels: map[string]string{ + "machine.openshift.io/cluster-api-cluster": clusterID, + "machine.openshift.io/cluster-api-machine-role": role, + "machine.openshift.io/cluster-api-machine-type": role, + }, + }, + Spec: machineapi.MachineSpec{ + ProviderSpec: machineapi.ProviderSpec{ + Value: &runtime.RawExtension{Object: machineSetProvider}, + }, + }, + }, + }, + }, + } + + return machines, controlPlaneMachineSet, nil } func provider(clusterID string, platform *nutanix.Platform, mpool *nutanix.MachinePool, osImage string, userDataSecret string) (*machinev1.NutanixMachineProviderConfig, error) {