Skip to content

Commit

Permalink
Send nil if controlplainFailureTolerance is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmiskiewicz committed Jan 17, 2025
1 parent c3edf37 commit da50e96
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
10 changes: 7 additions & 3 deletions internal/process/provisioning/create_runtime_resource_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,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(values.FailureTolerance)
runtime.Spec.Shoot.ControlPlane = 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 @@ -340,14 +340,18 @@ func (s *CreateRuntimeResourceStep) updateInstance(id string, region string) err
return nil
}

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

Expand Down
34 changes: 32 additions & 2 deletions internal/process/provisioning/create_runtime_resource_step_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func TestCreateRuntimeResourceStep_FailureToleranceForTrial(t *testing.T) {
Name: operation.RuntimeID,
}, &runtime)
assert.NoError(t, err)
assert.Nil(t, runtime.Spec.Shoot.ControlPlane.HighAvailability)
assert.Nil(t, runtime.Spec.Shoot.ControlPlane)
}

func TestCreateRuntimeResourceStep_FailureToleranceForCommercial(t *testing.T) {
Expand Down Expand Up @@ -225,6 +225,36 @@ func TestCreateRuntimeResourceStep_FailureToleranceForCommercial(t *testing.T) {
assert.Equal(t, "zone", string(runtime.Spec.Shoot.ControlPlane.HighAvailability.FailureTolerance.Type))
}

func TestCreateRuntimeResourceStep_FailureToleranceForCommercialWithNoConfig(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 = ""

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)
}

func TestCreateRuntimeResourceStep_FailureToleranceForCommercialWithConfiguredNode(t *testing.T) {
// given
assert.NoError(t, imv1.AddToScheme(scheme.Scheme))
Expand Down Expand Up @@ -800,7 +830,7 @@ func TestCreateRuntimeResourceStep_Defaults_Freemium(t *testing.T) {
assert.Equal(t, testCase.expectedProvider, runtime.Spec.Shoot.Provider.Type)
assertWorkers(t, runtime.Spec.Shoot.Provider.Workers, testCase.expectedMachineType, 1, 1, 1, 0, 1, testCase.possibleZones)

assert.Nil(t, runtime.Spec.Shoot.ControlPlane.HighAvailability)
assert.Nil(t, runtime.Spec.Shoot.ControlPlane)
})
}
}
Expand Down

0 comments on commit da50e96

Please sign in to comment.