From 48f80330cc95d8deb24e4e9552397a1a807c83ca Mon Sep 17 00:00:00 2001 From: Pieszka Date: Thu, 25 Jul 2024 11:03:30 +0200 Subject: [PATCH 1/8] testing target secret setting --- internal/process/provisioning/create_runtime_resource_step.go | 1 + .../process/provisioning/create_runtime_resource_step_test.go | 1 + 2 files changed, 2 insertions(+) diff --git a/internal/process/provisioning/create_runtime_resource_step.go b/internal/process/provisioning/create_runtime_resource_step.go index 4b21849791..d7c9937b08 100644 --- a/internal/process/provisioning/create_runtime_resource_step.go +++ b/internal/process/provisioning/create_runtime_resource_step.go @@ -117,6 +117,7 @@ func (s *CreateRuntimeResourceStep) createRuntimeResourceObject(operation intern runtime.Spec.Shoot.Region = values.Region runtime.Spec.Shoot.Purpose = gardener.ShootPurpose(values.Purpose) runtime.Spec.Shoot.PlatformRegion = operation.ProvisioningParameters.PlatformRegion + runtime.Spec.Shoot.SecretBindingName = *operation.ProvisioningParameters.Parameters.TargetSecret runtime.Spec.Security = s.createSecurityConfiguration(operation) return &runtime, nil diff --git a/internal/process/provisioning/create_runtime_resource_step_test.go b/internal/process/provisioning/create_runtime_resource_step_test.go index 45a32c6713..e09d4f2eb2 100644 --- a/internal/process/provisioning/create_runtime_resource_step_test.go +++ b/internal/process/provisioning/create_runtime_resource_step_test.go @@ -794,5 +794,6 @@ func fixProvisioningParametersDTOWithRegion(region string) internal.Provisioning Name: "cluster-test", Region: ptr.String(region), RuntimeAdministrators: runtimeAdministrators, + TargetSecret: ptr.String("gardener-secret"), } } From 0958f41c91fce525529e1ef4aec180b1b4b1a1d4 Mon Sep 17 00:00:00 2001 From: Pieszka Date: Thu, 25 Jul 2024 13:08:21 +0200 Subject: [PATCH 2/8] assert workers defined --- .../create_runtime_resource_step_test.go | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/internal/process/provisioning/create_runtime_resource_step_test.go b/internal/process/provisioning/create_runtime_resource_step_test.go index e09d4f2eb2..b5af80b366 100644 --- a/internal/process/provisioning/create_runtime_resource_step_test.go +++ b/internal/process/provisioning/create_runtime_resource_step_test.go @@ -3,8 +3,9 @@ package provisioning import ( "context" "fmt" + gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1" + "k8s.io/apimachinery/pkg/util/intstr" "os" - "reflect" "strings" "testing" @@ -30,6 +31,8 @@ import ( "k8s.io/client-go/kubernetes/scheme" ) +const SecretBindingName = "gardener-secret" + var runtimeAdministrators = []string{"admin1@test.com", "admin2@test.com"} func TestCreateRuntimeResourceStep_Defaults_Azure_MultiZone_YamlOnly(t *testing.T) { @@ -319,6 +322,8 @@ func TestCreateRuntimeResourceStep_Defaults_AWS_SingleZone_ActualCreation(t *tes assert.Equal(t, runtime.Spec.Shoot.Provider.Type, "aws") assert.Equal(t, runtime.Spec.Shoot.Region, "eu-west-2") assert.Equal(t, string(runtime.Spec.Shoot.Purpose), "production") + assert.Equal(t, runtime.Spec.Shoot.SecretBindingName, SecretBindingName) + //assertWorkers(t, runtime.Spec.Shoot.Provider.Workers, 1, 1) assert.Len(t, runtime.Spec.Shoot.Provider.Workers, 1) assert.Len(t, runtime.Spec.Shoot.Provider.Workers[0].Zones, 1) //TODO assert zone as an element from set @@ -706,10 +711,10 @@ func TestCreateRuntimeResourceStep_Defaults_GCP_MultiZone_ActualCreation(t *test } -// assertions and fixtures +// assertions func assertSecurity(t *testing.T, runtime imv1.Runtime) { - assert.True(t, reflect.DeepEqual(runtime.Spec.Security.Administrators, runtimeAdministrators)) + assert.ElementsMatch(t, runtime.Spec.Security.Administrators, runtimeAdministrators) assert.Equal(t, runtime.Spec.Security.Networking.Filter.Egress, imv1.Egress(imv1.Egress{Enabled: false})) } @@ -724,6 +729,19 @@ func assertLabels(t *testing.T, preOperation internal.Operation, runtime imv1.Ru assert.Equal(t, *preOperation.ProvisioningParameters.Parameters.Region, runtime.Labels["kyma-project.io/region"]) } +func assertWorkers(t *testing.T, workers []gardener.Worker, machine string, maximum, minimum int32, maxSurge, maxUnavailable *intstr.IntOrString, zoneCount int, zones []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, maxSurge) + assert.Equal(t, workers[0].MaxUnavailable, maxUnavailable) + assert.Equal(t, workers[0].Maximum, maximum) + assert.Equal(t, workers[0].Minimum, minimum) +} + +// test fixtures + func fixOperationForCreateRuntimeResource(instanceID string, provisioningParameters internal.ProvisioningParameters) internal.Operation { operation := fixture.FixProvisioningOperationWithProvisioningParameters("op-id", instanceID, provisioningParameters) operation.KymaTemplate = ` @@ -794,6 +812,6 @@ func fixProvisioningParametersDTOWithRegion(region string) internal.Provisioning Name: "cluster-test", Region: ptr.String(region), RuntimeAdministrators: runtimeAdministrators, - TargetSecret: ptr.String("gardener-secret"), + TargetSecret: ptr.String(SecretBindingName), } } From 9c8083c423cf320c3ee1a26c372596b98830e863 Mon Sep 17 00:00:00 2001 From: Pieszka Date: Thu, 25 Jul 2024 14:04:56 +0200 Subject: [PATCH 3/8] aws with workers assert --- .../create_runtime_resource_step_test.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/internal/process/provisioning/create_runtime_resource_step_test.go b/internal/process/provisioning/create_runtime_resource_step_test.go index b5af80b366..e3c9d33637 100644 --- a/internal/process/provisioning/create_runtime_resource_step_test.go +++ b/internal/process/provisioning/create_runtime_resource_step_test.go @@ -4,7 +4,6 @@ import ( "context" "fmt" gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1" - "k8s.io/apimachinery/pkg/util/intstr" "os" "strings" "testing" @@ -323,9 +322,7 @@ func TestCreateRuntimeResourceStep_Defaults_AWS_SingleZone_ActualCreation(t *tes assert.Equal(t, runtime.Spec.Shoot.Region, "eu-west-2") assert.Equal(t, string(runtime.Spec.Shoot.Purpose), "production") assert.Equal(t, runtime.Spec.Shoot.SecretBindingName, SecretBindingName) - //assertWorkers(t, runtime.Spec.Shoot.Provider.Workers, 1, 1) - assert.Len(t, runtime.Spec.Shoot.Provider.Workers, 1) - assert.Len(t, runtime.Spec.Shoot.Provider.Workers[0].Zones, 1) //TODO assert zone as an element from set + assertWorkers(t, runtime.Spec.Shoot.Provider.Workers, "m6i.large", 20, 3, 3, 0, 1, []string{"eu-west-2a", "eu-west-2b", "eu-west-2c"}) _, err = memoryStorage.Instances().GetByID(preOperation.InstanceID) assert.NoError(t, err) @@ -377,8 +374,7 @@ func TestCreateRuntimeResourceStep_Defaults_AWS_MultiZone_ActualCreation(t *test assert.Equal(t, runtime.Spec.Shoot.Provider.Type, "aws") assert.Equal(t, runtime.Spec.Shoot.Region, "eu-west-2") assert.Equal(t, string(runtime.Spec.Shoot.Purpose), "production") - assert.Len(t, runtime.Spec.Shoot.Provider.Workers, 1) - assert.Len(t, runtime.Spec.Shoot.Provider.Workers[0].Zones, 3) //TODO assert zones + assertWorkers(t, runtime.Spec.Shoot.Provider.Workers, "m6i.large", 20, 3, 3, 0, 3, []string{"eu-west-2a", "eu-west-2b", "eu-west-2c"}) _, err = memoryStorage.Instances().GetByID(preOperation.InstanceID) assert.NoError(t, err) @@ -729,15 +725,15 @@ func assertLabels(t *testing.T, preOperation internal.Operation, runtime imv1.Ru assert.Equal(t, *preOperation.ProvisioningParameters.Parameters.Region, runtime.Labels["kyma-project.io/region"]) } -func assertWorkers(t *testing.T, workers []gardener.Worker, machine string, maximum, minimum int32, maxSurge, maxUnavailable *intstr.IntOrString, zoneCount int, zones []string) { +func assertWorkers(t *testing.T, workers []gardener.Worker, machine string, maximum, minimum, maxSurge, maxUnavailable int, zoneCount int, zones []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, maxSurge) - assert.Equal(t, workers[0].MaxUnavailable, maxUnavailable) - assert.Equal(t, workers[0].Maximum, maximum) - assert.Equal(t, workers[0].Minimum, minimum) + 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)) } // test fixtures From a2759f471fe492e9d0202178591d1c3ef222e802 Mon Sep 17 00:00:00 2001 From: Pieszka Date: Thu, 25 Jul 2024 14:07:03 +0200 Subject: [PATCH 4/8] preview with workers asserted --- .../provisioning/create_runtime_resource_step_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/internal/process/provisioning/create_runtime_resource_step_test.go b/internal/process/provisioning/create_runtime_resource_step_test.go index e3c9d33637..3f552439b8 100644 --- a/internal/process/provisioning/create_runtime_resource_step_test.go +++ b/internal/process/provisioning/create_runtime_resource_step_test.go @@ -426,8 +426,7 @@ func TestCreateRuntimeResourceStep_Defaults_Preview_SingleZone_ActualCreation(t assert.Equal(t, runtime.Spec.Shoot.Provider.Type, "aws") assert.Equal(t, runtime.Spec.Shoot.Region, "eu-west-2") assert.Equal(t, string(runtime.Spec.Shoot.Purpose), "production") - assert.Len(t, runtime.Spec.Shoot.Provider.Workers, 1) - assert.Len(t, runtime.Spec.Shoot.Provider.Workers[0].Zones, 1) //TODO assert zone as an element from set + assertWorkers(t, runtime.Spec.Shoot.Provider.Workers, "m6i.large", 20, 3, 1, 0, 1, []string{"eu-west-2a", "eu-west-2b", "eu-west-2c"}) _, err = memoryStorage.Instances().GetByID(preOperation.InstanceID) assert.NoError(t, err) @@ -480,8 +479,7 @@ func TestCreateRuntimeResourceStep_Defaults_Preview_MultiZone_ActualCreation(t * assert.Equal(t, runtime.Spec.Shoot.Provider.Type, "aws") assert.Equal(t, runtime.Spec.Shoot.Region, "eu-west-2") assert.Equal(t, string(runtime.Spec.Shoot.Purpose), "production") - assert.Len(t, runtime.Spec.Shoot.Provider.Workers, 1) - assert.Len(t, runtime.Spec.Shoot.Provider.Workers[0].Zones, 3) //TODO assert zones + assertWorkers(t, runtime.Spec.Shoot.Provider.Workers, "m6i.large", 20, 3, 3, 0, 3, []string{"eu-west-2a", "eu-west-2b", "eu-west-2c"}) _, err = memoryStorage.Instances().GetByID(preOperation.InstanceID) assert.NoError(t, err) From 3308338d89ebf3874be314eaa603dcf7858652be Mon Sep 17 00:00:00 2001 From: Pieszka Date: Thu, 25 Jul 2024 14:09:59 +0200 Subject: [PATCH 5/8] azure with workers asserted --- .../provisioning/create_runtime_resource_step_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/process/provisioning/create_runtime_resource_step_test.go b/internal/process/provisioning/create_runtime_resource_step_test.go index 3f552439b8..4e21ad2170 100644 --- a/internal/process/provisioning/create_runtime_resource_step_test.go +++ b/internal/process/provisioning/create_runtime_resource_step_test.go @@ -532,8 +532,8 @@ func TestCreateRuntimeResourceStep_Defaults_Azure_SingleZone_ActualCreation(t *t assert.Equal(t, runtime.Spec.Shoot.Provider.Type, "azure") assert.Equal(t, runtime.Spec.Shoot.Region, "westeurope") assert.Equal(t, string(runtime.Spec.Shoot.Purpose), "production") - assert.Len(t, runtime.Spec.Shoot.Provider.Workers, 1) - assert.Len(t, runtime.Spec.Shoot.Provider.Workers[0].Zones, 1) //TODO assert zone as an element from set + + assertWorkers(t, runtime.Spec.Shoot.Provider.Workers, "Standard_D2s_v5", 20, 3, 1, 0, 1, []string{"1", "2", "3"}) _, err = memoryStorage.Instances().GetByID(preOperation.InstanceID) assert.NoError(t, err) @@ -587,8 +587,7 @@ func TestCreateRuntimeResourceStep_Defaults_Azure_MultiZone_ActualCreation(t *te assert.Equal(t, runtime.Spec.Shoot.Provider.Type, "azure") assert.Equal(t, runtime.Spec.Shoot.Region, "westeurope") assert.Equal(t, string(runtime.Spec.Shoot.Purpose), "production") - assert.Len(t, runtime.Spec.Shoot.Provider.Workers, 1) - assert.Len(t, runtime.Spec.Shoot.Provider.Workers[0].Zones, 3) //TODO assert zones + assertWorkers(t, runtime.Spec.Shoot.Provider.Workers, "Standard_D2s_v5", 20, 3, 3, 0, 3, []string{"1", "2", "3"}) _, err = memoryStorage.Instances().GetByID(preOperation.InstanceID) assert.NoError(t, err) From 90581910fb38a9c701c419f032c7907e91dcd44d Mon Sep 17 00:00:00 2001 From: Pieszka Date: Thu, 25 Jul 2024 14:13:40 +0200 Subject: [PATCH 6/8] gcp with workers asserted --- .../provisioning/create_runtime_resource_step_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/internal/process/provisioning/create_runtime_resource_step_test.go b/internal/process/provisioning/create_runtime_resource_step_test.go index 4e21ad2170..f4cddc729c 100644 --- a/internal/process/provisioning/create_runtime_resource_step_test.go +++ b/internal/process/provisioning/create_runtime_resource_step_test.go @@ -641,8 +641,7 @@ func TestCreateRuntimeResourceStep_Defaults_GCP_SingleZone_ActualCreation(t *tes assert.Equal(t, runtime.Spec.Shoot.Provider.Type, "gcp") assert.Equal(t, runtime.Spec.Shoot.Region, "asia-south1") assert.Equal(t, string(runtime.Spec.Shoot.Purpose), "production") - assert.Len(t, runtime.Spec.Shoot.Provider.Workers, 1) - assert.Len(t, runtime.Spec.Shoot.Provider.Workers[0].Zones, 1) //TODO assert zone as an element from set + assertWorkers(t, runtime.Spec.Shoot.Provider.Workers, "n2-standard-2", 20, 3, 1, 0, 1, []string{"asia-south1-a", "asia-south1-b", "asia-south1-c"}) _, err = memoryStorage.Instances().GetByID(preOperation.InstanceID) assert.NoError(t, err) @@ -696,8 +695,7 @@ func TestCreateRuntimeResourceStep_Defaults_GCP_MultiZone_ActualCreation(t *test assert.Equal(t, runtime.Spec.Shoot.Provider.Type, "gcp") assert.Equal(t, runtime.Spec.Shoot.Region, "asia-south1") assert.Equal(t, string(runtime.Spec.Shoot.Purpose), "production") - assert.Len(t, runtime.Spec.Shoot.Provider.Workers, 1) - assert.Len(t, runtime.Spec.Shoot.Provider.Workers[0].Zones, 3) //TODO assert zones + assertWorkers(t, runtime.Spec.Shoot.Provider.Workers, "n2-standard-2", 20, 3, 3, 0, 3, []string{"asia-south1-a", "asia-south1-b", "asia-south1-c"}) _, err = memoryStorage.Instances().GetByID(preOperation.InstanceID) assert.NoError(t, err) From 8c9556882ba6c6fdd4c325976d663534704d3ee6 Mon Sep 17 00:00:00 2001 From: Pieszka Date: Thu, 25 Jul 2024 14:33:54 +0200 Subject: [PATCH 7/8] maxsurge corrected --- .../process/provisioning/create_runtime_resource_step_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/process/provisioning/create_runtime_resource_step_test.go b/internal/process/provisioning/create_runtime_resource_step_test.go index f4cddc729c..2130520bd8 100644 --- a/internal/process/provisioning/create_runtime_resource_step_test.go +++ b/internal/process/provisioning/create_runtime_resource_step_test.go @@ -322,7 +322,7 @@ func TestCreateRuntimeResourceStep_Defaults_AWS_SingleZone_ActualCreation(t *tes assert.Equal(t, runtime.Spec.Shoot.Region, "eu-west-2") assert.Equal(t, string(runtime.Spec.Shoot.Purpose), "production") assert.Equal(t, runtime.Spec.Shoot.SecretBindingName, SecretBindingName) - assertWorkers(t, runtime.Spec.Shoot.Provider.Workers, "m6i.large", 20, 3, 3, 0, 1, []string{"eu-west-2a", "eu-west-2b", "eu-west-2c"}) + assertWorkers(t, runtime.Spec.Shoot.Provider.Workers, "m6i.large", 20, 3, 1, 0, 1, []string{"eu-west-2a", "eu-west-2b", "eu-west-2c"}) _, err = memoryStorage.Instances().GetByID(preOperation.InstanceID) assert.NoError(t, err) From e1f1cb22010eaae375fd4e5dab684ca310612860 Mon Sep 17 00:00:00 2001 From: Pieszka Date: Thu, 25 Jul 2024 14:43:10 +0200 Subject: [PATCH 8/8] go imports --- .../process/provisioning/create_runtime_resource_step_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/process/provisioning/create_runtime_resource_step_test.go b/internal/process/provisioning/create_runtime_resource_step_test.go index 2130520bd8..4f79e896b4 100644 --- a/internal/process/provisioning/create_runtime_resource_step_test.go +++ b/internal/process/provisioning/create_runtime_resource_step_test.go @@ -3,11 +3,12 @@ package provisioning import ( "context" "fmt" - gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1" "os" "strings" "testing" + gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1" + "github.com/kyma-project/kyma-environment-broker/internal/ptr" imv1 "github.com/kyma-project/infrastructure-manager/api/v1"