Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/asset/machines/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
57 changes: 51 additions & 6 deletions pkg/asset/machines/nutanix/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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{
Expand All @@ -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) {
Expand Down