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
8 changes: 6 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 27 additions & 1 deletion pkg/asset/cluster/tfvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
igntypes "github.com/coreos/ignition/config/v2_2/types"
gcpprovider "github.com/openshift/cluster-api-provider-gcp/pkg/apis/gcpprovider/v1beta1"
libvirtprovider "github.com/openshift/cluster-api-provider-libvirt/pkg/apis/libvirtproviderconfig/v1beta1"
vsphereprovider "github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
awsprovider "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1"
Expand All @@ -33,6 +34,7 @@ import (
libvirttfvars "github.com/openshift/installer/pkg/tfvars/libvirt"
openstacktfvars "github.com/openshift/installer/pkg/tfvars/openstack"
ovirttfvars "github.com/openshift/installer/pkg/tfvars/ovirt"
vspheretfvars "github.com/openshift/installer/pkg/tfvars/vsphere"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/aws"
"github.com/openshift/installer/pkg/types/azure"
Expand Down Expand Up @@ -102,7 +104,7 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {

platform := installConfig.Config.Platform.Name()
switch platform {
case none.Name, vsphere.Name:
case none.Name:
return errors.Errorf("cannot create the cluster because %q is a UPI platform", platform)
}

Expand Down Expand Up @@ -387,6 +389,30 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
Filename: fmt.Sprintf(TfPlatformVarsFileName, platform),
Data: data,
})
case vsphere.Name:
controlPlanes, err := mastersAsset.Machines()
if err != nil {
return err
}
controlPlaneConfigs := make([]*vsphereprovider.VSphereMachineProviderSpec, len(controlPlanes))
for i, c := range controlPlanes {
controlPlaneConfigs[i] = c.Spec.ProviderSpec.Value.Object.(*vsphereprovider.VSphereMachineProviderSpec)
}
data, err = vspheretfvars.TFVars(
vspheretfvars.TFVarsSources{
ControlPlaneConfigs: controlPlaneConfigs,
Username: installConfig.Config.VSphere.Username,
Password: installConfig.Config.VSphere.Password,
Cluster: installConfig.Config.VSphere.Cluster,
},
)
if err != nil {
return errors.Wrapf(err, "failed to get %s Terraform variables", platform)
}
t.FileList = append(t.FileList, &asset.File{
Filename: fmt.Sprintf(TfPlatformVarsFileName, platform),
Data: data,
})
default:
logrus.Warnf("unrecognized platform %s", platform)
}
Expand Down
17 changes: 16 additions & 1 deletion pkg/asset/machines/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
libvirtprovider "github.com/openshift/cluster-api-provider-libvirt/pkg/apis/libvirtproviderconfig/v1beta1"
ovirtprovider "github.com/openshift/cluster-api-provider-ovirt/pkg/apis"
machineapi "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
vsphereapi "github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider"
vsphereprovider "github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1"
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -37,6 +39,7 @@ import (
"github.com/openshift/installer/pkg/asset/machines/machineconfig"
"github.com/openshift/installer/pkg/asset/machines/openstack"
"github.com/openshift/installer/pkg/asset/machines/ovirt"
"github.com/openshift/installer/pkg/asset/machines/vsphere"
"github.com/openshift/installer/pkg/asset/rhcos"
rhcosutils "github.com/openshift/installer/pkg/rhcos"
"github.com/openshift/installer/pkg/types"
Expand Down Expand Up @@ -304,8 +307,18 @@ func (m *Master) Generate(dependencies asset.Parents) error {
if err != nil {
return errors.Wrap(err, "failed to create master machine objects for ovirt provider")
}
case vspheretypes.Name:
mpool := defaultVSphereMachinePoolPlatform()
mpool.Set(ic.Platform.VSphere.DefaultMachinePlatform)
mpool.Set(pool.Platform.VSphere)
pool.Platform.VSphere = &mpool

case nonetypes.Name, vspheretypes.Name:
machines, err = vsphere.Machines(clusterID.InfraID, ic, pool, string(*rhcosImage), "master", "master-user-data")
if err != nil {
return errors.Wrap(err, "failed to create master machine objects")
}
vsphere.ConfigMasters(machines, clusterID.InfraID)
case nonetypes.Name:
default:
return fmt.Errorf("invalid Platform")
}
Expand Down Expand Up @@ -420,13 +433,15 @@ func (m *Master) Machines() ([]machineapi.Machine, error) {
libvirtapi.AddToScheme(scheme)
openstackapi.AddToScheme(scheme)
ovirtprovider.AddToScheme(scheme)
vsphereapi.AddToScheme(scheme)
decoder := serializer.NewCodecFactory(scheme).UniversalDecoder(
awsprovider.SchemeGroupVersion,
azureprovider.SchemeGroupVersion,
baremetalprovider.SchemeGroupVersion,
gcpprovider.SchemeGroupVersion,
libvirtprovider.SchemeGroupVersion,
openstackprovider.SchemeGroupVersion,
vsphereprovider.SchemeGroupVersion,
)

machines := []machineapi.Machine{}
Expand Down
94 changes: 94 additions & 0 deletions pkg/asset/machines/vsphere/machines.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Package vsphere generates Machine objects for vsphere.
package vsphere

import (
"fmt"

machineapi "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
vsphereapis "github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

"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) {
if configPlatform := config.Platform.Name(); configPlatform != vsphere.Name {
return 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)
}
platform := config.Platform.VSphere
mpool := pool.Platform.VSphere

total := int64(1)
if pool.Replicas != nil {
total = *pool.Replicas
}
var machines []machineapi.Machine
for idx := int64(0); idx < total; idx++ {
provider, err := provider(clusterID, platform, mpool, osImage, userDataSecret)
if err != nil {
return nil, errors.Wrap(err, "failed to create provider")
}

machine := machineapi.Machine{
TypeMeta: metav1.TypeMeta{
APIVersion: "machine.openshift.io/v1beta1",
Kind: "Machine",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: "openshift-machine-api",
Name: fmt.Sprintf("%s-%s-%d", clusterID, pool.Name, idx),
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: provider},
},
// we don't need to set Versions, because we control those via operators.
},
}
machines = append(machines, machine)
}
return machines, nil
}

