Skip to content

Commit

Permalink
Fix availability zones for plans (#1638)
Browse files Browse the repository at this point in the history
* Fix availability zones for plans

* Tests

* wip

* wip
  • Loading branch information
piotrmiskiewicz authored Jan 16, 2025
1 parent 387c5c0 commit 19b9ac0
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 16 deletions.
30 changes: 14 additions & 16 deletions internal/process/provisioning/create_runtime_resource_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func (s *CreateRuntimeResourceStep) Run(operation internal.Operation, log *slog.
runtimeResourceName := steps.KymaRuntimeResourceName(operation)
log.Info(fmt.Sprintf("KymaResourceName: %s, KymaResourceNamespace: %s, RuntimeResourceName: %s", kymaResourceName, kymaResourceNamespace, runtimeResourceName))

values, err := provider.GetPlanSpecificValues(&operation, s.config.MultiZoneCluster, s.config.DefaultTrialProvider, s.useSmallerMachineTypes, s.trialPlatformRegionMapping, s.config.DefaultGardenerShootPurpose)
values, err := provider.GetPlanSpecificValues(&operation, s.config.MultiZoneCluster, s.config.DefaultTrialProvider, s.useSmallerMachineTypes, s.trialPlatformRegionMapping,
s.config.DefaultGardenerShootPurpose, s.config.ControlPlaneFailureTolerance)
if err != nil {
return s.operationManager.OperationFailed(operation, fmt.Sprintf("while updating calculating plan specific values : %s", err), err, log)
}
Expand Down Expand Up @@ -175,7 +176,7 @@ func (s *CreateRuntimeResourceStep) updateRuntimeResourceObject(values provider.
if runtime.Spec.Shoot.ControlPlane == nil {
runtime.Spec.Shoot.ControlPlane = &gardener.ControlPlane{}
}
runtime.Spec.Shoot.ControlPlane.HighAvailability = s.createHighAvailabilityConfiguration()
runtime.Spec.Shoot.ControlPlane.HighAvailability = s.createHighAvailabilityConfiguration(values.FailureTolerance)
runtime.Spec.Shoot.EnforceSeedLocation = operation.ProvisioningParameters.Parameters.ShootAndSeedSameRegion
runtime.Spec.Shoot.Networking = s.createNetworkingConfiguration(operation)
runtime.Spec.Shoot.Kubernetes = s.createKubernetesConfiguration(operation)
Expand Down Expand Up @@ -252,20 +253,6 @@ func (s *CreateRuntimeResourceStep) createShootProvider(operation *internal.Oper
return provider, nil
}

func (s *CreateRuntimeResourceStep) createHighAvailabilityConfiguration() *gardener.HighAvailability {

failureToleranceType := gardener.FailureToleranceTypeZone
if s.config.ControlPlaneFailureTolerance != string(gardener.FailureToleranceTypeZone) {
failureToleranceType = gardener.FailureToleranceTypeNode
}

return &gardener.HighAvailability{
FailureTolerance: gardener.FailureTolerance{
Type: failureToleranceType,
},
}
}

func (s *CreateRuntimeResourceStep) createNetworkingConfiguration(operation internal.Operation) imv1.Networking {

networkingParams := operation.ProvisioningParameters.Parameters.Networking
Expand Down Expand Up @@ -353,6 +340,17 @@ func (s *CreateRuntimeResourceStep) updateInstance(id string, region string) err
return nil
}

func (s *CreateRuntimeResourceStep) createHighAvailabilityConfiguration(tolerance *string) *gardener.HighAvailability {
if tolerance == nil {
return nil
}
return &gardener.HighAvailability{
FailureTolerance: gardener.FailureTolerance{
Type: gardener.FailureToleranceType(*tolerance),
},
}
}

func DefaultIfParamNotSet[T interface{}](d T, param *T) T {
if param == nil {
return d
Expand Down
91 changes: 91 additions & 0 deletions internal/process/provisioning/create_runtime_resource_step_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,97 @@ func TestCreateRuntimeResourceStep_Defaults_Azure_MultiZone_YamlOnly(t *testing.
assert.Zero(t, repeat)
}

func TestCreateRuntimeResourceStep_FailureToleranceForTrial(t *testing.T) {
// given
assert.NoError(t, imv1.AddToScheme(scheme.Scheme))
memoryStorage := storage.NewMemoryStorage()

instance, operation := fixInstanceAndOperation(broker.TrialPlanID, "westeurope", "platform-region")
assertInsertions(t, memoryStorage, instance, operation)

kimConfig := fixKimConfig("trial", false)
inputConfig := input.Config{MultiZoneCluster: true}
inputConfig.ControlPlaneFailureTolerance = "zone"
inputConfig.DefaultTrialProvider = "AWS"

cli := getClientForTests(t)

step := NewCreateRuntimeResourceStep(memoryStorage.Operations(), memoryStorage.Instances(), cli, kimConfig, inputConfig, nil, false, defaultOIDSConfig)

// when
_, _, err := step.Run(operation, fixLogger())

// then
assert.NoError(t, err)
runtime := imv1.Runtime{}
err = cli.Get(context.Background(), client.ObjectKey{
Namespace: "kyma-system",
Name: operation.RuntimeID,
}, &runtime)
assert.NoError(t, err)
assert.Nil(t, runtime.Spec.Shoot.ControlPlane.HighAvailability)
}

func TestCreateRuntimeResourceStep_FailureToleranceForCommercial(t *testing.T) {
// given
assert.NoError(t, imv1.AddToScheme(scheme.Scheme))
memoryStorage := storage.NewMemoryStorage()

instance, operation := fixInstanceAndOperation(broker.AzurePlanID, "westeurope", "platform-region")
assertInsertions(t, memoryStorage, instance, operation)

kimConfig := fixKimConfig("azure", false)
inputConfig := input.Config{MultiZoneCluster: true}
inputConfig.ControlPlaneFailureTolerance = "zone"

cli := getClientForTests(t)

step := NewCreateRuntimeResourceStep(memoryStorage.Operations(), memoryStorage.Instances(), cli, kimConfig, inputConfig, nil, false, defaultOIDSConfig)

// when
_, _, err := step.Run(operation, fixLogger())

// then
assert.NoError(t, err)
runtime := imv1.Runtime{}
err = cli.Get(context.Background(), client.ObjectKey{
Namespace: "kyma-system",
Name: operation.RuntimeID,
}, &runtime)
assert.NoError(t, err)
assert.Equal(t, "zone", string(runtime.Spec.Shoot.ControlPlane.HighAvailability.FailureTolerance.Type))
}

func TestCreateRuntimeResourceStep_FailureToleranceForCommercialWithConfiguredNode(t *testing.T) {
// given
assert.NoError(t, imv1.AddToScheme(scheme.Scheme))
memoryStorage := storage.NewMemoryStorage()

instance, operation := fixInstanceAndOperation(broker.AWSPlanID, "westeurope", "platform-region")
assertInsertions(t, memoryStorage, instance, operation)

kimConfig := fixKimConfig("aws", false)
inputConfig := input.Config{MultiZoneCluster: true}
inputConfig.ControlPlaneFailureTolerance = "node"

cli := getClientForTests(t)

step := NewCreateRuntimeResourceStep(memoryStorage.Operations(), memoryStorage.Instances(), cli, kimConfig, inputConfig, nil, false, defaultOIDSConfig)

// when
_, _, err := step.Run(operation, fixLogger())

// then
assert.NoError(t, err)
runtime := imv1.Runtime{}
err = cli.Get(context.Background(), client.ObjectKey{
Namespace: "kyma-system",
Name: operation.RuntimeID,
}, &runtime)
assert.NoError(t, err)
assert.Equal(t, "node", string(runtime.Spec.Shoot.ControlPlane.HighAvailability.FailureTolerance.Type))
}

func TestCreateRuntimeResourceStep_AllYamls(t *testing.T) {

for _, testCase := range []struct {
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type (
Purpose string
MultiZone bool
ProvisioningParameters internal.ProvisioningParameters
FailureTolerance string
}
AWSTrialInputProvider struct {
PlatformRegionMapping map[string]string
Expand Down Expand Up @@ -40,6 +41,7 @@ func (p *AWSInputProvider) Provide() Values {
Purpose: p.Purpose,
VolumeSizeGb: 80,
DiskType: "gp3",
FailureTolerance: &p.FailureTolerance,
}
}

Expand Down Expand Up @@ -77,6 +79,7 @@ func (p *AWSTrialInputProvider) Provide() Values {
Purpose: PurposeEvaluation,
VolumeSizeGb: 50,
DiskType: "gp3",
FailureTolerance: nil,
}
}

Expand Down Expand Up @@ -120,6 +123,7 @@ func (p *AWSFreemiumInputProvider) Provide() Values {
Purpose: PurposeEvaluation,
VolumeSizeGb: 50,
DiskType: "gp3",
FailureTolerance: nil,
}
}

Expand Down
6 changes: 6 additions & 0 deletions internal/provider/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestAWSDefaults(t *testing.T) {
Parameters: pkg.ProvisioningParametersDTO{Region: nil},
PlatformRegion: "cf-eu11",
},
FailureTolerance: "zone",
}

// when
Expand All @@ -39,6 +40,7 @@ func TestAWSDefaults(t *testing.T) {
Purpose: "production",
VolumeSizeGb: 80,
DiskType: "gp3",
FailureTolerance: ptr.String("zone"),
}, values)
}

Expand All @@ -54,6 +56,7 @@ func TestAWSSpecific(t *testing.T) {
},
PlatformRegion: "cf-eu11",
},
FailureTolerance: "zone",
}

// when
Expand All @@ -73,6 +76,7 @@ func TestAWSSpecific(t *testing.T) {
Purpose: "production",
VolumeSizeGb: 80,
DiskType: "gp3",
FailureTolerance: ptr.String("zone"),
}, values)
}

Expand Down Expand Up @@ -103,6 +107,7 @@ func TestAWSTrialDefaults(t *testing.T) {
Purpose: "evaluation",
VolumeSizeGb: 50,
DiskType: "gp3",
FailureTolerance: nil,
}, values)
}

Expand Down Expand Up @@ -136,6 +141,7 @@ func TestAWSTrialSpecific(t *testing.T) {
Purpose: "evaluation",
VolumeSizeGb: 50,
DiskType: "gp3",
FailureTolerance: nil,
}, values)
}

Expand Down
5 changes: 5 additions & 0 deletions internal/provider/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type (
Purpose string
MultiZone bool
ProvisioningParameters internal.ProvisioningParameters
FailureTolerance string
}
AzureTrialInputProvider struct {
PlatformRegionMapping map[string]string
Expand Down Expand Up @@ -45,6 +46,7 @@ func (p *AzureInputProvider) Provide() Values {
Purpose: p.Purpose,
DiskType: "StandardSSD_LRS",
VolumeSizeGb: 80,
FailureTolerance: &p.FailureTolerance,
}
}

Expand Down Expand Up @@ -84,6 +86,7 @@ func (p *AzureTrialInputProvider) Provide() Values {
Purpose: PurposeEvaluation,
DiskType: "Standard_LRS",
VolumeSizeGb: 50,
FailureTolerance: nil,
}
}

Expand Down Expand Up @@ -128,6 +131,7 @@ func (p *AzureLiteInputProvider) Provide() Values {
Purpose: p.Purpose,
DiskType: "StandardSSD_LRS",
VolumeSizeGb: 80,
FailureTolerance: nil,
}
}

Expand Down Expand Up @@ -163,6 +167,7 @@ func (p *AzureFreemiumInputProvider) Provide() Values {
Purpose: PurposeEvaluation,
DiskType: "Standard_LRS",
VolumeSizeGb: 50,
FailureTolerance: nil,
}
}

Expand Down
7 changes: 7 additions & 0 deletions internal/provider/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestAzureDefaults(t *testing.T) {
Parameters: pkg.ProvisioningParametersDTO{Region: ptr.String("eastus")},
PlatformRegion: "cf-eu11",
},
FailureTolerance: "zone",
}

// when
Expand All @@ -38,6 +39,7 @@ func TestAzureDefaults(t *testing.T) {
Purpose: "production",
DiskType: "StandardSSD_LRS",
VolumeSizeGb: 80,
FailureTolerance: ptr.String("zone"),
}, values)
}

