-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26f51e5
commit 913f22a
Showing
5 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
"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] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |