github.com/openshift/installer@v1.4.17/pkg/asset/machines/powervs/machinesets.go (about) 1 // Package powervs generates Machine objects for IBM Power VS. 2 package powervs 3 4 import ( 5 "fmt" 6 7 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 8 "k8s.io/apimachinery/pkg/runtime" 9 10 machineapi "github.com/openshift/api/machine/v1beta1" 11 "github.com/openshift/installer/pkg/types" 12 "github.com/openshift/installer/pkg/types/powervs" 13 ) 14 15 // MachineSets returns a list of machinesets for a machinepool. 16 func MachineSets(clusterID string, config *types.InstallConfig, pool *types.MachinePool, role, userDataSecret string) ([]*machineapi.MachineSet, error) { 17 if configPlatform := config.Platform.Name(); configPlatform != powervs.Name { 18 return nil, fmt.Errorf("non-powerVS configuration: %q", configPlatform) 19 } 20 if poolPlatform := pool.Platform.Name(); poolPlatform != powervs.Name { 21 return nil, fmt.Errorf("non-powerVS machine-pool: %q", poolPlatform) 22 } 23 24 platform := config.Platform.PowerVS 25 mpool := pool.Platform.PowerVS 26 var network string 27 image := fmt.Sprintf("rhcos-%s", clusterID) 28 29 total := int32(0) 30 if pool.Replicas != nil { 31 total = int32(*pool.Replicas) 32 } 33 var machinesets []*machineapi.MachineSet 34 provider, err := provider(clusterID, platform, mpool, userDataSecret, image, network) 35 if err != nil { 36 return nil, fmt.Errorf("failed to create provider: %w", err) 37 } 38 39 name := fmt.Sprintf("%s-%s", clusterID, pool.Name) 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 }, 51 }, 52 Spec: machineapi.MachineSetSpec{ 53 Replicas: &total, 54 Selector: metav1.LabelSelector{ 55 MatchLabels: map[string]string{ 56 "machine.openshift.io/cluster-api-machineset": name, 57 "machine.openshift.io/cluster-api-cluster": clusterID, 58 }, 59 }, 60 Template: machineapi.MachineTemplateSpec{ 61 ObjectMeta: machineapi.ObjectMeta{ 62 Labels: map[string]string{ 63 "machine.openshift.io/cluster-api-machineset": name, 64 "machine.openshift.io/cluster-api-cluster": clusterID, 65 "machine.openshift.io/cluster-api-machine-role": role, 66 "machine.openshift.io/cluster-api-machine-type": role, 67 }, 68 }, 69 Spec: machineapi.MachineSpec{ 70 ProviderSpec: machineapi.ProviderSpec{ 71 Value: &runtime.RawExtension{Object: provider}, 72 }, 73 }, 74 }, 75 }, 76 } 77 machinesets = append(machinesets, mset) 78 79 return machinesets, nil 80 }