Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KIM integration - assertions for workers #950

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package provisioning
import (
"context"
"fmt"
gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1"
"os"
"reflect"
"strings"
"testing"

Expand All @@ -30,6 +30,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) {
Expand Down Expand Up @@ -319,8 +321,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.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
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"})

_, err = memoryStorage.Instances().GetByID(preOperation.InstanceID)
assert.NoError(t, err)
Expand Down Expand Up @@ -372,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)
Expand Down Expand Up @@ -425,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)
Expand Down Expand Up @@ -479,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)
Expand Down Expand Up @@ -533,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)
Expand Down Expand Up @@ -588,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)
Expand Down Expand Up @@ -643,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)
Expand Down Expand Up @@ -698,18 +695,17 @@ 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)

}

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

Expand All @@ -724,6 +720,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, 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.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

func fixOperationForCreateRuntimeResource(instanceID string, provisioningParameters internal.ProvisioningParameters) internal.Operation {
operation := fixture.FixProvisioningOperationWithProvisioningParameters("op-id", instanceID, provisioningParameters)
operation.KymaTemplate = `
Expand Down Expand Up @@ -794,5 +803,6 @@ func fixProvisioningParametersDTOWithRegion(region string) internal.Provisioning
Name: "cluster-test",
Region: ptr.String(region),
RuntimeAdministrators: runtimeAdministrators,
TargetSecret: ptr.String(SecretBindingName),
}
}
Loading