Skip to content

Commit

Permalink
Merge branch 'main' into features/refactored-hap-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ralikio authored Jan 30, 2025
2 parents 4a8e45d + 42fb296 commit f13d87c
Show file tree
Hide file tree
Showing 15 changed files with 406 additions and 64 deletions.
17 changes: 17 additions & 0 deletions cmd/broker/broker_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"testing"
"time"

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

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

"github.com/kyma-project/kyma-environment-broker/internal/storage/dberr"
Expand Down Expand Up @@ -1276,3 +1278,18 @@ func createResource(t *testing.T, gvk schema.GroupVersionKind, k8sClient client.
err := k8sClient.Create(context.TODO(), object)
assert.NoError(t, err)
}

func (s *BrokerSuiteTest) assertAdditionalWorkerIsCreated(t *testing.T, provider imv1.Provider, name, machineType string, autoScalerMin, autoScalerMax, zonesNumer int) {
var worker *v1beta1.Worker
for _, additionalWorker := range *provider.AdditionalWorkers {
if additionalWorker.Name == name {
worker = &additionalWorker
}
}
require.NotNil(t, worker)
assert.Equal(t, machineType, worker.Machine.Type)
assert.Equal(t, int32(autoScalerMin), worker.Minimum)
assert.Equal(t, int32(autoScalerMax), worker.Maximum)
assert.Equal(t, zonesNumer, worker.MaxSurge.IntValue())
assert.Len(t, worker.Zones, zonesNumer)
}
54 changes: 54 additions & 0 deletions cmd/broker/provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1877,3 +1877,57 @@ func TestProvisioning_Modules(t *testing.T) {
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
})
}

func TestProvisioningWithAdditionalWorkerNodePools(t *testing.T) {
//given
cfg := fixConfig()
cfg.Broker.KimConfig.Enabled = true
cfg.Broker.KimConfig.Plans = []string{"preview"}
cfg.Broker.KimConfig.KimOnlyPlans = []string{"preview"}

suite := NewBrokerSuiteTestWithConfig(t, cfg)
defer suite.TearDown()
iid := uuid.New().String()

// when
resp := suite.CallAPI("PUT", fmt.Sprintf("oauth/cf-eu21/v2/service_instances/%s?accepts_incomplete=true", iid),
`{
"service_id": "47c9dcbf-ff30-448e-ab36-d3bad66ba281",
"plan_id": "5cb3d976-b85c-42ea-a636-79cadda109a9",
"context": {
"globalaccount_id": "g-account-id",
"subaccount_id": "sub-id",
"user_id": "[email protected]"
},
"parameters": {
"name": "testing-cluster",
"region": "eu-central-1",
"additionalWorkerNodePools": [
{
"name": "name-1",
"machineType": "m6i.large",
"haZones": true,
"autoScalerMin": 3,
"autoScalerMax": 20
},
{
"name": "name-2",
"machineType": "m5.large",
"haZones": false,
"autoScalerMin": 1,
"autoScalerMax": 1
}
]
}
}`)

opID := suite.DecodeOperationID(resp)
suite.processKIMOnlyProvisioningByOperationID(opID)

// then
suite.WaitForOperationState(opID, domain.Succeeded)
runtime := suite.GetRuntimeResourceByInstanceID(iid)
assert.Len(t, *runtime.Spec.Shoot.Provider.AdditionalWorkers, 2)
suite.assertAdditionalWorkerIsCreated(t, runtime.Spec.Shoot.Provider, "name-1", "m6i.large", 3, 20, 3)
suite.assertAdditionalWorkerIsCreated(t, runtime.Spec.Shoot.Provider, "name-2", "m5.large", 1, 1, 1)
}
9 changes: 8 additions & 1 deletion cmd/broker/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"log/slog"

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

"github.com/kyma-project/kyma-environment-broker/internal/process/steps"