func provider(clusterID string, platform *vsphere.Platform, mpool *vsphere.MachinePool, osImage string, userDataSecret string) (*vsphereapis.VSphereMachineProviderSpec, error) {
return &vsphereapis.VSphereMachineProviderSpec{
TypeMeta: metav1.TypeMeta{
APIVersion: vsphereapis.SchemeGroupVersion.String(),
Kind: "VSphereMachineProviderSpec",
},
UserDataSecret: &corev1.LocalObjectReference{Name: userDataSecret},
CredentialsSecret: &corev1.LocalObjectReference{Name: "vsphere-cloud-credentials"},
Template: osImage,
Network: vsphereapis.NetworkSpec{
Devices: []vsphereapis.NetworkDeviceSpec{
{
NetworkName: platform.Network,
},
},
},
Workspace: &vsphereapis.Workspace{
Server: platform.VCenter,
Datacenter: platform.Datacenter,
Datastore: platform.DefaultDatastore,
Folder: clusterID,
},
DiskGiB: mpool.OSDisk.DiskSizeGB,
}, nil
}

// ConfigMasters sets the PublicIP flag and assigns a set of load balancers to the given machines
func ConfigMasters(machines []machineapi.Machine, clusterID string) {
}
80 changes: 80 additions & 0 deletions pkg/asset/machines/vsphere/machinesets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//Package vsphere generates Machine objects for vsphere.package vsphere
package vsphere

import (
"fmt"

machineapi "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/vsphere"
)

// MachineSets returns a list of machinesets for a machinepool.
func MachineSets(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string) ([]*machineapi.MachineSet, error) {
if configPlatform := config.Platform.Name(); configPlatform != vsphere.Name {
return 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)
}

platform := config.Platform.VSphere
mpool := pool.Platform.VSphere

total := int32(0)
if pool.Replicas != nil {
total = int32(*pool.Replicas)
}
var machinesets []*machineapi.MachineSet
provider, err := provider(clusterID, platform, mpool, osImage, userDataSecret)
if err != nil {
return nil, errors.Wrap(err, "failed to create provider")
}

