Skip to content

Commit

Permalink
Merge branch 'main' into update_expiration_doc
Browse files Browse the repository at this point in the history
  • Loading branch information
IwonaLanger authored Sep 25, 2024
2 parents e0cc256 + fba6247 commit 2f83e80
Show file tree
Hide file tree
Showing 75 changed files with 1,059 additions and 4,088 deletions.
11 changes: 11 additions & 0 deletions clean-envtest-binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash -x

set -o nounset # treat unset variables as an error and exit immediately.
set -e # exit immediately when a command fails.

DIR=$1

cd "$(dirname "$0")/bin"

find ${DIR} -exec chmod u+w {} \;
rm -rf ${DIR}
34 changes: 5 additions & 29 deletions cmd/broker/broker_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/kyma-project/kyma-environment-broker/common/gardener"
"github.com/kyma-project/kyma-environment-broker/common/orchestration"
"github.com/kyma-project/kyma-environment-broker/internal"
"github.com/kyma-project/kyma-environment-broker/internal/avs"
"github.com/kyma-project/kyma-environment-broker/internal/broker"
kebConfig "github.com/kyma-project/kyma-environment-broker/internal/config"
"github.com/kyma-project/kyma-environment-broker/internal/edp"
Expand All @@ -39,7 +38,6 @@ import (
orchestrate "github.com/kyma-project/kyma-environment-broker/internal/orchestration/handlers"
"github.com/kyma-project/kyma-environment-broker/internal/process"
"github.com/kyma-project/kyma-environment-broker/internal/process/input"
"github.com/kyma-project/kyma-environment-broker/internal/process/provisioning"
"github.com/kyma-project/kyma-environment-broker/internal/process/steps"
"github.com/kyma-project/kyma-environment-broker/internal/process/upgrade_cluster"
"github.com/kyma-project/kyma-environment-broker/internal/provisioner"
Expand Down Expand Up @@ -197,8 +195,6 @@ func NewBrokerSuiteTestWithConfig(t *testing.T, cfg *Config, version ...string)
provisionerClient := provisioner.NewFakeClientWithGardener(gardenerClient, "kcp-system")
eventBroker := event.NewPubSub(logs)

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

edpClient := edp.NewFakeClient()
accountProvider := fixAccountProvider()
require.NoError(t, err)
Expand All @@ -207,7 +203,6 @@ func NewBrokerSuiteTestWithConfig(t *testing.T, cfg *Config, version ...string)
k8sClientProvider := kubeconfig.NewFakeK8sClientProvider(fakeK8sSKRClient)
provisionManager := process.NewStagedManager(db.Operations(), eventBroker, cfg.OperationTimeout, cfg.Provisioning, logs.WithField("provisioning", "manager"))
provisioningQueue := NewProvisioningProcessingQueue(context.Background(), provisionManager, workersAmount, cfg, db, provisionerClient, inputFactory,
avsDel, internalEvalAssistant, externalEvalCreator,
edpClient, accountProvider, k8sClientProvider, cli, defaultOIDCValues(), logs)

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

deprovisionManager := process.NewStagedManager(db.Operations(), eventBroker, time.Hour, cfg.Deprovisioning, logs.WithField("deprovisioning", "manager"))
deprovisioningQueue := NewDeprovisioningProcessingQueue(ctx, workersAmount, deprovisionManager, cfg, db, eventBroker,
provisionerClient, avsDel, internalEvalAssistant, externalEvalAssistant,
edpClient, accountProvider, k8sClientProvider, cli, configProvider, logs,
provisionerClient, edpClient, accountProvider, k8sClientProvider, cli, configProvider, logs,
)
deprovisionManager.SpeedUp(10000)

Expand All @@ -242,20 +236,19 @@ func NewBrokerSuiteTestWithConfig(t *testing.T, cfg *Config, version ...string)
}
ts.poller = &broker.TimerPoller{PollInterval: 3 * time.Millisecond, PollTimeout: 3 * time.Second, Log: ts.t.Log}

