Skip to content

Commit 1c0d4dc

Browse files
Merge pull request openshift#7780 from rvanderp3/revert-7708
SPLAT-1277: unrevert PR 7418; implement vSphere control plane machinesets
2 parents 5816b2b + e0151ed commit 1c0d4dc

File tree

6 files changed

+106
-18
lines changed

6 files changed

+106
-18
lines changed

pkg/asset/machines/master.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,15 @@ func (m *Master) Generate(dependencies asset.Parents) error {
473473
pool.Platform.VSphere = &mpool
474474
templateName := clusterID.InfraID + "-rhcos"
475475

476-
machines, err = vsphere.Machines(clusterID.InfraID, ic, &pool, templateName, "master", masterUserDataSecretName)
476+
machines, controlPlaneMachineSet, err = vsphere.Machines(clusterID.InfraID, ic, &pool, templateName, "master", masterUserDataSecretName)
477477
if err != nil {
478478
return errors.Wrap(err, "failed to create master machine objects")
479479
}
480+
481+
if ic.FeatureSet != configv1.TechPreviewNoUpgrade {
482+
controlPlaneMachineSet = nil
483+
}
484+
480485
vsphere.ConfigMasters(machines, clusterID.InfraID)
481486
case powervstypes.Name:
482487
mpool := defaultPowerVSMachinePoolPlatform()

pkg/asset/machines/vsphere/machines.go

+87-11
Original file line numberDiff line numberDiff line change
@@ -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,18 +83,22 @@ 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

94104
// Apply static IP if configured
@@ -112,8 +122,74 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
112122
},
113123
}
114124
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+
},
115190
}
116-
return machines, nil
191+
192+
return machines, controlPlaneMachineSet, nil
117193
}
118194

119195
// applyNetworkConfig this function will apply the static ip configuration to the networkDevice

pkg/asset/machines/vsphere/machines_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ func TestConfigMasters(t *testing.T) {
378378

379379
for _, tc := range testCases {
380380
t.Run(tc.testCase, func(t *testing.T) {
381-
machines, err := Machines(clusterID, tc.installConfig, tc.machinePool, "", "", "")
381+
machines, _, err := Machines(clusterID, tc.installConfig, tc.machinePool, "", "", "")
382382
assertOnUnexpectedErrorState(t, tc.expectedError, err)
383383

384384
if len(tc.workspaces) > 0 {
@@ -449,7 +449,7 @@ func TestHostsToMachines(t *testing.T) {
449449

450450
for _, tc := range testCases {
451451
t.Run(tc.testCase, func(t *testing.T) {
452-
machines, err := Machines(clusterID, tc.installConfig, tc.machinePool, "", tc.role, "")
452+
machines, _, err := Machines(clusterID, tc.installConfig, tc.machinePool, "", tc.role, "")
453453
assertOnUnexpectedErrorState(t, tc.expectedError, err)
454454

455455
// Check machine counts

pkg/asset/machines/worker.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ func (w *Worker) Generate(dependencies asset.Parents) error {
635635
logrus.Debug("Generating worker machines with static IPs.")
636636
templateName := clusterID.InfraID + "-rhcos"
637637

638-
machines, err = vsphere.Machines(clusterID.InfraID, ic, &pool, templateName, "worker", workerUserDataSecretName)
638+
machines, _, err = vsphere.Machines(clusterID.InfraID, ic, &pool, templateName, "worker", workerUserDataSecretName)
639639
if err != nil {
640640
return errors.Wrap(err, "failed to create worker machine objects")
641641
}

pkg/asset/manifests/infrastructure.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ func (i *Infrastructure) Generate(dependencies asset.Parents) error {
247247
}
248248
}
249249

250-
config.Spec.PlatformSpec.VSphere = vsphereinfra.GetInfraPlatformSpec(installConfig)
251-
250+
config.Spec.PlatformSpec.VSphere = vsphereinfra.GetInfraPlatformSpec(installConfig, clusterID.InfraID)
252251
if _, exists := cloudproviderconfig.ConfigMap.Data["vsphere.conf"]; exists {
253252
cloudProviderConfigMapKey = "vsphere.conf"
254253
}

pkg/asset/manifests/vsphere/infrastructure.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package vsphere
22

33
import (
4+
"fmt"
5+
46
configv1 "github.com/openshift/api/config/v1"
57
"github.com/openshift/installer/pkg/asset/installconfig"
68
)
79

810
// GetInfraPlatformSpec constructs VSpherePlatformSpec for the infrastructure spec
9-
func GetInfraPlatformSpec(ic *installconfig.InstallConfig) *configv1.VSpherePlatformSpec {
11+
func GetInfraPlatformSpec(ic *installconfig.InstallConfig, clusterID string) *configv1.VSpherePlatformSpec {
1012
var platformSpec configv1.VSpherePlatformSpec
1113
icPlatformSpec := ic.Config.VSphere
1214

@@ -21,6 +23,11 @@ func GetInfraPlatformSpec(ic *installconfig.InstallConfig) *configv1.VSpherePlat
2123
for _, failureDomain := range icPlatformSpec.FailureDomains {
2224
topology := failureDomain.Topology
2325
if topology.ComputeCluster != "" && topology.Networks[0] != "" {
26+
template := topology.Template
27+
if len(template) == 0 {
28+
template = fmt.Sprintf("/%s/vm/%s-rhcos-%s-%s", topology.Datacenter, clusterID, failureDomain.Region, failureDomain.Zone)
29+
}
30+
2431
platformSpec.FailureDomains = append(platformSpec.FailureDomains, configv1.VSpherePlatformFailureDomainSpec{
2532
Name: failureDomain.Name,
2633
Region: failureDomain.Region,
@@ -33,6 +40,7 @@ func GetInfraPlatformSpec(ic *installconfig.InstallConfig) *configv1.VSpherePlat
3340
Datastore: topology.Datastore,
3441
ResourcePool: topology.ResourcePool,
3542
Folder: topology.Folder,
43+
Template: template,
3644
},
3745
})
3846
}

0 commit comments

Comments
 (0)