-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add machines and machinesets for VSphere #2889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-robot
merged 1 commit into
openshift:master
from
patrickdillon:vsphere-machinesets-cors-1318
Jan 16, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these should be defaulted as well:
https://github.com/openshift/machine-api-operator/blob/master/pkg/apis/vsphereprovider/v1alpha1/vsphereproviderconfig_types.go#L34-L49