Skip to content

Commit

Permalink
Merge branch 'main' into update-sm-credentials-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jaroslaw-pieszka authored Jan 30, 2025
2 parents b8aceca + 42fb296 commit 23589c1
Show file tree
Hide file tree
Showing 15 changed files with 389 additions and 46 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)
})
}
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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
Expand All @@ -24,7 +24,7 @@ require (
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
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ github.com/kyma-project/brokerapi/v8 v8.2.4-0.20241017055904-60727c4de1c4 h1:vXE
github.com/kyma-project/brokerapi/v8 v8.2.4-0.20241017055904-60727c4de1c4/go.mod h1:MGZMnpFeMjZ/JVEYDv92uJMf8QMohfOFaSgPwzEQ5/c=
github.com/kyma-project/control-plane/components/provisioner v0.0.0-20240925074719-868d3d02df59 h1:PAynE3RawB3Kvg9Q430hNB9FoBMViTxfy7BzC/o335U=
github.com/kyma-project/control-plane/components/provisioner v0.0.0-20240925074719-868d3d02df59/go.mod h1:xgWRmQjXFgIBX+TAvHr8iQIpjFhamm4HOpHPfGmnz2Q=
github.com/kyma-project/infrastructure-manager v1.20.0 h1:GYwqA7oEvOL7kb4/wfbW0n463/eh6Qr0xe9iteSpDcc=
github.com/kyma-project/infrastructure-manager v1.20.0/go.mod h1:PqYZ2GsFQz4SUvRYuQesItBPCHMg5BLi3SkKEkceWyw=
github.com/kyma-project/infrastructure-manager v0.0.0-20250128154549-67d41ee7791a h1:RAbKl9hZ1HpV6wEwT4fI6GO6NCZWJkMZHGsyFPckk6Y=
github.com/kyma-project/infrastructure-manager v0.0.0-20250128154549-67d41ee7791a/go.mod h1:8eSCG1g+C1CjSFJELkzsPODBpDijaHS1LCjguiHpJYc=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
Expand Down Expand Up @@ -283,8 +283,8 @@ github.com/onrik/logrus v0.11.0 h1:pu+BCaWL36t0yQaj/2UHK2erf88dwssAKOT51mxPUVs=
github.com/onrik/logrus v0.11.0/go.mod h1:fO2vlZwIdti6PidD3gV5YKt9Lq5ptpnP293RAe1ITwk=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/ginkgo/v2 v2.22.1 h1:QW7tbJAUDyVDVOM5dFa7qaybo+CRfR7bemlQUN6Z8aM=
github.com/onsi/ginkgo/v2 v2.22.1/go.mod h1:S6aTpoRsSq2cZOd+pssHAlKW/Q/jZt6cPrPlnj4a1xM=
github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU=
github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk=
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
Expand Down
2 changes: 1 addition & 1 deletion internal/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type UpdatingParametersDTO struct {
OIDC *pkg.OIDCConfigDTO `json:"oidc,omitempty"`
RuntimeAdministrators []string `json:"administrators,omitempty"`
MachineType *string `json:"machineType,omitempty"`
AdditionalWorkerNodePools []pkg.AdditionalWorkerNodePool `json:"additionalWorkerNodePools,omitempty"`
AdditionalWorkerNodePools []pkg.AdditionalWorkerNodePool `json:"additionalWorkerNodePools"`
}

func (u UpdatingParametersDTO) UpdateAutoScaler(p *pkg.ProvisioningParametersDTO) bool {
Expand Down
Loading

0 comments on commit 23589c1

Please sign in to comment.