name := fmt.Sprintf("%s-%s", clusterID, pool.Name)
mset := &machineapi.MachineSet{
TypeMeta: metav1.TypeMeta{
APIVersion: "machine.openshift.io/v1beta1",
Kind: "MachineSet",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: "openshift-machine-api",
Name: name,
Labels: map[string]string{
"machine.openshift.io/cluster-api-cluster": clusterID,
},
},
Spec: machineapi.MachineSetSpec{
Replicas: &total,
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
"machine.openshift.io/cluster-api-machineset": name,
"machine.openshift.io/cluster-api-cluster": clusterID,
},
},
Template: machineapi.MachineTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"machine.openshift.io/cluster-api-machineset": name,
"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: provider},
},
// we don't need to set Versions, because we control those via cluster operators.
},
},
},
}
machinesets = append(machinesets, mset)

return machinesets, nil
}
26 changes: 24 additions & 2 deletions pkg/asset/machines/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/openshift/installer/pkg/asset/machines/machineconfig"
"github.com/openshift/installer/pkg/asset/machines/openstack"
"github.com/openshift/installer/pkg/asset/machines/ovirt"
"github.com/openshift/installer/pkg/asset/machines/vsphere"
"github.com/openshift/installer/pkg/asset/rhcos"
rhcosutils "github.com/openshift/installer/pkg/rhcos"
"github.com/openshift/installer/pkg/types"
Expand Down Expand Up @@ -108,6 +109,14 @@ func defaultOvirtMachinePoolPlatform() ovirttypes.MachinePool {
return ovirttypes.MachinePool{}
}

func defaultVSphereMachinePoolPlatform() vspheretypes.MachinePool {
return vspheretypes.MachinePool{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OSDisk: vspheretypes.OSDisk{
DiskSizeGB: 120,
},
}
}

// Worker generates the machinesets for `worker` machine pool.
type Worker struct {
UserDataFile *asset.File
Expand Down Expand Up @@ -289,7 +298,20 @@ func (w *Worker) Generate(dependencies asset.Parents) error {

sets, err := openstack.MachineSets(clusterID.InfraID, ic, &pool, imageName, "worker", "worker-user-data")
if err != nil {
return errors.Wrap(err, "failed to create master machine objects")
return errors.Wrap(err, "failed to create worker machine objects")
}
for _, set := range sets {
machineSets = append(machineSets, set)
}
case vspheretypes.Name:
mpool := defaultVSphereMachinePoolPlatform()
mpool.Set(ic.Platform.VSphere.DefaultMachinePlatform)
mpool.Set(pool.Platform.VSphere)
pool.Platform.VSphere = &mpool

sets, err := vsphere.MachineSets(clusterID.InfraID, ic, &pool, string(*rhcosImage), "worker", "worker-user-data")
if err != nil {
return errors.Wrap(err, "failed to create worker machine objects")
}
for _, set := range sets {
machineSets = append(machineSets, set)
Expand All @@ -304,7 +326,7 @@ func (w *Worker) Generate(dependencies asset.Parents) error {
for _, set := range sets {
machineSets = append(machineSets, set)
}
case nonetypes.Name, vspheretypes.Name:
case nonetypes.Name:
default:
return fmt.Errorf("invalid Platform")
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/types/vsphere/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ package vsphere
// MachinePool stores the configuration for a machine pool installed
// on vSphere.
type MachinePool struct {
// OSDisk defines the storage for instance.
OSDisk `json:"osDisk"`
}

// OSDisk defines the disk for a virtual machine.
type OSDisk struct {
// DiskSizeGB defines the size of disk in GB.
DiskSizeGB int32 `json:"diskSizeGB"`
}

// Set sets the values from `required` to `p`.
func (p *MachinePool) Set(required *MachinePool) {
if required == nil || p == nil {
return
}

if required.OSDisk.DiskSizeGB != 0 {
p.OSDisk.DiskSizeGB = required.OSDisk.DiskSizeGB
}
}
Loading