github.com/openshift/installer@v1.4.17/pkg/asset/machines/baremetal/machines.go (about) 1 // Package baremetal generates Machine objects for bare metal. 2 package baremetal 3 4 import ( 5 "fmt" 6 7 "github.com/pkg/errors" 8 corev1 "k8s.io/api/core/v1" 9 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 10 "k8s.io/apimachinery/pkg/runtime" 11 12 machineapi "github.com/openshift/api/machine/v1beta1" 13 baremetalprovider "github.com/openshift/cluster-api-provider-baremetal/pkg/apis/baremetal/v1alpha1" 14 "github.com/openshift/installer/pkg/types" 15 "github.com/openshift/installer/pkg/types/baremetal" 16 ) 17 18 // Machines returns a list of machines for a machinepool. 19 func Machines(clusterID string, config *types.InstallConfig, pool *types.MachinePool, role, userDataSecret string) ([]machineapi.Machine, error) { 20 if configPlatform := config.Platform.Name(); configPlatform != baremetal.Name { 21 return nil, fmt.Errorf("non bare metal configuration: %q", configPlatform) 22 } 23 if poolPlatform := pool.Platform.Name(); poolPlatform != baremetal.Name { 24 return nil, fmt.Errorf("non bare metal machine-pool: %q", poolPlatform) 25 } 26 platform := config.Platform.BareMetal 27 28 total := int64(1) 29 if pool.Replicas != nil { 30 total = *pool.Replicas 31 } 32 provider, err := provider(platform, userDataSecret) 33 if err != nil { 34 return nil, errors.Wrap(err, "failed to create provider") 35 } 36 var machines []machineapi.Machine 37 for idx := int64(0); idx < total; idx++ { 38 machine := machineapi.Machine{ 39 TypeMeta: metav1.TypeMeta{ 40 APIVersion: "machine.openshift.io/v1beta1", 41 Kind: "Machine", 42 }, 43 ObjectMeta: metav1.ObjectMeta{ 44 Namespace: "openshift-machine-api", 45 Name: fmt.Sprintf("%s-%s-%d", clusterID, pool.Name, idx), 46 Labels: map[string]string{ 47 "machine.openshift.io/cluster-api-cluster": clusterID, 48 "machine.openshift.io/cluster-api-machine-role": role, 49 "machine.openshift.io/cluster-api-machine-type": role, 50 }, 51 }, 52 Spec: machineapi.MachineSpec{ 53 ProviderSpec: machineapi.ProviderSpec{ 54 Value: &runtime.RawExtension{Object: provider}, 55 }, 56 // we don't need to set Versions, because we control those via cluster operators. 57 }, 58 } 59 machines = append(machines, machine) 60 } 61 62 return machines, nil 63 } 64 65 func provider(platform *baremetal.Platform, userDataSecret string) (*baremetalprovider.BareMetalMachineProviderSpec, error) { 66 config := &baremetalprovider.BareMetalMachineProviderSpec{ 67 TypeMeta: metav1.TypeMeta{ 68 APIVersion: "baremetal.cluster.k8s.io/v1alpha1", 69 Kind: "BareMetalMachineProviderSpec", 70 }, 71 CustomDeploy: baremetalprovider.CustomDeploy{ 72 Method: "install_coreos", 73 }, 74 UserData: &corev1.SecretReference{Name: userDataSecret}, 75 } 76 return config, nil 77 }