Skip to content

Commit

Permalink
KIM Integration - managed by provisioner label not set for KIM only (#…
Browse files Browse the repository at this point in the history
…1040)

* setting label for kim only plan regardless of viewonly setting

* volume size corrected

* test added
  • Loading branch information
jaroslaw-pieszka authored Aug 14, 2024
1 parent f0951c9 commit 9034778
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
7 changes: 4 additions & 3 deletions internal/process/provisioning/create_runtime_resource_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provisioning
import (
"context"
"fmt"
"strconv"
"time"

"github.com/kyma-project/kyma-environment-broker/internal/ptr"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit 9034778

Please sign in to comment.