From 903477853777e0662c5e313dd27915d765dfc02a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Pieszka?= Date: Wed, 14 Aug 2024 17:00:54 +0200 Subject: [PATCH] KIM Integration - managed by provisioner label not set for KIM only (#1040) * setting label for kim only plan regardless of viewonly setting * volume size corrected * test added --- .../create_runtime_resource_step.go | 7 +- .../create_runtime_resource_step_test.go | 65 ++++++++++++++++++- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/internal/process/provisioning/create_runtime_resource_step.go b/internal/process/provisioning/create_runtime_resource_step.go index 163826e0b3..60c69980cf 100644 --- a/internal/process/provisioning/create_runtime_resource_step.go +++ b/internal/process/provisioning/create_runtime_resource_step.go @@ -3,6 +3,7 @@ package provisioning import ( "context" "fmt" + "strconv" "time" "github.com/kyma-project/kyma-environment-broker/internal/ptr" @@ -163,7 +164,7 @@ func (s *CreateRuntimeResourceStep) createLabelsForRuntime(operation internal.Op "kyma-project.io/region": region, "operator.kyma-project.io/kyma-name": kymaName, } - if s.kimConfig.ViewOnly { + if s.kimConfig.ViewOnly && !s.kimConfig.IsDrivenByKimOnly(broker.PlanNamesMapping[operation.ProvisioningParameters.PlanID]) { labels["kyma-project.io/controlled-by-provisioner"] = "true" } return labels @@ -192,7 +193,7 @@ func (s *CreateRuntimeResourceStep) createShootProvider(operation *internal.Oper max := int32(DefaultIfParamNotSet(values.DefaultAutoScalerMax, operation.ProvisioningParameters.Parameters.AutoScalerMax)) min := int32(DefaultIfParamNotSet(values.DefaultAutoScalerMin, operation.ProvisioningParameters.Parameters.AutoScalerMin)) - volumeSize := int32(DefaultIfParamNotSet(values.VolumeSizeGb, operation.ProvisioningParameters.Parameters.VolumeSizeGb)) + volumeSize := strconv.Itoa(DefaultIfParamNotSet(values.VolumeSizeGb, operation.ProvisioningParameters.Parameters.VolumeSizeGb)) providerObj := imv1.Provider{ Type: values.ProviderType, @@ -213,7 +214,7 @@ func (s *CreateRuntimeResourceStep) createShootProvider(operation *internal.Oper Zones: values.Zones, Volume: &gardener.Volume{ Type: ptr.String(values.DiskType), - VolumeSize: string(volumeSize), + VolumeSize: volumeSize, }, }, }, diff --git a/internal/process/provisioning/create_runtime_resource_step_test.go b/internal/process/provisioning/create_runtime_resource_step_test.go index 76b0acafd6..87e514d4d6 100644 --- a/internal/process/provisioning/create_runtime_resource_step_test.go +++ b/internal/process/provisioning/create_runtime_resource_step_test.go @@ -396,6 +396,56 @@ func TestCreateRuntimeResourceStep_Defaults_AWS_SingleZone_DryRun_ActualCreation assert.NoError(t, err) } +func TestCreateRuntimeResourceStep_Defaults_AWS_SingleZone_DryRun_KimOnly_ActualCreation(t *testing.T) { + // given + log := logrus.New() + memoryStorage := storage.NewMemoryStorage() + + err := imv1.AddToScheme(scheme.Scheme) + + instance, operation := fixInstanceAndOperation(broker.AWSPlanID, "eu-west-2", "platform-region") + assertInsertions(t, memoryStorage, instance, operation) + + kimConfig := fixKimConfig("aws", false) + kimConfig.KimOnlyPlans = []string{"aws"} + kimConfig.ViewOnly = true + inputConfig := input.Config{MultiZoneCluster: false, ControlPlaneFailureTolerance: "zone"} + + cli := getClientForTests(t) + step := NewCreateRuntimeResourceStep(memoryStorage.Operations(), memoryStorage.Instances(), cli, kimConfig, inputConfig, nil, false, defaultOIDSConfig) + + // when + entry := log.WithFields(logrus.Fields{"step": "TEST"}) + _, repeat, err := step.Run(operation, entry) + + // then + assert.NoError(t, err) + assert.Zero(t, repeat) + + runtime := imv1.Runtime{} + err = cli.Get(context.Background(), client.ObjectKey{ + Namespace: "kyma-system", + Name: operation.RuntimeID, + }, &runtime) + assert.NoError(t, err) + assert.Equal(t, runtime.Name, operation.RuntimeID) + assert.Equal(t, "runtime-58f8c703-1756-48ab-9299-a847974d1fee", runtime.Labels["operator.kyma-project.io/kyma-name"]) + + assertLabelsKIMDriven(t, operation, runtime) + assertSecurity(t, runtime) + + assert.Equal(t, "aws", runtime.Spec.Shoot.Provider.Type) + assert.Equal(t, "eu-west-2", runtime.Spec.Shoot.Region) + assert.Equal(t, "production", string(runtime.Spec.Shoot.Purpose)) + assert.Equal(t, SecretBindingName, runtime.Spec.Shoot.SecretBindingName) + assertWorkers(t, runtime.Spec.Shoot.Provider.Workers, "m6i.large", 20, 3, 1, 0, 1, []string{"eu-west-2a", "eu-west-2b", "eu-west-2c"}) + assert.Equal(t, "zone", string(runtime.Spec.Shoot.ControlPlane.HighAvailability.FailureTolerance.Type)) + assertDefaultNetworking(t, runtime.Spec.Shoot.Networking) + + _, err = memoryStorage.Instances().GetByID(operation.InstanceID) + assert.NoError(t, err) +} + func TestCreateRuntimeResourceStep_Defaults_AWS_MultiZoneWithNetworking_ActualCreation(t *testing.T) { // given log := logrus.New() @@ -441,7 +491,7 @@ func TestCreateRuntimeResourceStep_Defaults_AWS_MultiZoneWithNetworking_ActualCr assert.Equal(t, "aws", runtime.Spec.Shoot.Provider.Type) assert.Equal(t, "eu-west-2", runtime.Spec.Shoot.Region) assert.Equal(t, "production", string(runtime.Spec.Shoot.Purpose)) - assertWorkers(t, runtime.Spec.Shoot.Provider.Workers, "m6i.large", 20, 3, 3, 0, 3, []string{"eu-west-2a", "eu-west-2b", "eu-west-2c"}) + assertWorkersWithVolume(t, runtime.Spec.Shoot.Provider.Workers, "m6i.large", 20, 3, 3, 0, 3, []string{"eu-west-2a", "eu-west-2b", "eu-west-2c"}, "50", "gp2") assertNetworking(t, imv1.Networking{ Nodes: "192.168.48.0/20", Pods: "10.104.0.0/24", @@ -669,6 +719,19 @@ func assertWorkers(t *testing.T, workers []gardener.Worker, machine string, maxi assert.Equal(t, workers[0].Minimum, int32(minimum)) } +func assertWorkersWithVolume(t *testing.T, workers []gardener.Worker, machine string, maximum, minimum, maxSurge, maxUnavailable int, zoneCount int, zones []string, volumeSize, volumeType string) { + assert.Len(t, workers, 1) + assert.Len(t, workers[0].Zones, zoneCount) + assert.Subset(t, zones, workers[0].Zones) + assert.Equal(t, workers[0].Machine.Type, machine) + assert.Equal(t, workers[0].MaxSurge.IntValue(), maxSurge) + assert.Equal(t, workers[0].MaxUnavailable.IntValue(), maxUnavailable) + assert.Equal(t, workers[0].Maximum, int32(maximum)) + assert.Equal(t, workers[0].Minimum, int32(minimum)) + assert.Equal(t, workers[0].Volume.VolumeSize, volumeSize) + assert.Equal(t, *workers[0].Volume.Type, volumeType) +} + func assertNetworking(t *testing.T, expected imv1.Networking, actual imv1.Networking) { assert.True(t, reflect.DeepEqual(expected, actual)) }