Skip to content

Commit ce6a0a1

Browse files
Merge pull request openshift#7119 from nutanix-cloud-native/enable-cpmso
[CORS-2666] Add ControlPlaneMachineSet for Nutanix
2 parents f7b3fef + 93b3197 commit ce6a0a1

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

pkg/asset/machines/master.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ func (m *Master) Generate(dependencies asset.Parents) error {
487487
pool.Platform.Nutanix = &mpool
488488
templateName := nutanixtypes.RHCOSImageName(clusterID.InfraID)
489489

490-
machines, err = nutanix.Machines(clusterID.InfraID, ic, &pool, templateName, "master", masterUserDataSecretName)
490+
machines, controlPlaneMachineSet, err = nutanix.Machines(clusterID.InfraID, ic, &pool, templateName, "master", masterUserDataSecretName)
491491
if err != nil {
492492
return errors.Wrap(err, "failed to create master machine objects")
493493
}

pkg/asset/machines/nutanix/machines.go

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package nutanix
44
import (
55
"fmt"
66

7-
"github.com/pkg/errors"
87
corev1 "k8s.io/api/core/v1"
98
"k8s.io/apimachinery/pkg/api/resource"
109
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -17,12 +16,12 @@ import (
1716
)
1817

1918
// Machines returns a list of machines for a machinepool.
20-
func Machines(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string) ([]machineapi.Machine, error) {
19+
func Machines(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string) ([]machineapi.Machine, *machinev1.ControlPlaneMachineSet, error) {
2120
if configPlatform := config.Platform.Name(); configPlatform != nutanix.Name {
22-
return nil, fmt.Errorf("non nutanix configuration: %q", configPlatform)
21+
return nil, nil, fmt.Errorf("non nutanix configuration: %q", configPlatform)
2322
}
2423
if poolPlatform := pool.Platform.Name(); poolPlatform != nutanix.Name {
25-
return nil, fmt.Errorf("non-nutanix machine-pool: %q", poolPlatform)
24+
return nil, nil, fmt.Errorf("non-nutanix machine-pool: %q", poolPlatform)
2625
}
2726
platform := config.Platform.Nutanix
2827
mpool := pool.Platform.Nutanix
@@ -32,11 +31,12 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
3231
total = *pool.Replicas
3332
}
3433
var machines []machineapi.Machine
34+
machineSetProvider := &machinev1.NutanixMachineProviderConfig{}
3535
for idx := int64(0); idx < total; idx++ {
3636
provider, err := provider(clusterID, platform, mpool, osImage, userDataSecret)
3737

3838
if err != nil {
39-
return nil, errors.Wrap(err, "failed to create provider")
39+
return nil, nil, fmt.Errorf("failed to create provider: %w", err)
4040
}
4141
machine := machineapi.Machine{
4242
TypeMeta: metav1.TypeMeta{
@@ -59,9 +59,54 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
5959
// we don't need to set Versions, because we control those via operators.
6060
},
6161
}
62+
*machineSetProvider = *provider
6263
machines = append(machines, machine)
6364
}
64-
return machines, nil
65+
66+
replicas := int32(total)
67+
controlPlaneMachineSet := &machinev1.ControlPlaneMachineSet{
68+
TypeMeta: metav1.TypeMeta{
69+
APIVersion: "machine.openshift.io/v1",
70+
Kind: "ControlPlaneMachineSet",
71+
},
72+
ObjectMeta: metav1.ObjectMeta{
73+
Namespace: "openshift-machine-api",
74+
Name: "cluster",
75+
Labels: map[string]string{
76+
"machine.openshift.io/cluster-api-cluster": clusterID,
77+
},
78+
},
79+
Spec: machinev1.ControlPlaneMachineSetSpec{
80+
Replicas: &replicas,
81+
State: machinev1.ControlPlaneMachineSetStateActive,
82+
Selector: metav1.LabelSelector{
83+
MatchLabels: map[string]string{
84+
"machine.openshift.io/cluster-api-machine-role": role,
85+
"machine.openshift.io/cluster-api-machine-type": role,
86+
"machine.openshift.io/cluster-api-cluster": clusterID,
87+
},
88+
},
89+
Template: machinev1.ControlPlaneMachineSetTemplate{
90+
MachineType: machinev1.OpenShiftMachineV1Beta1MachineType,
91+
OpenShiftMachineV1Beta1Machine: &machinev1.OpenShiftMachineV1Beta1MachineTemplate{
92+
ObjectMeta: machinev1.ControlPlaneMachineSetTemplateObjectMeta{
93+
Labels: map[string]string{
94+
"machine.openshift.io/cluster-api-cluster": clusterID,
95+
"machine.openshift.io/cluster-api-machine-role": role,
96+
"machine.openshift.io/cluster-api-machine-type": role,
97+
},
98+
},
99+
Spec: machineapi.MachineSpec{
100+
ProviderSpec: machineapi.ProviderSpec{
101+
Value: &runtime.RawExtension{Object: machineSetProvider},
102+
},
103+
},
104+
},
105+
},
106+
},
107+
}
108+
109+
return machines, controlPlaneMachineSet, nil
65110
}
66111

67112
func provider(clusterID string, platform *nutanix.Platform, mpool *nutanix.MachinePool, osImage string, userDataSecret string) (*machinev1.NutanixMachineProviderConfig, error) {

0 commit comments

Comments
 (0)