"github.com/kyma-project/kyma-environment-broker/internal/event"
Expand All @@ -19,6 +21,11 @@ func NewUpdateProcessingQueue(ctx context.Context, manager *process.StagedManage
provisionerClient provisioner.Client, publisher event.Publisher,
cfg Config, k8sClientProvider K8sClientProvider, cli client.Client, logs *slog.Logger) *process.Queue {

trialRegionsMapping, err := provider.ReadPlatformRegionMappingFromFile(cfg.TrialRegionMappingFilePath)
if err != nil {
fatalOnError(err, logs)
}

manager.DefineStages([]string{"cluster", "btp-operator", "btp-operator-check", "check", "runtime_resource", "check_runtime_resource"})
updateSteps := []struct {
disabled bool
Expand All @@ -42,7 +49,7 @@ func NewUpdateProcessingQueue(ctx context.Context, manager *process.StagedManage
},
{
stage: "runtime_resource",
step: update.NewUpdateRuntimeStep(db.Operations(), cli, cfg.UpdateRuntimeResourceDelay),
step: update.NewUpdateRuntimeStep(db.Operations(), cli, cfg.UpdateRuntimeResourceDelay, cfg.Provisioner, cfg.Broker.UseSmallerMachineTypes, trialRegionsMapping),
condition: update.SkipForOwnClusterPlan,
},
{
Expand Down
194 changes: 194 additions & 0 deletions cmd/broker/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2526,3 +2526,197 @@ func TestUpdateErsContextAndParamsForExpiredInstance(t *testing.T) {
}`)
assert.Equal(t, http.StatusBadRequest, response.StatusCode)
}

func TestUpdateAdditionalWorkerNodePools(t *testing.T) {
t.Run("should add additional worker node pools", func(t *testing.T) {
// given
suite := NewBrokerSuiteTest(t)
defer suite.TearDown()
iid := uuid.New().String()

resp := suite.CallAPI("PUT", fmt.Sprintf("oauth/cf-eu10/v2/service_instances/%s?accepts_incomplete=true&plan_id=7d55d31d-35ae-4438-bf13-6ffdfa107d9f&service_id=47c9dcbf-ff30-448e-ab36-d3bad66ba281", iid),
`{
"service_id": "47c9dcbf-ff30-448e-ab36-d3bad66ba281",
"plan_id": "5cb3d976-b85c-42ea-a636-79cadda109a9",
"context": {
"globalaccount_id": "g-account-id",
"subaccount_id": "sub-id",
"user_id": "[email protected]"
},
"parameters": {
"name": "testing-cluster",
"region": "eu-central-1"
}
}`)
opID := suite.DecodeOperationID(resp)
suite.waitForRuntimeAndMakeItReady(opID)
suite.WaitForOperationState(opID, domain.Succeeded)

// when
// OSB update:
resp = suite.CallAPI("PATCH", fmt.Sprintf("oauth/cf-eu10/v2/service_instances/%s?accepts_incomplete=true", iid),
`{
"service_id": "47c9dcbf-ff30-448e-ab36-d3bad66ba281",
"plan_id": "5cb3d976-b85c-42ea-a636-79cadda109a9",
"context": {
"globalaccount_id": "g-account-id",
"user_id": "[email protected]"
},
"parameters": {
"additionalWorkerNodePools": [
{
"name": "name-1",
"machineType": "m6i.large",
"haZones": true,
"autoScalerMin": 3,
"autoScalerMax": 20
},
{
"name": "name-2",
"machineType": "m5.large",
"haZones": false,
"autoScalerMin": 4,
"autoScalerMax": 21
}
]
}
}`)
assert.Equal(t, http.StatusAccepted, resp.StatusCode)
upgradeOperationID := suite.DecodeOperationID(resp)

// then
suite.WaitForOperationState(upgradeOperationID, domain.Succeeded)
runtime := suite.GetRuntimeResourceByInstanceID(iid)
assert.Len(t, *runtime.Spec.Shoot.Provider.AdditionalWorkers, 2)
suite.assertAdditionalWorkerIsCreated(t, runtime.Spec.Shoot.Provider, "name-1", "m6i.large", 3, 20, 3)
suite.assertAdditionalWorkerIsCreated(t, runtime.Spec.Shoot.Provider, "name-2", "m5.large", 4, 21, 1)
})

t.Run("should replace additional worker node pools", func(t *testing.T) {
// given
suite := NewBrokerSuiteTest(t)
defer suite.TearDown()
iid := uuid.New().String()

resp := suite.CallAPI("PUT", fmt.Sprintf("oauth/cf-eu10/v2/service_instances/%s?accepts_incomplete=true&plan_id=7d55d31d-35ae-4438-bf13-6ffdfa107d9f&service_id=47c9dcbf-ff30-448e-ab36-d3bad66ba281", iid),
`{
"service_id": "47c9dcbf-ff30-448e-ab36-d3bad66ba281",
"plan_id": "5cb3d976-b85c-42ea-a636-79cadda109a9",
"context": {
"globalaccount_id": "g-account-id",
"subaccount_id": "sub-id",
"user_id": "[email protected]"
},
"parameters": {
"name": "testing-cluster",
"region": "eu-central-1",
"additionalWorkerNodePools": [
{
"name": "name-1",
"machineType": "m6i.large",
"haZones": true,
"autoScalerMin": 3,
"autoScalerMax": 20
}
]
}
}`)
opID := suite.DecodeOperationID(resp)
suite.waitForRuntimeAndMakeItReady(opID)
suite.WaitForOperationState(opID, domain.Succeeded)

// when
// OSB update:
resp = suite.CallAPI("PATCH", fmt.Sprintf("oauth/cf-eu10/v2/service_instances/%s?accepts_incomplete=true", iid),
`{
"service_id": "47c9dcbf-ff30-448e-ab36-d3bad66ba281",
"plan_id": "5cb3d976-b85c-42ea-a636-79cadda109a9",
"context": {
"globalaccount_id": "g-account-id",
"user_id": "[email protected]"
},
"parameters": {
"additionalWorkerNodePools": [
{
"name": "name-2",
"machineType": "m5.large",
"haZones": true,
"autoScalerMin": 4,
"autoScalerMax": 21
}
]
}
}`)
assert.Equal(t, http.StatusAccepted, resp.StatusCode)
upgradeOperationID := suite.DecodeOperationID(resp)

// then
suite.WaitForOperationState(upgradeOperationID, domain.Succeeded)
runtime := suite.GetRuntimeResourceByInstanceID(iid)
assert.Len(t, *runtime.Spec.Shoot.Provider.AdditionalWorkers, 1)
suite.assertAdditionalWorkerIsCreated(t, runtime.Spec.Shoot.Provider, "name-2", "m5.large", 4, 21, 3)
})

t.Run("should remove additional worker node pools when list is empty", func(t *testing.T) {
// given
suite := NewBrokerSuiteTest(t)
defer suite.TearDown()
iid := uuid.New().String()

resp := suite.CallAPI("PUT", fmt.Sprintf("oauth/cf-eu10/v2/service_instances/%s?accepts_incomplete=true&plan_id=7d55d31d-35ae-4438-bf13-6ffdfa107d9f&service_id=47c9dcbf-ff30-448e-ab36-d3bad66ba281", iid),
`{
"service_id": "47c9dcbf-ff30-448e-ab36-d3bad66ba281",
"plan_id": "5cb3d976-b85c-42ea-a636-79cadda109a9",
"context": {
"globalaccount_id": "g-account-id",
"subaccount_id": "sub-id",
"user_id": "[email protected]"
},
"parameters": {
"name": "testing-cluster",
"region": "eu-central-1",
"additionalWorkerNodePools": [
{
"name": "name-1",
"machineType": "m6i.large",
"haZones": false,
"autoScalerMin": 3,
"autoScalerMax": 20
},
{
"name": "name-2",
"machineType": "m5.large",
"haZones": false,
"autoScalerMin": 4,
"autoScalerMax": 21
}
]
}
}`)
opID := suite.DecodeOperationID(resp)
suite.waitForRuntimeAndMakeItReady(opID)
suite.WaitForOperationState(opID, domain.Succeeded)

// when
// OSB update:
resp = suite.CallAPI("PATCH", fmt.Sprintf("oauth/cf-eu10/v2/service_instances/%s?accepts_incomplete=true", iid),
`{
"service_id": "47c9dcbf-ff30-448e-ab36-d3bad66ba281",
"plan_id": "5cb3d976-b85c-42ea-a636-79cadda109a9",
"context": {
"globalaccount_id": "g-account-id",
"user_id": "[email protected]"
},
"parameters": {
"additionalWorkerNodePools": []
}
}`)
assert.Equal(t, http.StatusAccepted, resp.StatusCode)
upgradeOperationID := suite.DecodeOperationID(resp)

// then
suite.WaitForOperationState(upgradeOperationID, domain.Succeeded)
runtime := suite.GetRuntimeResourceByInstanceID(iid)
assert.Len(t, *runtime.Spec.Shoot.Provider.AdditionalWorkers, 0)
})
}
22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/kyma-project/kyma-environment-broker

go 1.23.1
go 1.23.5

require (
code.cloudfoundry.org/lager v2.0.0+incompatible
github.com/99designs/gqlgen v0.17.63
github.com/99designs/gqlgen v0.17.64
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible
github.com/Azure/go-autorest/autorest v0.11.29
github.com/Azure/go-autorest/autorest v0.11.30
github.com/Azure/go-autorest/autorest/adal v0.9.24
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/dlmiddlecote/sqlstats v1.0.2
Expand All @@ -16,15 +16,15 @@ require (
github.com/go-co-op/gocron v1.37.0
github.com/gocraft/dbr v0.0.0-20190714181702-8114670a83bd
github.com/golang-jwt/jwt/v4 v4.5.1
github.com/golang-migrate/migrate/v4 v4.18.1
github.com/golang-migrate/migrate/v4 v4.18.2
github.com/google/uuid v1.6.0
github.com/gorilla/handlers v1.5.2
github.com/gorilla/mux v1.8.1
github.com/hashicorp/go-multierror v1.1.1
github.com/kennygrant/sanitize v1.2.4
github.com/kyma-incubator/compass/components/director v0.0.0-20240704074401-a423d6070404
github.com/kyma-project/control-plane/components/provisioner v0.0.0-20240925074719-868d3d02df59
github.com/kyma-project/infrastructure-manager v1.20.0
github.com/kyma-project/infrastructure-manager v0.0.0-20250128154549-67d41ee7791a
github.com/lib/pq v1.10.9
github.com/matryer/is v1.4.1
github.com/pivotal-cf/brokerapi/v8 v8.2.3
Expand All @@ -38,11 +38,11 @@ require (
golang.org/x/time v0.9.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.31.5
k8s.io/apiextensions-apiserver v0.31.5
k8s.io/apimachinery v0.31.5
k8s.io/api v0.32.1
k8s.io/apiextensions-apiserver v0.32.1
k8s.io/apimachinery v0.32.1
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
sigs.k8s.io/controller-runtime v0.19.4
sigs.k8s.io/controller-runtime v0.20.1
sigs.k8s.io/yaml v1.4.0
)

Expand Down Expand Up @@ -109,7 +109,7 @@ require (
github.com/stretchr/objx v0.5.2 // indirect
github.com/tidwall/gjson v1.17.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/vektah/gqlparser/v2 v2.5.21 // indirect
github.com/vektah/gqlparser/v2 v2.5.22 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
Expand All @@ -123,7 +123,7 @@ require (
golang.org/x/sys v0.29.0 // indirect
golang.org/x/term v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/protobuf v1.36.1 // indirect
google.golang.org/protobuf v1.36.4 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
Expand Down
Loading

0 comments on commit f13d87c

Please sign in to comment.