Expand Down Expand Up @@ -68,6 +70,7 @@ func TestAzureTrialDefaults(t *testing.T) {
Purpose: "evaluation",
DiskType: "Standard_LRS",
VolumeSizeGb: 50,
FailureTolerance: nil,
}, values)
}

Expand Down Expand Up @@ -115,6 +118,7 @@ func TestAzureSpecific(t *testing.T) {
PlatformRegion: "cf-eu11",
PlatformProvider: "azure",
},
FailureTolerance: "zone",
}

// when
Expand All @@ -134,6 +138,7 @@ func TestAzureSpecific(t *testing.T) {
Purpose: "production",
DiskType: "StandardSSD_LRS",
VolumeSizeGb: 80,
FailureTolerance: ptr.String("zone"),
}, values)
}

Expand Down Expand Up @@ -170,6 +175,7 @@ func TestAzureTrialSpecific(t *testing.T) {
Purpose: "evaluation",
DiskType: "Standard_LRS",
VolumeSizeGb: 50,
FailureTolerance: nil,
}, values)
}

Expand Down Expand Up @@ -205,5 +211,6 @@ func TestAzureLiteSpecific(t *testing.T) {
Purpose: "evaluation",
DiskType: "StandardSSD_LRS",
VolumeSizeGb: 80,
FailureTolerance: nil,
}, values)
}
3 changes: 3 additions & 0 deletions internal/provider/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type (
Purpose string
MultiZone bool
ProvisioningParameters internal.ProvisioningParameters
FailureTolerance string
}

GCPTrialInputProvider struct {
Expand All @@ -34,6 +35,7 @@ func (p *GCPInputProvider) Provide() Values {
Purpose: p.Purpose,
VolumeSizeGb: 80,
DiskType: "pd-balanced",
FailureTolerance: &p.FailureTolerance,
}
}

Expand Down Expand Up @@ -79,6 +81,7 @@ func (p *GCPTrialInputProvider) Provide() Values {
Purpose: PurposeEvaluation,
VolumeSizeGb: 30,
DiskType: "pd-standard",
FailureTolerance: nil,
}
}

Expand Down
4 changes: 4 additions & 0 deletions internal/provider/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestGCPDefaults(t *testing.T) {
Parameters: pkg.ProvisioningParametersDTO{Region: nil},
PlatformRegion: "cf-eu11",
},
FailureTolerance: "zone",
}

// when
Expand All @@ -36,6 +37,7 @@ func TestGCPDefaults(t *testing.T) {
Purpose: "production",
VolumeSizeGb: 80,
DiskType: "pd-balanced",
FailureTolerance: ptr.String("zone"),
}, values)
}

Expand All @@ -51,6 +53,7 @@ func TestGCPSpecific(t *testing.T) {
},
PlatformRegion: "cf-eu11",
},
FailureTolerance: "zone",
}

// when
Expand All @@ -70,6 +73,7 @@ func TestGCPSpecific(t *testing.T) {
Purpose: "production",
VolumeSizeGb: 80,
DiskType: "pd-balanced",
FailureTolerance: ptr.String("zone"),
}, values)
}

Expand Down
1 change: 1 addition & 0 deletions internal/provider/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ type Values struct {
Purpose string
VolumeSizeGb int
DiskType string
FailureTolerance *string
}
Loading

0 comments on commit 19b9ac0

Please sign in to comment.