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
7 changes: 6 additions & 1 deletion pkg/asset/machines/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,15 @@ func (m *Master) Generate(dependencies asset.Parents) error {
pool.Platform.VSphere = &mpool
templateName := clusterID.InfraID + "-rhcos"

machines, err = vsphere.Machines(clusterID.InfraID, ic, &pool, templateName, "master", masterUserDataSecretName)
machines, controlPlaneMachineSet, err = vsphere.Machines(clusterID.InfraID, ic, &pool, templateName, "master", masterUserDataSecretName)
if err != nil {
return errors.Wrap(err, "failed to create master machine objects")
}

if ic.FeatureSet != configv1.TechPreviewNoUpgrade {
controlPlaneMachineSet = nil
}

vsphere.ConfigMasters(machines, clusterID.InfraID)
case powervstypes.Name:
mpool := defaultPowerVSMachinePoolPlatform()
Expand Down
98 changes: 87 additions & 11 deletions pkg/asset/machines/vsphere/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,37 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

v1 "github.com/openshift/api/config/v1"
machinev1 "github.com/openshift/api/machine/v1"
machineapi "github.com/openshift/api/machine/v1beta1"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/vsphere"
)

// 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 != vsphere.Name {
return nil, fmt.Errorf("non vsphere configuration: %q", configPlatform)
return nil, nil, fmt.Errorf("non vsphere configuration: %q", configPlatform)
}
if poolPlatform := pool.Platform.Name(); poolPlatform != vsphere.Name {
return nil, fmt.Errorf("non-VSphere machine-pool: %q", poolPlatform)
return nil, nil, fmt.Errorf("non-VSphere machine-pool: %q", poolPlatform)
}

var failureDomain vsphere.FailureDomain
var machines []machineapi.Machine
platform := config.Platform.VSphere
mpool := pool.Platform.VSphere
replicas := int64(1)
replicas := int32(1)

numOfZones := len(mpool.Zones)

zones, err := getDefinedZonesFromTopology(platform)
if err != nil {
return machines, err
return machines, nil, err
}

if pool.Replicas != nil {
replicas = *pool.Replicas
replicas = int32(*pool.Replicas)
}

// Create hosts to populate from. Copying so we can remove without changing original
Expand All @@ -53,7 +55,11 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
}
}

for idx := int64(0); idx < replicas; idx++ {
failureDomains := []machinev1.VSphereFailureDomain{}

vsphereMachineProvider := &machineapi.VSphereMachineProviderSpec{}

for idx := int32(0); idx < replicas; idx++ {
logrus.Debugf("Creating %v machine %v", role, idx)
var host *vsphere.Host
desiredZone := mpool.Zones[int(idx)%numOfZones]
Expand All @@ -66,7 +72,7 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
logrus.Debugf("Desired zone: %v", desiredZone)

if _, exists := zones[desiredZone]; !exists {
return nil, errors.Errorf("zone [%s] specified by machinepool is not defined", desiredZone)
return nil, nil, errors.Errorf("zone [%s] specified by machinepool is not defined", desiredZone)
}

failureDomain = zones[desiredZone]
Expand All @@ -77,18 +83,22 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
"machine.openshift.io/cluster-api-machine-type": role,
}

failureDomains = append(failureDomains, machinev1.VSphereFailureDomain{
Name: failureDomain.Name,
})

osImageForZone := failureDomain.Topology.Template
if failureDomain.Topology.Template == "" {
osImageForZone = fmt.Sprintf("%s-%s-%s", osImage, failureDomain.Region, failureDomain.Zone)
}

vcenter, err := getVCenterFromServerName(failureDomain.Server, platform)
if err != nil {
return nil, errors.Wrap(err, "unable to find vCenter in failure domains")
return nil, nil, errors.Wrap(err, "unable to find vCenter in failure domains")
}
provider, err := provider(clusterID, vcenter, failureDomain, mpool, osImageForZone, userDataSecret)
if err != nil {
return nil, errors.Wrap(err, "failed to create provider")
return nil, nil, errors.Wrap(err, "failed to create provider")
}

// Apply static IP if configured
Expand All @@ -112,8 +122,74 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
},
}
machines = append(machines, machine)

vsphereMachineProvider = provider.DeepCopy()
}

// when multiple zones are defined, network and workspace are derived from the topology
origProv := vsphereMachineProvider.DeepCopy()
if len(failureDomains) > 1 {
vsphereMachineProvider.Network = machineapi.NetworkSpec{}
vsphereMachineProvider.Workspace = &machineapi.Workspace{}
vsphereMachineProvider.Template = ""
}

if len(hosts) > 0 {
vsphereMachineProvider.Network.Devices = []machineapi.NetworkDeviceSpec{
{
AddressesFromPools: origProv.Network.Devices[0].AddressesFromPools,
Nameservers: origProv.Network.Devices[0].Nameservers,
},
}
}

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{
FailureDomains: &machinev1.FailureDomains{
Platform: v1.VSpherePlatformType,
VSphere: failureDomains,
},
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: vsphereMachineProvider},
},
},
},
},
},
}
return machines, nil

return machines, controlPlaneMachineSet, nil
}

// applyNetworkConfig this function will apply the static ip configuration to the networkDevice
Expand Down
4 changes: 2 additions & 2 deletions pkg/asset/machines/vsphere/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func TestConfigMasters(t *testing.T) {

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

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

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

// Check machine counts
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/machines/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ func (w *Worker) Generate(dependencies asset.Parents) error {
logrus.Debug("Generating worker machines with static IPs.")
templateName := clusterID.InfraID + "-rhcos"

machines, err = vsphere.Machines(clusterID.InfraID, ic, &pool, templateName, "worker", workerUserDataSecretName)
machines, _, err = vsphere.Machines(clusterID.InfraID, ic, &pool, templateName, "worker", workerUserDataSecretName)
if err != nil {
return errors.Wrap(err, "failed to create worker machine objects")
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/asset/manifests/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ func (i *Infrastructure) Generate(dependencies asset.Parents) error {
}
}

config.Spec.PlatformSpec.VSphere = vsphereinfra.GetInfraPlatformSpec(installConfig)

config.Spec.PlatformSpec.VSphere = vsphereinfra.GetInfraPlatformSpec(installConfig, clusterID.InfraID)
if _, exists := cloudproviderconfig.ConfigMap.Data["vsphere.conf"]; exists {
cloudProviderConfigMapKey = "vsphere.conf"
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/asset/manifests/vsphere/infrastructure.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package vsphere

import (
"fmt"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/installer/pkg/asset/installconfig"
)

// GetInfraPlatformSpec constructs VSpherePlatformSpec for the infrastructure spec
func GetInfraPlatformSpec(ic *installconfig.InstallConfig) *configv1.VSpherePlatformSpec {
func GetInfraPlatformSpec(ic *installconfig.InstallConfig, clusterID string) *configv1.VSpherePlatformSpec {
var platformSpec configv1.VSpherePlatformSpec
icPlatformSpec := ic.Config.VSphere

Expand All @@ -21,6 +23,11 @@ func GetInfraPlatformSpec(ic *installconfig.InstallConfig) *configv1.VSpherePlat
for _, failureDomain := range icPlatformSpec.FailureDomains {
topology := failureDomain.Topology
if topology.ComputeCluster != "" && topology.Networks[0] != "" {
template := topology.Template
if len(template) == 0 {
template = fmt.Sprintf("/%s/vm/%s-rhcos-%s-%s", topology.Datacenter, clusterID, failureDomain.Region, failureDomain.Zone)
}

platformSpec.FailureDomains = append(platformSpec.FailureDomains, configv1.VSpherePlatformFailureDomainSpec{
Name: failureDomain.Name,
Region: failureDomain.Region,
Expand All @@ -33,6 +40,7 @@ func GetInfraPlatformSpec(ic *installconfig.InstallConfig) *configv1.VSpherePlat
Datastore: topology.Datastore,
ResourcePool: topology.ResourcePool,
Folder: topology.Folder,
Template: template,
},
})
}
Expand Down