Skip to content

Commit

Permalink
Remove Kyma version configuration for a given global account or subac…
Browse files Browse the repository at this point in the history
…count
  • Loading branch information
KsaweryZietara committed Jun 18, 2024
1 parent 2ba8ae6 commit aa812ff
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 437 deletions.
5 changes: 2 additions & 3 deletions cmd/broker/broker_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ func NewBrokerSuiteTestWithConfig(t *testing.T, cfg *Config, version ...string)
provisionerClient := provisioner.NewFakeClientWithGardener(gardenerClient, "kcp-system")
eventBroker := event.NewPubSub(logs)

accountVersionMapping := runtimeversion.NewAccountVersionMapping(ctx, cli, cfg.VersionConfig.Namespace, cfg.VersionConfig.Name, logs)
runtimeVerConfigurator := runtimeversion.NewRuntimeVersionConfigurator(cfg.KymaVersion, accountVersionMapping, nil)
runtimeVerConfigurator := runtimeversion.NewRuntimeVersionConfigurator(cfg.KymaVersion, nil)

avsDel, externalEvalCreator, internalEvalAssistant, externalEvalAssistant := createFakeAvsDelegator(t, db, cfg)

Expand All @@ -221,7 +220,7 @@ func NewBrokerSuiteTestWithConfig(t *testing.T, cfg *Config, version ...string)
provisionManager.SpeedUp(10000)

