diff --git a/internal/process/provisioning/create_runtime_resource_step.go b/internal/process/provisioning/create_runtime_resource_step.go index fd8ad9311d..c7f08efaed 100644 --- a/internal/process/provisioning/create_runtime_resource_step.go +++ b/internal/process/provisioning/create_runtime_resource_step.go @@ -198,10 +198,16 @@ type Provider interface { func (s *CreateRuntimeResourceStep) providerValues(operation *internal.Operation) (provider.Values, error) { var p Provider switch operation.ProvisioningParameters.PlanID { + // TODO: implement input provider for Azure case broker.AWSPlanID: p = &provider.AWSInputProvider{ MultiZone: s.config.MultiZoneCluster, - ProvisioningParameters: internal.ProvisioningParameters{}, + ProvisioningParameters: operation.ProvisioningParameters, + } + case broker.AzurePlanID: + p = &provider.AzureInputProvider{ + MultiZone: s.config.MultiZoneCluster, + ProvisioningParameters: operation.ProvisioningParameters, } case broker.TrialPlanID: var trialProvider internal.CloudProvider diff --git a/internal/process/provisioning/create_runtime_resource_step_test.go b/internal/process/provisioning/create_runtime_resource_step_test.go index 28614e5d8c..68ad6727c9 100644 --- a/internal/process/provisioning/create_runtime_resource_step_test.go +++ b/internal/process/provisioning/create_runtime_resource_step_test.go @@ -1,6 +1,7 @@ package provisioning import ( + "github.com/kyma-project/kyma-environment-broker/internal/process/input" "testing" "github.com/kyma-project/kyma-environment-broker/internal/fixture" @@ -30,7 +31,8 @@ func TestCreateRuntimeResourceStep_HappyPath_YamlOnly(t *testing.T) { DryRun: true, } - step := NewCreateRuntimeResourceStep(memoryStorage.Operations(), memoryStorage.RuntimeStates(), memoryStorage.Instances(), kimConfig) + step := NewCreateRuntimeResourceStep(memoryStorage.Operations(), + memoryStorage.RuntimeStates(), memoryStorage.Instances(), kimConfig, input.Config{}) // when entry := log.WithFields(logrus.Fields{"step": "TEST"}) diff --git a/internal/provider/aws_test.go b/internal/provider/aws_test.go index 49c5cc2223..8f6744c7ea 100644 --- a/internal/provider/aws_test.go +++ b/internal/provider/aws_test.go @@ -42,10 +42,6 @@ func TestAWSSpecific(t *testing.T) { MultiZone: true, ProvisioningParameters: internal.ProvisioningParameters{ Parameters: internal.ProvisioningParametersDTO{ - AutoScalerParameters: internal.AutoScalerParameters{ - AutoScalerMin: ptr.Integer(5), - AutoScalerMax: ptr.Integer(6), - }, MachineType: ptr.String("m6i.xlarge"), Region: ptr.String("ap-southeast-1"), }, diff --git a/internal/provider/azure.go b/internal/provider/azure.go new file mode 100644 index 0000000000..3c48e6a982 --- /dev/null +++ b/internal/provider/azure.go @@ -0,0 +1,54 @@ +package provider + +import ( + "github.com/kyma-project/kyma-environment-broker/internal" + "math/rand" +) + +type ( + AzureInputProvider struct { + MultiZone bool + ProvisioningParameters internal.ProvisioningParameters + } +) + +func (p *AzureInputProvider) Provide() Values { + zonesCount := p.zonesCount() + zones := p.zones() + region := DefaultAzureRegion + if p.ProvisioningParameters.Parameters.Region != nil { + region = *p.ProvisioningParameters.Parameters.Region + } + return Values{ + DefaultAutoScalerMax: 20, + DefaultAutoScalerMin: 3, + ZonesCount: zonesCount, + Zones: zones, + ProviderType: "azure", + DefaultMachineType: DefaultAzureMachineType, + Region: region, + Purpose: PurposeProduction, + } +} + +func (p *AzureInputProvider) zonesCount() int { + zonesCount := 1 + if p.MultiZone { + zonesCount = DefaultAzureMultiZoneCount + } + return zonesCount +} + +func (p *AzureInputProvider) zones() []string { + return p.generateRandomAzureZones(p.zonesCount()) +} + +func (p *AzureInputProvider) generateRandomAzureZones(zonesCount int) []string { + zones := []string{"1", "2", "3"} + if zonesCount > 3 { + zonesCount = 3 + } + + rand.Shuffle(len(zones), func(i, j int) { zones[i], zones[j] = zones[j], zones[i] }) + return zones[:zonesCount] +} diff --git a/internal/provider/azure_test.go b/internal/provider/azure_test.go new file mode 100644 index 0000000000..36db2b0ea6 --- /dev/null +++ b/internal/provider/azure_test.go @@ -0,0 +1,68 @@ +package provider + +import ( + "github.com/kyma-project/kyma-environment-broker/internal" + "github.com/kyma-project/kyma-environment-broker/internal/ptr" + "testing" +) + +func TestAzureDefaults(t *testing.T) { + + // given + aws := AzureInputProvider{ + MultiZone: true, + ProvisioningParameters: internal.ProvisioningParameters{ + Parameters: internal.ProvisioningParametersDTO{Region: ptr.String("eastus")}, + PlatformRegion: "cf-eu11", + }, + } + + // when + values := aws.Provide() + + // then + + assertValues(t, Values{ + DefaultAutoScalerMax: 20, + DefaultAutoScalerMin: 3, + ZonesCount: 3, + Zones: []string{"1", "2", "3"}, + ProviderType: "azure", + DefaultMachineType: "Standard_D2s_v5", + Region: "eastus", + Purpose: "production", + }, values) +} + +func TestAzureSpecific(t *testing.T) { + + // given + aws := AzureInputProvider{ + MultiZone: true, + ProvisioningParameters: internal.ProvisioningParameters{ + Parameters: internal.ProvisioningParametersDTO{ + MachineType: ptr.String("Standard_D48_v3"), + Region: ptr.String("uksouth"), + }, + PlatformRegion: "cf-eu11", + PlatformProvider: "azure", + }, + } + + // when + values := aws.Provide() + + // then + + assertValues(t, Values{ + // default values does not depend on provisioning parameters + DefaultAutoScalerMax: 20, + DefaultAutoScalerMin: 3, + ZonesCount: 3, + Zones: []string{"1,2,3"}, + ProviderType: "azure", + DefaultMachineType: "Standard_D48_v3", + Region: "uksouth", + Purpose: "production", + }, values) +}