github.com/openshift/installer@v1.4.17/pkg/asset/machines/baremetal/machinesets.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 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 9 "k8s.io/apimachinery/pkg/runtime" 10 "k8s.io/utils/pointer" 11 12 machineapi "github.com/openshift/api/machine/v1beta1" 13 "github.com/openshift/installer/pkg/types" 14 "github.com/openshift/installer/pkg/types/baremetal" 15 ) 16 17 // MachineSets returns a list of machinesets for a machinepool. 18 func MachineSets(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string) ([]*machineapi.MachineSet, error) { 19 if configPlatform := config.Platform.Name(); configPlatform != baremetal.Name { 20 return nil, fmt.Errorf("non bare metal configuration: %q", configPlatform) 21 } 22 // FIXME: empty is a valid case for bare metal as we don't use it? 23 if poolPlatform := pool.Platform.Name(); poolPlatform != "" && poolPlatform != baremetal.Name { 24 return nil, fmt.Errorf("non bare metal machine-pool: %q", poolPlatform) 25 } 26 platform := config.Platform.BareMetal 27 // FIXME: bare metal actuator does not support any options from machinepool. 28 // mpool := pool.Platform.BareMetal 29 30 total := int64(0) 31 if pool.Replicas != nil { 32 total = *pool.Replicas 33 } 34 35 provider, err := provider(platform, userDataSecret) 36 if err != nil { 37 return nil, errors.Wrap(err, "failed to create provider") 38 } 39 name := fmt.Sprintf("%s-%s-%d", clusterID, pool.Name, 0) 40 mset := &machineapi.MachineSet{ 41 TypeMeta: metav1.TypeMeta{ 42 APIVersion: "machine.openshift.io/v1beta1", 43 Kind: "MachineSet", 44 }, 45 ObjectMeta: metav1.ObjectMeta{ 46 Namespace: "openshift-machine-api", 47 Name: name, 48 Labels: map[string]string{ 49 "machine.openshift.io/cluster-api-cluster": clusterID, 50 "machine.openshift.io/cluster-api-machine-role": role, 51 "machine.openshift.io/cluster-api-machine-type": role, 52 }, 53 }, 54 Spec: machineapi.MachineSetSpec{ 55 Replicas: pointer.Int32Ptr(int32(total)), 56 Selector: metav1.LabelSelector{ 57 MatchLabels: map[string]string{ 58 "machine.openshift.io/cluster-api-machineset": name, 59 "machine.openshift.io/cluster-api-cluster": clusterID, 60 }, 61 }, 62 Template: machineapi.MachineTemplateSpec{ 63 ObjectMeta: machineapi.ObjectMeta{ 64 Labels: map[string]string{ 65 "machine.openshift.io/cluster-api-machineset": name, 66 "machine.openshift.io/cluster-api-cluster": clusterID, 67 "machine.openshift.io/cluster-api-machine-role": role, 68 "machine.openshift.io/cluster-api-machine-type": role, 69 }, 70 }, 71 Spec: machineapi.MachineSpec{ 72 ProviderSpec: machineapi.ProviderSpec{ 73 Value: &runtime.RawExtension{Object: provider}, 74 }, 75 // we don't need to set Versions, because we control those via cluster operators. 76 }, 77 }, 78 }, 79 } 80 81 return []*machineapi.MachineSet{mset}, nil 82 }