updateManager := process.NewStagedManager(db.Operations(), eventBroker, time.Hour, cfg.Update, logs)
rvc := runtimeversion.NewRuntimeVersionConfigurator(cfg.KymaVersion, nil, db.RuntimeStates())
rvc := runtimeversion.NewRuntimeVersionConfigurator(cfg.KymaVersion, db.RuntimeStates())
updateQueue := NewUpdateProcessingQueue(context.Background(), updateManager, 1, db, inputFactory, provisionerClient,
eventBroker, rvc, db.RuntimeStates(), *cfg, k8sClientProvider, cli, logs)
updateQueue.SpeedUp(10000)
Expand Down
8 changes: 1 addition & 7 deletions cmd/broker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@ type Config struct {

Notification notification.Config

VersionConfig struct {
Namespace string
Name string
}

KymaDashboardConfig dashboard.Config

OrchestrationConfig orchestration.Config
Expand Down Expand Up @@ -354,8 +349,7 @@ func main() {
_ = metricsv2.Register(ctx, eventBroker, db.Operations(), db.Instances(), cfg.MetricsV2, logs)

// define steps
accountVersionMapping := runtimeversion.NewAccountVersionMapping(ctx, cli, cfg.VersionConfig.Namespace, cfg.VersionConfig.Name, logs)
runtimeVerConfigurator := runtimeversion.NewRuntimeVersionConfigurator(cfg.KymaVersion, accountVersionMapping, db.RuntimeStates())
runtimeVerConfigurator := runtimeversion.NewRuntimeVersionConfigurator(cfg.KymaVersion, db.RuntimeStates())

// run queues
provisionManager := process.NewStagedManager(db.Operations(), eventBroker, cfg.OperationTimeout, cfg.Provisioning, logs.WithField("provisioning", "manager"))
Expand Down
31 changes: 14 additions & 17 deletions cmd/broker/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,18 @@ import (
)

const (
globalAccountLabel = "account"
subAccountLabel = "subaccount"
runtimeIDAnnotation = "kcp.provisioner.kyma-project.io/runtime-id"
defaultNamespace = "kcp-system"
defaultKymaVer = "2.4.0"
kymaVersionsConfigName = "kyma-versions"
defaultRegion = "cf-eu10"
globalAccountID = "dummy-ga-id"
dashboardURL = "http://console.garden-dummy.kyma.io"
operationID = "provisioning-op-id"
deprovisioningOpID = "deprovisioning-op-id"
reDeprovisioningOpID = "re-deprovisioning-op-id"
instanceID = "instance-id"
dbSecretKey = "1234567890123456"
globalAccountLabel = "account"
subAccountLabel = "subaccount"
runtimeIDAnnotation = "kcp.provisioner.kyma-project.io/runtime-id"
defaultKymaVer = "2.4.0"
defaultRegion = "cf-eu10"
globalAccountID = "dummy-ga-id"
dashboardURL = "http://console.garden-dummy.kyma.io"
operationID = "provisioning-op-id"
deprovisioningOpID = "deprovisioning-op-id"
reDeprovisioningOpID = "re-deprovisioning-op-id"
instanceID = "instance-id"
dbSecretKey = "1234567890123456"

pollingInterval = 3 * time.Millisecond
)
Expand Down Expand Up @@ -156,7 +154,7 @@ func NewOrchestrationSuite(t *testing.T, additionalKymaVersions []string) *Orche

eventBroker := event.NewPubSub(logs)

runtimeVerConfigurator := runtimeversion.NewRuntimeVersionConfigurator(kymaVer, runtimeversion.NewAccountVersionMapping(ctx, cli, defaultNamespace, kymaVersionsConfigName, logs), nil)
runtimeVerConfigurator := runtimeversion.NewRuntimeVersionConfigurator(kymaVer, nil)

avsClient, _ := avs.NewClient(ctx, avs.Config{}, logs)
avsDel := avs.NewDelegator(avsClient, avs.Config{}, db.Operations())
Expand Down Expand Up @@ -614,8 +612,7 @@ func NewProvisioningSuite(t *testing.T, multiZoneCluster bool, controlPlaneFailu
internalEvalAssistant := avs.NewInternalEvalAssistant(cfg.Avs)
externalEvalCreator := provisioning.NewExternalEvalCreator(avsDel, cfg.Avs.Disabled, externalEvalAssistant)

accountVersionMapping := runtimeversion.NewAccountVersionMapping(ctx, cli, cfg.VersionConfig.Namespace, cfg.VersionConfig.Name, logs)
runtimeVerConfigurator := runtimeversion.NewRuntimeVersionConfigurator(cfg.KymaVersion, accountVersionMapping, nil)
runtimeVerConfigurator := runtimeversion.NewRuntimeVersionConfigurator(cfg.KymaVersion, nil)

edpClient := edp.NewFakeClient()

Expand Down
9 changes: 2 additions & 7 deletions internal/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ type AvsLifecycleData struct {
type RuntimeVersionOrigin string

const (
Parameters RuntimeVersionOrigin = "parameters"
Defaults RuntimeVersionOrigin = "defaults"
AccountMapping RuntimeVersionOrigin = "account-mapping"
Parameters RuntimeVersionOrigin = "parameters"
Defaults RuntimeVersionOrigin = "defaults"
)

// RuntimeVersionData describes the Kyma Version used for the cluster
Expand Down Expand Up @@ -102,10 +101,6 @@ func DetermineMajorVersion(version string) int {
return majorVerNum
}

func NewRuntimeVersionFromAccountMapping(version string, majorVersion int) *RuntimeVersionData {
return &RuntimeVersionData{Version: version, Origin: AccountMapping, MajorVersion: majorVersion}
}

type EventHub struct {
Deleted bool `json:"event_hub_deleted"`
}
Expand Down
19 changes: 0 additions & 19 deletions internal/process/input/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,6 @@ func TestInputBuilderFactory_ForPlan(t *testing.T) {
assert.NotNil(t, result.upgradeRuntimeInput)
})

t.Run("should build RuntimeInput with GA version Kyma components and UpgradeRuntimeInput", func(t *testing.T) {
// given
configProvider := mockConfigProvider()

ibf, err := NewInputBuilderFactory(configProvider, Config{}, "1.10", fixTrialRegionMapping(), fixTrialProviders(), fixture.FixOIDCConfigDTO(), false)
assert.NoError(t, err)
pp := fixProvisioningParameters(broker.GCPPlanID)

// when
input, err := ibf.CreateUpgradeInput(pp, internal.RuntimeVersionData{Version: "1.1.0", Origin: internal.AccountMapping})

// Then
assert.NoError(t, err)
require.IsType(t, &RuntimeInput{}, input)

result := input.(*RuntimeInput)
assert.NotNil(t, result.upgradeRuntimeInput)
})

t.Run("should build RuntimeInput with set version Kyma components", func(t *testing.T) {
// given
configProvider := mockConfigProvider()
Expand Down
62 changes: 0 additions & 62 deletions internal/runtimeversion/account_mapping.go

This file was deleted.

79 changes: 0 additions & 79 deletions internal/runtimeversion/account_mapping_test.go

This file was deleted.

58 changes: 3 additions & 55 deletions internal/runtimeversion/runtimeversion.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package runtimeversion

import (
"fmt"
"strconv"
"strings"

"github.com/kyma-project/kyma-environment-broker/internal/storage/dberr"

"github.com/kyma-project/kyma-environment-broker/internal"
Expand All @@ -13,18 +9,16 @@ import (

type RuntimeVersionConfigurator struct {
defaultVersion string
accountMapping *AccountVersionMapping
runtimeStateDB storage.RuntimeStates
}

func NewRuntimeVersionConfigurator(defaultVersion string, accountMapping *AccountVersionMapping, runtimeStates storage.RuntimeStates) *RuntimeVersionConfigurator {
func NewRuntimeVersionConfigurator(defaultVersion string, runtimeStates storage.RuntimeStates) *RuntimeVersionConfigurator {
if defaultVersion == "" {
panic("Default version not provided")
}

return &RuntimeVersionConfigurator{
defaultVersion: defaultVersion,
accountMapping: accountMapping,
runtimeStateDB: runtimeStates,
}
}
Expand All @@ -41,56 +35,10 @@ func (rvc *RuntimeVersionConfigurator) ForUpdating(op internal.Operation) (*inte
return internal.NewRuntimeVersionFromDefaults(r.GetKymaVersion()), nil
}

func (rvc *RuntimeVersionConfigurator) ForProvisioning(op internal.Operation) (*internal.RuntimeVersionData, error) {

pp := op.ProvisioningParameters

version, found, err := rvc.accountMapping.Get(pp.ErsContext.GlobalAccountID, pp.ErsContext.SubAccountID)
if err != nil {
return nil, err
}
if found {
majorVer, err := determineMajorVersion(version, rvc.defaultVersion)
if err != nil {
return nil, fmt.Errorf("while determining Kyma's major version: %w", err)
}
return internal.NewRuntimeVersionFromAccountMapping(version, majorVer), nil
}
func (rvc *RuntimeVersionConfigurator) ForProvisioning(internal.Operation) (*internal.RuntimeVersionData, error) {
return internal.NewRuntimeVersionFromDefaults(rvc.defaultVersion), nil
}

func determineMajorVersion(version, defaultVersion string) (int, error) {
if isCustomVersion(version) {
return extractMajorVersionNumberFromVersionString(defaultVersion)
}
return extractMajorVersionNumberFromVersionString(version)
}

func isCustomVersion(version string) bool {
return strings.HasPrefix(version, "PR-") || strings.HasPrefix(version, "main-")
}

func extractMajorVersionNumberFromVersionString(version string) (int, error) {
splitVer := strings.Split(version, ".")
majorVerNum, err := strconv.Atoi(splitVer[0])
if err != nil {
return 0, fmt.Errorf("cannot convert major version (version: \"%s\") to int", version)
}
return majorVerNum, nil
}

func (rvc *RuntimeVersionConfigurator) ForUpgrade(op internal.UpgradeKymaOperation) (*internal.RuntimeVersionData, error) {
version, found, err := rvc.accountMapping.Get(op.GlobalAccountID, op.RuntimeOperation.SubAccountID)
if err != nil {
return nil, err
}
if found {
majorVer, err := determineMajorVersion(version, rvc.defaultVersion)
if err != nil {
return nil, fmt.Errorf("while determining Kyma's major version: %w", err)
}
return internal.NewRuntimeVersionFromAccountMapping(version, majorVer), nil
}

func (rvc *RuntimeVersionConfigurator) ForUpgrade(internal.UpgradeKymaOperation) (*internal.RuntimeVersionData, error) {
return internal.NewRuntimeVersionFromDefaults(rvc.defaultVersion), nil
}
Loading

0 comments on commit aa812ff

Please sign in to comment.