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