@@ -10,35 +10,37 @@ import (
1010 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1111 "k8s.io/apimachinery/pkg/runtime"
1212
13+ v1 "github.com/openshift/api/config/v1"
14+ machinev1 "github.com/openshift/api/machine/v1"
1315 machineapi "github.com/openshift/api/machine/v1beta1"
1416 "github.com/openshift/installer/pkg/types"
1517 "github.com/openshift/installer/pkg/types/vsphere"
1618)
1719
1820// Machines returns a list of machines for a machinepool.
19- func Machines (clusterID string , config * types.InstallConfig , pool * types.MachinePool , osImage , role , userDataSecret string ) ([]machineapi.Machine , error ) {
21+ func Machines (clusterID string , config * types.InstallConfig , pool * types.MachinePool , osImage , role , userDataSecret string ) ([]machineapi.Machine , * machinev1. ControlPlaneMachineSet , error ) {
2022 if configPlatform := config .Platform .Name (); configPlatform != vsphere .Name {
21- return nil , fmt .Errorf ("non vsphere configuration: %q" , configPlatform )
23+ return nil , nil , fmt .Errorf ("non vsphere configuration: %q" , configPlatform )
2224 }
2325 if poolPlatform := pool .Platform .Name (); poolPlatform != vsphere .Name {
24- return nil , fmt .Errorf ("non-VSphere machine-pool: %q" , poolPlatform )
26+ return nil , nil , fmt .Errorf ("non-VSphere machine-pool: %q" , poolPlatform )
2527 }
2628
2729 var failureDomain vsphere.FailureDomain
2830 var machines []machineapi.Machine
2931 platform := config .Platform .VSphere
3032 mpool := pool .Platform .VSphere
31- replicas := int64 (1 )
33+ replicas := int32 (1 )
3234
3335 numOfZones := len (mpool .Zones )
3436
3537 zones , err := getDefinedZonesFromTopology (platform )
3638 if err != nil {
37- return machines , err
39+ return machines , nil , err
3840 }
3941
4042 if pool .Replicas != nil {
41- replicas = * pool .Replicas
43+ replicas = int32 ( * pool .Replicas )
4244 }
4345
4446 // Create hosts to populate from. Copying so we can remove without changing original
@@ -53,7 +55,11 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
5355 }
5456 }
5557
56- for idx := int64 (0 ); idx < replicas ; idx ++ {
58+ failureDomains := []machinev1.VSphereFailureDomain {}
59+
60+ vsphereMachineProvider := & machineapi.VSphereMachineProviderSpec {}
61+
62+ for idx := int32 (0 ); idx < replicas ; idx ++ {
5763 logrus .Debugf ("Creating %v machine %v" , role , idx )
5864 var host * vsphere.Host
5965 desiredZone := mpool .Zones [int (idx )% numOfZones ]
@@ -66,7 +72,7 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
6672 logrus .Debugf ("Desired zone: %v" , desiredZone )
6773
6874 if _ , exists := zones [desiredZone ]; ! exists {
69- return nil , errors .Errorf ("zone [%s] specified by machinepool is not defined" , desiredZone )
75+ return nil , nil , errors .Errorf ("zone [%s] specified by machinepool is not defined" , desiredZone )
7076 }
7177
7278 failureDomain = zones [desiredZone ]
@@ -77,20 +83,26 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
7783 "machine.openshift.io/cluster-api-machine-type" : role ,
7884 }
7985
86+ failureDomains = append (failureDomains , machinev1.VSphereFailureDomain {
87+ Name : failureDomain .Name ,
88+ })
89+
8090 osImageForZone := failureDomain .Topology .Template
8191 if failureDomain .Topology .Template == "" {
8292 osImageForZone = fmt .Sprintf ("%s-%s-%s" , osImage , failureDomain .Region , failureDomain .Zone )
8393 }
8494
8595 vcenter , err := getVCenterFromServerName (failureDomain .Server , platform )
8696 if err != nil {
87- return nil , errors .Wrap (err , "unable to find vCenter in failure domains" )
97+ return nil , nil , errors .Wrap (err , "unable to find vCenter in failure domains" )
8898 }
8999 provider , err := provider (clusterID , vcenter , failureDomain , mpool , osImageForZone , userDataSecret )
90100 if err != nil {
91- return nil , errors .Wrap (err , "failed to create provider" )
101+ return nil , nil , errors .Wrap (err , "failed to create provider" )
92102 }
93103
104+ vsphereMachineProvider = provider
105+
94106 // Apply static IP if configured
95107 applyNetworkConfig (host , provider )
96108
@@ -113,7 +125,61 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
113125 }
114126 machines = append (machines , machine )
115127 }
116- return machines , nil
128+
129+ // when multiple zones are defined, network and workspace are derived from the topology
130+ if len (failureDomains ) > 1 {
131+ vsphereMachineProvider .Network = machineapi.NetworkSpec {}
132+ vsphereMachineProvider .Workspace = & machineapi.Workspace {}
133+ vsphereMachineProvider .Template = ""
134+ }
135+
136+ controlPlaneMachineSet := & machinev1.ControlPlaneMachineSet {
137+ TypeMeta : metav1.TypeMeta {
138+ APIVersion : "machine.openshift.io/v1" ,
139+ Kind : "ControlPlaneMachineSet" ,
140+ },
141+ ObjectMeta : metav1.ObjectMeta {
142+ Namespace : "openshift-machine-api" ,
143+ Name : "cluster" ,
144+ Labels : map [string ]string {
145+ "machine.openshift.io/cluster-api-cluster" : clusterID ,
146+ },
147+ },
148+ Spec : machinev1.ControlPlaneMachineSetSpec {
149+ Replicas : & replicas ,
150+ State : machinev1 .ControlPlaneMachineSetStateActive ,
151+ Selector : metav1.LabelSelector {
152+ MatchLabels : map [string ]string {
153+ "machine.openshift.io/cluster-api-machine-role" : role ,
154+ "machine.openshift.io/cluster-api-machine-type" : role ,
155+ "machine.openshift.io/cluster-api-cluster" : clusterID ,
156+ },
157+ },
158+ Template : machinev1.ControlPlaneMachineSetTemplate {
159+ MachineType : machinev1 .OpenShiftMachineV1Beta1MachineType ,
160+ OpenShiftMachineV1Beta1Machine : & machinev1.OpenShiftMachineV1Beta1MachineTemplate {
161+ FailureDomains : machinev1.FailureDomains {
162+ Platform : v1 .VSpherePlatformType ,
163+ VSphere : failureDomains ,
164+ },
165+ ObjectMeta : machinev1.ControlPlaneMachineSetTemplateObjectMeta {
166+ Labels : map [string ]string {
167+ "machine.openshift.io/cluster-api-cluster" : clusterID ,
168+ "machine.openshift.io/cluster-api-machine-role" : role ,
169+ "machine.openshift.io/cluster-api-machine-type" : role ,
170+ },
171+ },
172+ Spec : machineapi.MachineSpec {
173+ ProviderSpec : machineapi.ProviderSpec {
174+ Value : & runtime.RawExtension {Object : vsphereMachineProvider },
175+ },
176+ },
177+ },
178+ },
179+ },
180+ }
181+
182+ return machines , controlPlaneMachineSet , nil
117183}
118184
119185// applyNetworkConfig this function will apply the static ip configuration to the networkDevice
0 commit comments