github.com/kyma-project/kyma-environment-broker@v0.0.1/cmd/broker/update.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  
     7  	"github.com/kyma-project/kyma-environment-broker/internal"
     8  	"github.com/kyma-project/kyma-environment-broker/internal/event"
     9  	"github.com/kyma-project/kyma-environment-broker/internal/process"
    10  	"github.com/kyma-project/kyma-environment-broker/internal/process/input"
    11  	"github.com/kyma-project/kyma-environment-broker/internal/process/update"
    12  	"github.com/kyma-project/kyma-environment-broker/internal/provisioner"
    13  	"github.com/kyma-project/kyma-environment-broker/internal/reconciler"
    14  	"github.com/kyma-project/kyma-environment-broker/internal/runtimeversion"
    15  	"github.com/kyma-project/kyma-environment-broker/internal/storage"
    16  	"github.com/sirupsen/logrus"
    17  	"sigs.k8s.io/controller-runtime/pkg/client"
    18  )
    19  
    20  func NewUpdateProcessingQueue(ctx context.Context, manager *process.StagedManager, workersAmount int, db storage.BrokerStorage, inputFactory input.CreatorForPlan,
    21  	provisionerClient provisioner.Client, publisher event.Publisher, runtimeVerConfigurator *runtimeversion.RuntimeVersionConfigurator, runtimeStatesDb storage.RuntimeStates,
    22  	runtimeProvider input.ComponentListProvider, reconcilerClient reconciler.Client, cfg Config, k8sClientProvider func(kcfg string) (client.Client, error), cli client.Client, logs logrus.FieldLogger) *process.Queue {
    23  
    24  	requiresReconcilerUpdate := update.RequiresReconcilerUpdate
    25  	if cfg.ReconcilerIntegrationDisabled {
    26  		requiresReconcilerUpdate = func(op internal.Operation) bool { return false }
    27  	}
    28  	manager.DefineStages([]string{"cluster", "btp-operator", "btp-operator-check", "check"})
    29  	updateSteps := []struct {
    30  		stage     string
    31  		step      process.Step
    32  		condition process.StepCondition
    33  	}{
    34  		{
    35  			stage: "cluster",
    36  			step:  update.NewInitialisationStep(db.Instances(), db.Operations(), runtimeVerConfigurator, inputFactory),
    37  		},
    38  		{
    39  			stage:     "cluster",
    40  			step:      update.NewUpgradeShootStep(db.Operations(), db.RuntimeStates(), provisionerClient),
    41  			condition: update.SkipForOwnClusterPlan,
    42  		},
    43  		{
    44  			stage: "btp-operator",
    45  			step:  update.NewInitKymaVersionStep(db.Operations(), runtimeVerConfigurator, runtimeStatesDb),
    46  		},
    47  		{
    48  			stage:     "btp-operator",
    49  			step:      update.NewGetKubeconfigStep(db.Operations(), provisionerClient, k8sClientProvider),
    50  			condition: update.ForBTPOperatorCredentialsProvided,
    51  		},
    52  		{
    53  			stage:     "btp-operator",
    54  			step:      update.NewBTPOperatorOverridesStep(db.Operations(), runtimeProvider),
    55  			condition: update.RequiresBTPOperatorCredentials,
    56  		},
    57  		{
    58  			stage:     "btp-operator",
    59  			step:      update.NewApplyReconcilerConfigurationStep(db.Operations(), db.RuntimeStates(), reconcilerClient),
    60  			condition: requiresReconcilerUpdate,
    61  		},
    62  		{
    63  			stage:     "btp-operator-check",
    64  			step:      update.NewCheckReconcilerState(db.Operations(), reconcilerClient),
    65  			condition: update.CheckReconcilerStatus,
    66  		},
    67  		{
    68  			stage:     "check",
    69  			step:      update.NewCheckStep(db.Operations(), provisionerClient, 40*time.Minute),
    70  			condition: update.SkipForOwnClusterPlan,
    71  		},
    72  	}
    73  
    74  	for _, step := range updateSteps {
    75  		err := manager.AddStep(step.stage, step.step, step.condition)
    76  		if err != nil {
    77  			fatalOnError(err)
    78  		}
    79  	}
    80  	queue := process.NewQueue(manager, logs)
    81  	queue.Run(ctx.Done(), workersAmount)
    82  
    83  	return queue
    84  }