@@ -10,35 +10,37 @@ import (
10
10
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11
11
"k8s.io/apimachinery/pkg/runtime"
12
12
13
+ v1 "github.com/openshift/api/config/v1"
14
+ machinev1 "github.com/openshift/api/machine/v1"
13
15
machineapi "github.com/openshift/api/machine/v1beta1"
14
16
"github.com/openshift/installer/pkg/types"
15
17
"github.com/openshift/installer/pkg/types/vsphere"
16
18
)
17
19
18
20
// 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 ) {
20
22
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 )
22
24
}
23
25
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 )
25
27
}
26
28
27
29
var failureDomain vsphere.FailureDomain
28
30
var machines []machineapi.Machine
29
31
platform := config .Platform .VSphere
30
32
mpool := pool .Platform .VSphere
31
- replicas := int64 (1 )
33
+ replicas := int32 (1 )
32
34
33
35
numOfZones := len (mpool .Zones )
34
36
35
37
zones , err := getDefinedZonesFromTopology (platform )
36
38
if err != nil {
37
- return machines , err
39
+ return machines , nil , err
38
40
}
39
41
40
42
if pool .Replicas != nil {
41
- replicas = * pool .Replicas
43
+ replicas = int32 ( * pool .Replicas )
42
44
}
43
45
44
46
// 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
53
55
}
54
56
}
55
57
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 ++ {
57
63
logrus .Debugf ("Creating %v machine %v" , role , idx )
58
64
var host * vsphere.Host
59
65
desiredZone := mpool .Zones [int (idx )% numOfZones ]
@@ -66,7 +72,7 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
66
72
logrus .Debugf ("Desired zone: %v" , desiredZone )
67
73
68
74
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 )
70
76
}
71
77
72
78
failureDomain = zones [desiredZone ]
@@ -77,18 +83,22 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
77
83
"machine.openshift.io/cluster-api-machine-type" : role ,
78
84
}
79
85
86
+ failureDomains = append (failureDomains , machinev1.VSphereFailureDomain {
87
+ Name : failureDomain .Name ,
88
+ })
89
+
80
90
osImageForZone := failureDomain .Topology .Template
81
91
if failureDomain .Topology .Template == "" {
82
92
osImageForZone = fmt .Sprintf ("%s-%s-%s" , osImage , failureDomain .Region , failureDomain .Zone )
83
93
}
84
94
85
95
vcenter , err := getVCenterFromServerName (failureDomain .Server , platform )
86
96
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" )
88
98
}
89
99
provider , err := provider (clusterID , vcenter , failureDomain , mpool , osImageForZone , userDataSecret )
90
100
if err != nil {
91
- return nil , errors .Wrap (err , "failed to create provider" )
101
+ return nil , nil , errors .Wrap (err , "failed to create provider" )
92
102
}
93
103
94
104
// Apply static IP if configured
@@ -112,8 +122,74 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
112
122
},
113
123
}
114
124
machines = append (machines , machine )
125
+
126
+ vsphereMachineProvider = provider .DeepCopy ()
127
+ }
128
+
129
+ // when multiple zones are defined, network and workspace are derived from the topology
130
+ origProv := vsphereMachineProvider .DeepCopy ()
131
+ if len (failureDomains ) > 1 {
132
+ vsphereMachineProvider .Network = machineapi.NetworkSpec {}
133
+ vsphereMachineProvider .Workspace = & machineapi.Workspace {}
134
+ vsphereMachineProvider .Template = ""
135
+ }
136
+
137
+ if len (hosts ) > 0 {
138
+ vsphereMachineProvider .Network .Devices = []machineapi.NetworkDeviceSpec {
139
+ {
140
+ AddressesFromPools : origProv .Network .Devices [0 ].AddressesFromPools ,
141
+ Nameservers : origProv .Network .Devices [0 ].Nameservers ,
142
+ },
143
+ }
144
+ }
145
+
146
+ controlPlaneMachineSet := & machinev1.ControlPlaneMachineSet {
147
+ TypeMeta : metav1.TypeMeta {
148
+ APIVersion : "machine.openshift.io/v1" ,
149
+ Kind : "ControlPlaneMachineSet" ,
150
+ },
151
+ ObjectMeta : metav1.ObjectMeta {
152
+ Namespace : "openshift-machine-api" ,
153
+ Name : "cluster" ,
154
+ Labels : map [string ]string {
155
+ "machine.openshift.io/cluster-api-cluster" : clusterID ,
156
+ },
157
+ },
158
+ Spec : machinev1.ControlPlaneMachineSetSpec {
159
+ Replicas : & replicas ,
160
+ State : machinev1 .ControlPlaneMachineSetStateActive ,
161
+ Selector : metav1.LabelSelector {
162
+ MatchLabels : map [string ]string {
163
+ "machine.openshift.io/cluster-api-machine-role" : role ,
164
+ "machine.openshift.io/cluster-api-machine-type" : role ,
165
+ "machine.openshift.io/cluster-api-cluster" : clusterID ,
166
+ },
167
+ },
168
+ Template : machinev1.ControlPlaneMachineSetTemplate {
169
+ MachineType : machinev1 .OpenShiftMachineV1Beta1MachineType ,
170
+ OpenShiftMachineV1Beta1Machine : & machinev1.OpenShiftMachineV1Beta1MachineTemplate {
171
+ FailureDomains : & machinev1.FailureDomains {
172
+ Platform : v1 .VSpherePlatformType ,
173
+ VSphere : failureDomains ,
174
+ },
175
+ ObjectMeta : machinev1.ControlPlaneMachineSetTemplateObjectMeta {
176
+ Labels : map [string ]string {
177
+ "machine.openshift.io/cluster-api-cluster" : clusterID ,
178
+ "machine.openshift.io/cluster-api-machine-role" : role ,
179
+ "machine.openshift.io/cluster-api-machine-type" : role ,
180
+ },
181
+ },
182
+ Spec : machineapi.MachineSpec {
183
+ ProviderSpec : machineapi.ProviderSpec {
184
+ Value : & runtime.RawExtension {Object : vsphereMachineProvider },
185
+ },
186
+ },
187
+ },
188
+ },
189
+ },
115
190
}
116
- return machines , nil
191
+
192
+ return machines , controlPlaneMachineSet , nil
117
193
}
118
194
119
195
// applyNetworkConfig this function will apply the static ip configuration to the networkDevice
0 commit comments