Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmiskiewicz committed Jul 16, 2024
1 parent 26f51e5 commit 913f22a
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"})
Expand Down
4 changes: 0 additions & 4 deletions internal/provider/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
Expand Down
54 changes: 54 additions & 0 deletions internal/provider/azure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package provider

import (
"github.com/kyma-project/kyma-environment-broker/internal"

Check failure on line 4 in internal/provider/azure.go

View workflow job for this annotation

GitHub Actions / run-go-linter

File is not `goimports`-ed (goimports)
"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]
}
68 changes: 68 additions & 0 deletions internal/provider/azure_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package provider

import (

Check failure on line 3 in internal/provider/azure_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

File is not `goimports`-ed (goimports)
"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)
}

0 comments on commit 913f22a

Please sign in to comment.