ts.CreateAPI(inputFactory, cfg, db, provisioningQueue, deprovisioningQueue, updateQueue, logs)
ts.CreateAPI(inputFactory, cfg, db, provisioningQueue, deprovisioningQueue, updateQueue, logs, k8sClientProvider, gardener.NewFakeClient())

notificationFakeClient := notification.NewFakeClient()
notificationBundleBuilder := notification.NewBundleBuilder(notificationFakeClient, cfg.Notification)

upgradeEvaluationManager := avs.NewEvaluationManager(avsDel, avs.Config{})
runtimeLister := kebOrchestration.NewRuntimeLister(db.Instances(), db.Operations(), kebRuntime.NewConverter(defaultRegion), logs)
runtimeResolver := orchestration.NewGardenerRuntimeResolver(gardenerClient, fixedGardenerNamespace, runtimeLister, logs)

clusterQueue := NewClusterOrchestrationProcessingQueue(ctx, db, provisionerClient, eventBroker, inputFactory, &upgrade_cluster.TimeSchedule{
Retry: 10 * time.Millisecond,
StatusCheck: 100 * time.Millisecond,
UpgradeClusterTimeout: 3 * time.Second,
}, 250*time.Millisecond, runtimeResolver, upgradeEvaluationManager, notificationBundleBuilder, logs, cli, *cfg, 1000)
}, 250*time.Millisecond, runtimeResolver, notificationBundleBuilder, logs, cli, *cfg, 1000)

clusterQueue.SpeedUp(1000)

Expand Down Expand Up @@ -339,7 +332,7 @@ func (s *BrokerSuiteTest) CallAPI(method string, path string, body string) *http
return resp
}

