github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/provider/openstack_provider.go (about) 1 package provider 2 3 import ( 4 "fmt" 5 "math/rand" 6 7 "github.com/kyma-project/kyma-environment-broker/internal/networking" 8 9 "github.com/kyma-project/kyma-environment-broker/internal/ptr" 10 11 "github.com/kyma-project/control-plane/components/provisioner/pkg/gqlschema" 12 "github.com/kyma-project/kyma-environment-broker/internal" 13 ) 14 15 const ( 16 DefaultOpenStackRegion = "eu-de-2" 17 DefaultExposureClass = "converged-cloud-internet" 18 ) 19 20 type OpenStackInput struct { 21 FloatingPoolName string 22 } 23 24 func (p *OpenStackInput) Defaults() *gqlschema.ClusterConfigInput { 25 return &gqlschema.ClusterConfigInput{ 26 GardenerConfig: &gqlschema.GardenerConfigInput{ 27 DiskType: nil, 28 MachineType: "g_c4_m16", 29 Region: DefaultOpenStackRegion, 30 Provider: "openstack", 31 WorkerCidr: networking.DefaultNodesCIDR, 32 AutoScalerMin: 4, 33 AutoScalerMax: 8, 34 MaxSurge: 1, 35 MaxUnavailable: 0, 36 ExposureClassName: ptr.String(DefaultExposureClass), 37 ProviderSpecificConfig: &gqlschema.ProviderSpecificInput{ 38 OpenStackConfig: &gqlschema.OpenStackProviderConfigInput{ 39 Zones: ZonesForOpenStack(DefaultOpenStackRegion), 40 FloatingPoolName: p.FloatingPoolName, 41 CloudProfileName: "converged-cloud-cp", 42 LoadBalancerProvider: "f5", 43 }, 44 }, 45 }, 46 } 47 } 48 49 func (p *OpenStackInput) ApplyParameters(input *gqlschema.ClusterConfigInput, pp internal.ProvisioningParameters) { 50 if pp.Parameters.Region != nil && *pp.Parameters.Region != "" { 51 input.GardenerConfig.ProviderSpecificConfig.OpenStackConfig.Zones = ZonesForOpenStack(*pp.Parameters.Region) 52 } 53 } 54 55 func (p *OpenStackInput) Profile() gqlschema.KymaProfile { 56 return gqlschema.KymaProfileProduction 57 } 58 59 func (p *OpenStackInput) Provider() internal.CloudProvider { 60 return internal.Openstack 61 } 62 63 // openstackZones defines a possible suffixes for given OpenStack regions 64 // The table is tested in a unit test to check if all necessary regions are covered 65 var openstackZones = map[string]string{ 66 "eu-de-1": "abd", 67 "eu-de-2": "abd", 68 "ap-sa-1": "a", 69 } 70 71 func ZonesForOpenStack(region string) []string { 72 zones, found := openstackZones[region] 73 if !found { 74 zones = "a" 75 } 76 zone := string(zones[rand.Intn(len(zones))]) 77 return []string{fmt.Sprintf("%s%s", region, zone)} 78 }