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 - shoot name and networking for basic plans #951

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion internal/process/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Config struct {
MachineImage string `envconfig:"optional"`
MachineImageVersion string `envconfig:"optional"`
TrialNodesNumber int `envconfig:"optional"`
DefaultTrialProvider internal.CloudProvider `envconfig:"default=Azure"` // could be: Azure, AWS, GCP, SapConvergedCloud, unknown
DefaultTrialProvider internal.CloudProvider `envconfig:"default=Azure"`
AutoUpdateKubernetesVersion bool `envconfig:"default=false"`
AutoUpdateMachineImageVersion bool `envconfig:"default=false"`
MultiZoneCluster bool `envconfig:"default=false"`
Expand Down
55 changes: 46 additions & 9 deletions internal/process/provisioning/create_runtime_resource_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"time"

"github.com/kyma-project/kyma-environment-broker/internal/networking"

"sigs.k8s.io/controller-runtime/pkg/client"

gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1"
Expand Down Expand Up @@ -115,11 +117,13 @@ func (s *CreateRuntimeResourceStep) createRuntimeResourceObject(operation intern

runtime.Spec.Shoot.Provider = providerObj
runtime.Spec.Shoot.Region = values.Region
runtime.Spec.Shoot.Name = operation.ShootName
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.Shoot.ControlPlane.HighAvailability = s.createHighAvailabilityConfiguration()
runtime.Spec.Security = s.createSecurityConfiguration(operation)
runtime.Spec.Shoot.Networking = s.createNetworkingConfiguration(operation)
return &runtime, nil
}

Expand Down Expand Up @@ -147,14 +151,6 @@ func (s *CreateRuntimeResourceStep) createSecurityConfiguration(operation intern
return security
}

func RuntimeToYaml(runtime *imv1.Runtime) (string, error) {
result, err := yaml.Marshal(runtime)
if err != nil {
return "", err
}
return string(result), nil
}

func (s *CreateRuntimeResourceStep) createShootProvider(operation *internal.Operation, values provider.Values) (imv1.Provider, error) {

maxSurge := intstr.FromInt32(int32(DefaultIfParamNotSet(values.ZonesCount, operation.ProvisioningParameters.Parameters.MaxSurge)))
Expand Down Expand Up @@ -248,9 +244,50 @@ func (s *CreateRuntimeResourceStep) providerValues(operation *internal.Operation
return p.Provide(), 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
if networkingParams == nil {
networkingParams = &internal.NetworkingDTO{}
}

nodes := networkingParams.NodesCidr
if nodes == "" {
nodes = networking.DefaultNodesCIDR
}

return imv1.Networking{
Pods: DefaultIfParamNotSet(networking.DefaultPodsCIDR, networkingParams.PodsCidr),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get you question.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question removed.

Services: DefaultIfParamNotSet(networking.DefaultServicesCIDR, networkingParams.ServicesCidr),
Nodes: nodes,
}
}

func DefaultIfParamNotSet[T interface{}](d T, param *T) T {
if param == nil {
return d
}
return *param
}

func RuntimeToYaml(runtime *imv1.Runtime) (string, error) {
result, err := yaml.Marshal(runtime)
if err != nil {
return "", err
}
return string(result), nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import (
"context"
"fmt"
"os"
"reflect"
"strings"
"testing"

"github.com/kyma-project/kyma-environment-broker/internal/networking"

gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1"

"github.com/kyma-project/kyma-environment-broker/internal/ptr"
Expand Down Expand Up @@ -34,6 +37,11 @@ import (
const SecretBindingName = "gardener-secret"

var runtimeAdministrators = []string{"admin1@test.com", "admin2@test.com"}
var defaultNetworking = imv1.Networking{
Nodes: networking.DefaultNodesCIDR,
Pods: networking.DefaultPodsCIDR,
Services: networking.DefaultServicesCIDR,
}

func TestCreateRuntimeResourceStep_Defaults_Azure_MultiZone_YamlOnly(t *testing.T) {
// given
Expand Down Expand Up @@ -294,9 +302,9 @@ func TestCreateRuntimeResourceStep_Defaults_AWS_SingleZone_ActualCreation(t *tes
assert.NoError(t, err)

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

cli := getClientForTests(t)
inputConfig := input.Config{MultiZoneCluster: false}
step := NewCreateRuntimeResourceStep(memoryStorage.Operations(), memoryStorage.Instances(), cli, kimConfig, inputConfig, nil, false)

// when
Expand All @@ -313,17 +321,19 @@ func TestCreateRuntimeResourceStep_Defaults_AWS_SingleZone_ActualCreation(t *tes
Name: preOperation.RuntimeID,
}, &runtime)
assert.NoError(t, err)
assert.Equal(t, preOperation.RuntimeID, runtime.Name)
assert.Equal(t, runtime.Name, preOperation.RuntimeID)
assert.Equal(t, "runtime-58f8c703-1756-48ab-9299-a847974d1fee", runtime.Labels["operator.kyma-project.io/kyma-name"])

assertLabels(t, preOperation, runtime)
assertSecurity(t, runtime)

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)
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(preOperation.InstanceID)
assert.NoError(t, err)
Expand Down Expand Up @@ -366,15 +376,15 @@ func TestCreateRuntimeResourceStep_Defaults_AWS_MultiZone_ActualCreation(t *test
Name: preOperation.RuntimeID,
}, &runtime)
assert.NoError(t, err)
assert.Equal(t, preOperation.RuntimeID, runtime.Name)
assert.Equal(t, runtime.Name, preOperation.RuntimeID)
assert.Equal(t, "runtime-58f8c703-1756-48ab-9299-a847974d1fee", runtime.Labels["operator.kyma-project.io/kyma-name"])

assertLabels(t, preOperation, runtime)
assertSecurity(t, runtime)

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

_, err = memoryStorage.Instances().GetByID(preOperation.InstanceID)
Expand Down Expand Up @@ -424,9 +434,9 @@ func TestCreateRuntimeResourceStep_Defaults_Preview_SingleZone_ActualCreation(t
assertLabels(t, preOperation, runtime)
assertSecurity(t, runtime)

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, "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, 1, 0, 1, []string{"eu-west-2a", "eu-west-2b", "eu-west-2c"})

_, err = memoryStorage.Instances().GetByID(preOperation.InstanceID)
Expand Down Expand Up @@ -477,9 +487,9 @@ func TestCreateRuntimeResourceStep_Defaults_Preview_MultiZone_ActualCreation(t *
assertLabels(t, preOperation, runtime)
assertSecurity(t, runtime)

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

_, err = memoryStorage.Instances().GetByID(preOperation.InstanceID)
Expand Down Expand Up @@ -530,9 +540,9 @@ func TestCreateRuntimeResourceStep_Defaults_Azure_SingleZone_ActualCreation(t *t
assertLabels(t, preOperation, runtime)
assertSecurity(t, runtime)

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.Equal(t, "azure", runtime.Spec.Shoot.Provider.Type)
assert.Equal(t, "westeurope", runtime.Spec.Shoot.Region)
assert.Equal(t, "production", string(runtime.Spec.Shoot.Purpose))

assertWorkers(t, runtime.Spec.Shoot.Provider.Workers, "Standard_D2s_v5", 20, 3, 1, 0, 1, []string{"1", "2", "3"})

Expand Down Expand Up @@ -585,9 +595,10 @@ func TestCreateRuntimeResourceStep_Defaults_Azure_MultiZone_ActualCreation(t *te
assertLabels(t, preOperation, runtime)
assertSecurity(t, runtime)

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.Equal(t, "azure", runtime.Spec.Shoot.Provider.Type)
assert.Equal(t, "westeurope", runtime.Spec.Shoot.Region)
assert.Equal(t, "production", string(runtime.Spec.Shoot.Purpose))

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)
Expand Down Expand Up @@ -639,9 +650,10 @@ func TestCreateRuntimeResourceStep_Defaults_GCP_SingleZone_ActualCreation(t *tes
assertLabels(t, preOperation, runtime)
assertSecurity(t, runtime)

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.Equal(t, "gcp", runtime.Spec.Shoot.Provider.Type)
assert.Equal(t, "asia-south1", runtime.Spec.Shoot.Region)
assert.Equal(t, "production", string(runtime.Spec.Shoot.Purpose))

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)
Expand Down Expand Up @@ -693,9 +705,9 @@ func TestCreateRuntimeResourceStep_Defaults_GCP_MultiZone_ActualCreation(t *test
assertLabels(t, preOperation, runtime)
assertSecurity(t, runtime)

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.Equal(t, "gcp", runtime.Spec.Shoot.Provider.Type)
assert.Equal(t, "asia-south1", runtime.Spec.Shoot.Region)
assert.Equal(t, "production", string(runtime.Spec.Shoot.Purpose))
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)
Expand Down Expand Up @@ -732,6 +744,14 @@ func assertWorkers(t *testing.T, workers []gardener.Worker, machine string, maxi
assert.Equal(t, workers[0].Minimum, int32(minimum))
}

func assertNetworking(t *testing.T, expected imv1.Networking, actual imv1.Networking) {
assert.True(t, reflect.DeepEqual(expected, actual))
}

func assertDefaultNetworking(t *testing.T, actual imv1.Networking) {
assertNetworking(t, defaultNetworking, actual)
}

// test fixtures

func fixOperationForCreateRuntimeResource(instanceID string, provisioningParameters internal.ProvisioningParameters) internal.Operation {
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func (p *AWSInputProvider) Provide() Values {
ProviderType: "aws",
DefaultMachineType: DefaultAWSMachineType,
Region: region,
Purpose: PurposeProduction,
Purpose: PurposeProduction, //TODO - default value is define per landscape in mgmt plane config
}
}

func (p *AWSInputProvider) zonesCount() int { //TODO - reconsider this is called twice per provisioning
func (p *AWSInputProvider) zonesCount() int { //TODO - this is called twice per provisioning
zonesCount := 1
if p.MultiZone {
zonesCount = DefaultAWSMultiZoneCount
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Values struct {
ProviderType string
DefaultMachineType string
Region string
Purpose string
Purpose string //TODO default per landscape in configuration

// todo: add other plan specific values
}
Loading