func (s *BrokerSuiteTest) CreateAPI(inputFactory broker.PlanValidator, cfg *Config, db storage.BrokerStorage, provisioningQueue *process.Queue, deprovisionQueue *process.Queue, updateQueue *process.Queue, logs logrus.FieldLogger) {
func (s *BrokerSuiteTest) CreateAPI(inputFactory broker.PlanValidator, cfg *Config, db storage.BrokerStorage, provisioningQueue *process.Queue, deprovisionQueue *process.Queue, updateQueue *process.Queue, logs logrus.FieldLogger, skrK8sClientProvider *kubeconfig.FakeProvider, gardenerClient client.Client) {
servicesConfig := map[string]broker.Service{
broker.KymaServiceName: {
Description: "",
Expand Down Expand Up @@ -368,28 +361,11 @@ func (s *BrokerSuiteTest) CreateAPI(inputFactory broker.PlanValidator, cfg *Conf
}
kcBuilder := &kcMock.KcBuilder{}
kcBuilder.On("Build", nil).Return("--kubeconfig file", nil)
createAPI(s.router, servicesConfig, inputFactory, cfg, db, provisioningQueue, deprovisionQueue, updateQueue, lager.NewLogger("api"), logs, planDefaults, kcBuilder)
createAPI(s.router, servicesConfig, inputFactory, cfg, db, provisioningQueue, deprovisionQueue, updateQueue, lager.NewLogger("api"), logs, planDefaults, kcBuilder, skrK8sClientProvider, skrK8sClientProvider, gardenerClient)

s.httpServer = httptest.NewServer(s.router)
}

func createFakeAvsDelegator(t *testing.T, db storage.BrokerStorage, cfg *Config) (*avs.Delegator, *provisioning.ExternalEvalCreator, *avs.InternalEvalAssistant, *avs.ExternalEvalAssistant) {
server := avs.NewMockAvsServer(t)
mockServer := avs.FixMockAvsServer(server)
avsConfig := avs.Config{
OauthTokenEndpoint: fmt.Sprintf("%s/oauth/token", mockServer.URL),
ApiEndpoint: fmt.Sprintf("%s/api/v2/evaluationmetadata", mockServer.URL),
}
client, err := avs.NewClient(context.TODO(), avsConfig, logrus.New())
assert.NoError(t, err)
avsDel := avs.NewDelegator(client, avsConfig, db.Operations())
externalEvalAssistant := avs.NewExternalEvalAssistant(cfg.Avs)
internalEvalAssistant := avs.NewInternalEvalAssistant(cfg.Avs)
externalEvalCreator := provisioning.NewExternalEvalCreator(avsDel, cfg.Avs.Disabled, externalEvalAssistant)

return avsDel, externalEvalCreator, internalEvalAssistant, externalEvalAssistant
}

func (s *BrokerSuiteTest) CreateProvisionedRuntime(options RuntimeOptions) string {
randomInstanceId := uuid.New().String()

Expand Down
9 changes: 2 additions & 7 deletions cmd/broker/deprovisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/kyma-project/kyma-environment-broker/common/hyperscaler"
"github.com/kyma-project/kyma-environment-broker/internal/avs"
"github.com/kyma-project/kyma-environment-broker/internal/event"
"github.com/kyma-project/kyma-environment-broker/internal/process"
"github.com/kyma-project/kyma-environment-broker/internal/process/deprovisioning"
Expand All @@ -19,8 +18,7 @@ import (

func NewDeprovisioningProcessingQueue(ctx context.Context, workersAmount int, deprovisionManager *process.StagedManager,
cfg *Config, db storage.BrokerStorage, pub event.Publisher,
provisionerClient provisioner.Client, avsDel *avs.Delegator, internalEvalAssistant *avs.InternalEvalAssistant,
externalEvalAssistant *avs.ExternalEvalAssistant,
provisionerClient provisioner.Client,
edpClient deprovisioning.EDPClient, accountProvider hyperscaler.AccountProvider,
k8sClientProvider K8sClientProvider, cli client.Client, configProvider input.ConfigurationProvider, logs logrus.FieldLogger) *process.Queue {

Expand All @@ -34,9 +32,6 @@ func NewDeprovisioningProcessingQueue(ctx context.Context, workersAmount int, de
{
step: deprovisioning.NewBTPOperatorCleanupStep(db.Operations(), k8sClientProvider),
},
{
step: deprovisioning.NewAvsEvaluationsRemovalStep(avsDel, db.Operations(), externalEvalAssistant, internalEvalAssistant),
},
{
step: deprovisioning.NewEDPDeregistrationStep(db.Operations(), db.Instances(), edpClient, cfg.EDP),
disabled: cfg.EDP.Disabled,
Expand All @@ -62,7 +57,7 @@ func NewDeprovisioningProcessingQueue(ctx context.Context, workersAmount int, de
step: deprovisioning.NewCheckGardenerClusterDeletedStep(db.Operations(), cli),
},
{
step: deprovisioning.NewRemoveRuntimeStep(db.Operations(), db.Instances(), provisionerClient, cfg.Provisioner.DeprovisioningTimeout, cfg.Broker.KimConfig),
step: deprovisioning.NewRemoveRuntimeStep(db.Operations(), db.Instances(), provisionerClient, cfg.Provisioner.DeprovisioningTimeout),
},
{
step: deprovisioning.NewCheckRuntimeRemovalStep(db.Operations(), db.Instances(), provisionerClient, cfg.Provisioner.DeprovisioningTimeout),
Expand Down
19 changes: 1 addition & 18 deletions cmd/broker/deprovisioning_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/google/uuid"
"github.com/kyma-project/control-plane/components/provisioner/pkg/gqlschema"
"github.com/kyma-project/kyma-environment-broker/internal"
"github.com/kyma-project/kyma-environment-broker/internal/avs"
"github.com/kyma-project/kyma-environment-broker/internal/edp"
"github.com/kyma-project/kyma-environment-broker/internal/event"
"github.com/kyma-project/kyma-environment-broker/internal/fixture"
Expand Down Expand Up @@ -86,22 +85,6 @@ func NewDeprovisioningSuite(t *testing.T) *DeprovisioningSuite {
eventBroker := event.NewPubSub(logs)
provisionerClient := provisioner.NewFakeClient()

server := avs.NewMockAvsServer(t)
mockServer := avs.FixMockAvsServer(server)
avsConfig := avs.Config{
OauthTokenEndpoint: fmt.Sprintf("%s/oauth/token", mockServer.URL),
ApiEndpoint: fmt.Sprintf("%s/api/v2/evaluationmetadata", mockServer.URL),
}
client, err := avs.NewClient(context.TODO(), avsConfig, logrus.New())
assert.NoError(t, err)
_, err = client.CreateEvaluation(&avs.BasicEvaluationCreateRequest{
Name: "fake-evaluation",
})
assert.NoError(t, err)
avsDel := avs.NewDelegator(client, avsConfig, db.Operations())
externalEvalAssistant := avs.NewExternalEvalAssistant(cfg.Avs)
internalEvalAssistant := avs.NewInternalEvalAssistant(cfg.Avs)

edpClient := fixEDPClient(t)

accountProvider := fixAccountProvider()
Expand All @@ -126,7 +109,7 @@ func NewDeprovisioningSuite(t *testing.T) *DeprovisioningSuite {
kebConfig.NewConfigMapConverter())

deprovisioningQueue := NewDeprovisioningProcessingQueue(ctx, workersAmount, deprovisionManager, cfg, db, eventBroker,
provisionerClient, avsDel, internalEvalAssistant, externalEvalAssistant,
provisionerClient,
edpClient, accountProvider, kubeconfig.NewFakeK8sClientProvider(fakeK8sSKRClient), fakeK8sSKRClient, configProvider, logs,
)

Expand Down
35 changes: 14 additions & 21 deletions cmd/broker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import (

"code.cloudfoundry.org/lager"
"github.com/dlmiddlecote/sqlstats"
shoot "github.com/gardener/gardener/pkg/apis/core/v1beta1"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/kyma-project/kyma-environment-broker/common/gardener"
"github.com/kyma-project/kyma-environment-broker/common/hyperscaler"
orchestrationExt "github.com/kyma-project/kyma-environment-broker/common/orchestration"
"github.com/kyma-project/kyma-environment-broker/internal"
"github.com/kyma-project/kyma-environment-broker/internal/appinfo"
"github.com/kyma-project/kyma-environment-broker/internal/avs"
"github.com/kyma-project/kyma-environment-broker/internal/broker"
kebConfig "github.com/kyma-project/kyma-environment-broker/internal/config"
"github.com/kyma-project/kyma-environment-broker/internal/dashboard"
Expand All @@ -43,7 +43,6 @@ import (
orchestrate "github.com/kyma-project/kyma-environment-broker/internal/orchestration/handlers"
"github.com/kyma-project/kyma-environment-broker/internal/process"
"github.com/kyma-project/kyma-environment-broker/internal/process/input"
"github.com/kyma-project/kyma-environment-broker/internal/process/provisioning"
"github.com/kyma-project/kyma-environment-broker/internal/provider"
"github.com/kyma-project/kyma-environment-broker/internal/provisioner"
"github.com/kyma-project/kyma-environment-broker/internal/runtime"
Expand All @@ -58,6 +57,7 @@ import (
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -111,7 +111,6 @@ type Config struct {
Broker broker.Config
CatalogFilePath string

Avs avs.Config
EDP edp.Config

Notification notification.Config
Expand Down Expand Up @@ -156,7 +155,8 @@ type Config struct {

RuntimeConfigurationConfigMapName string `envconfig:"default=keb-runtime-config"`

UpdateRuntimeResourceDelay time.Duration `envconfig:"default=4s"`
UpdateRuntimeResourceDelay time.Duration `envconfig:"default=4s"`
BindingTokenExpirationSeconds int `envconfig:"default=600"`
}

type ProfilerConfig struct {
Expand All @@ -167,6 +167,7 @@ type ProfilerConfig struct {

type K8sClientProvider interface {
K8sClientForRuntimeID(rid string) (client.Client, error)
K8sClientSetForRuntimeID(runtimeID string) (*kubernetes.Clientset, error)
}

type KubeconfigProvider interface {
Expand Down Expand Up @@ -209,6 +210,8 @@ func main() {
panicOnError(err)
err = imv1.AddToScheme(scheme.Scheme)
panicOnError(err)
err = shoot.AddToScheme(scheme.Scheme)
panicOnError(err)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -286,6 +289,8 @@ func main() {
fatalOnError(err, logs)
dynamicGardener, err := dynamic.NewForConfig(gardenerClusterConfig)
fatalOnError(err, logs)
gardenerClient, err := initClient(gardenerClusterConfig)
fatalOnError(err, logs)

gardenerNamespace := fmt.Sprintf("garden-%v", cfg.Gardener.Project)
gardenerAccountPool := hyperscaler.NewAccountPool(dynamicGardener, gardenerNamespace)
Expand All @@ -303,16 +308,6 @@ func main() {

edpClient := edp.NewClient(cfg.EDP)

panicOnError(cfg.Avs.ReadMaintenanceModeDuringUpgradeAlwaysDisabledGAIDsFromYaml(
cfg.AvsMaintenanceModeDuringUpgradeAlwaysDisabledGlobalAccountsFilePath))
avsClient, err := avs.NewClient(ctx, cfg.Avs, logs)
fatalOnError(err, logs)
avsDel := avs.NewDelegator(avsClient, cfg.Avs, db.Operations())
externalEvalAssistant := avs.NewExternalEvalAssistant(cfg.Avs)
internalEvalAssistant := avs.NewInternalEvalAssistant(cfg.Avs)
externalEvalCreator := provisioning.NewExternalEvalCreator(avsDel, cfg.Avs.ExternalTesterDisabled, externalEvalAssistant)
upgradeEvalManager := avs.NewEvaluationManager(avsDel, cfg.Avs)

// application event broker
eventBroker := event.NewPubSub(logs)

Expand All @@ -322,12 +317,10 @@ func main() {
// run queues
provisionManager := process.NewStagedManager(db.Operations(), eventBroker, cfg.OperationTimeout, cfg.Provisioning, logs.WithField("provisioning", "manager"))
provisionQueue := NewProvisioningProcessingQueue(ctx, provisionManager, cfg.Provisioning.WorkersAmount, &cfg, db, provisionerClient, inputFactory,
avsDel, internalEvalAssistant, externalEvalCreator,
edpClient, accountProvider, skrK8sClientProvider, cli, oidcDefaultValues, logs)

deprovisionManager := process.NewStagedManager(db.Operations(), eventBroker, cfg.OperationTimeout, cfg.Deprovisioning, logs.WithField("deprovisioning", "manager"))
deprovisionQueue := NewDeprovisioningProcessingQueue(ctx, cfg.Deprovisioning.WorkersAmount, deprovisionManager, &cfg, db, eventBroker, provisionerClient,
avsDel, internalEvalAssistant, externalEvalAssistant, edpClient, accountProvider,
deprovisionQueue := NewDeprovisioningProcessingQueue(ctx, cfg.Deprovisioning.WorkersAmount, deprovisionManager, &cfg, db, eventBroker, provisionerClient, edpClient, accountProvider,
skrK8sClientProvider, cli, configProvider, logs)

updateManager := process.NewStagedManager(db.Operations(), eventBroker, cfg.OperationTimeout, cfg.Update, logs.WithField("update", "manager"))
Expand All @@ -342,7 +335,7 @@ func main() {

// create server
router := mux.NewRouter()
createAPI(router, servicesConfig, inputFactory, &cfg, db, provisionQueue, deprovisionQueue, updateQueue, logger, logs, inputFactory.GetPlanDefaults, kcBuilder)
createAPI(router, servicesConfig, inputFactory, &cfg, db, provisionQueue, deprovisionQueue, updateQueue, logger, logs, inputFactory.GetPlanDefaults, kcBuilder, skrK8sClientProvider, skrK8sClientProvider, gardenerClient)

// create metrics endpoint
router.Handle("/metrics", promhttp.Handler())
Expand All @@ -355,7 +348,7 @@ func main() {
runtimeResolver := orchestrationExt.NewGardenerRuntimeResolver(dynamicGardener, gardenerNamespace, runtimeLister, logs)

clusterQueue := NewClusterOrchestrationProcessingQueue(ctx, db, provisionerClient, eventBroker, inputFactory,
nil, time.Minute, runtimeResolver, upgradeEvalManager, notificationBuilder, logs, cli, cfg, 1)
nil, time.Minute, runtimeResolver, notificationBuilder, logs, cli, cfg, 1)

// TODO: in case of cluster upgrade the same Azure Zones must be send to the Provisioner
orchestrationHandler := orchestrate.NewOrchestrationHandler(db, clusterQueue, cfg.MaxPaginationPage, logs)
Expand Down Expand Up @@ -419,7 +412,7 @@ func logConfiguration(logs *logrus.Logger, cfg Config) {
logs.Infof("Is SubaccountMovementEnabled: %t", cfg.Broker.SubaccountMovementEnabled)
}

func createAPI(router *mux.Router, servicesConfig broker.ServicesConfig, planValidator broker.PlanValidator, cfg *Config, db storage.BrokerStorage, provisionQueue, deprovisionQueue, updateQueue *process.Queue, logger lager.Logger, logs logrus.FieldLogger, planDefaults broker.PlanDefaults, kcBuilder kubeconfig.KcBuilder) {
func createAPI(router *mux.Router, servicesConfig broker.ServicesConfig, planValidator broker.PlanValidator, cfg *Config, db storage.BrokerStorage, provisionQueue, deprovisionQueue, updateQueue *process.Queue, logger lager.Logger, logs logrus.FieldLogger, planDefaults broker.PlanDefaults, kcBuilder kubeconfig.KcBuilder, clientProvider K8sClientProvider, kubeconfigProvider KubeconfigProvider, gardenerClient client.Client) {
suspensionCtxHandler := suspension.NewContextUpdateHandler(db.Operations(), provisionQueue, deprovisionQueue, logs)

defaultPlansConfig, err := servicesConfig.DefaultPlansConfig()
Expand Down Expand Up @@ -454,7 +447,7 @@ func createAPI(router *mux.Router, servicesConfig broker.ServicesConfig, planVal
planDefaults, logs, cfg.KymaDashboardConfig, kcBuilder, convergedCloudRegionProvider),
GetInstanceEndpoint: broker.NewGetInstance(cfg.Broker, db.Instances(), db.Operations(), kcBuilder, logs),
LastOperationEndpoint: broker.NewLastOperation(db.Operations(), db.InstancesArchived(), logs),
BindEndpoint: broker.NewBind(cfg.Broker.Binding, db.Instances(), logs),
BindEndpoint: broker.NewBind(cfg.Broker.Binding, db.Instances(), logs, clientProvider, kubeconfigProvider, gardenerClient, cfg.BindingTokenExpirationSeconds),
UnbindEndpoint: broker.NewUnbind(logs),
GetBindingEndpoint: broker.NewGetBinding(logs),
LastBindingOperationEndpoint: broker.NewLastBindingOperation(logs),
Expand Down
Loading

0 comments on commit 2f83e80

Please sign in to comment.