github.com/kyma-project/kyma-environment-broker@v0.0.1/cmd/broker/provisioning.go (about) 1 package main 2 3 import ( 4 "context" 5 6 "github.com/kyma-project/kyma-environment-broker/common/hyperscaler" 7 "github.com/kyma-project/kyma-environment-broker/internal/avs" 8 "github.com/kyma-project/kyma-environment-broker/internal/process" 9 "github.com/kyma-project/kyma-environment-broker/internal/process/input" 10 "github.com/kyma-project/kyma-environment-broker/internal/process/provisioning" 11 "github.com/kyma-project/kyma-environment-broker/internal/process/steps" 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 NewProvisioningProcessingQueue(ctx context.Context, provisionManager *process.StagedManager, workersAmount int, cfg *Config, 21 db storage.BrokerStorage, provisionerClient provisioner.Client, inputFactory input.CreatorForPlan, avsDel *avs.Delegator, 22 internalEvalAssistant *avs.InternalEvalAssistant, externalEvalCreator *provisioning.ExternalEvalCreator, 23 runtimeVerConfigurator *runtimeversion.RuntimeVersionConfigurator, 24 runtimeOverrides provisioning.RuntimeOverridesAppender, edpClient provisioning.EDPClient, accountProvider hyperscaler.AccountProvider, 25 reconcilerClient reconciler.Client, k8sClientProvider func(kcfg string) (client.Client, error), cli client.Client, logs logrus.FieldLogger) *process.Queue { 26 27 const postActionsStageName = "post_actions" 28 provisionManager.DefineStages([]string{startStageName, createRuntimeStageName, 29 checkKymaStageName, createKymaResourceStageName, postActionsStageName}) 30 /* 31 The provisioning process contains the following stages: 32 1. "start" - changes the state from pending to in progress if no deprovisioning is ongoing. 33 2. "create_runtime" - collects all information needed to make an input for the Provisioner request as overrides and labels. 34 Those data is collected using an InputCreator which is not persisted. That's why all steps which prepares such data must be in the same stage as "create runtime step". 35 All steps which requires InputCreator must be run in this stage. 36 3. "check_kyma" - checks if the Kyma is installed 37 4. "post_actions" - all steps which must be executed after the runtime is provisioned 38 39 Once the stage is done it will never be retried. 40 */ 41 42 provisioningSteps := []struct { 43 disabled bool 44 stage string 45 step process.Step 46 condition process.StepCondition 47 }{ 48 { 49 stage: startStageName, 50 step: provisioning.NewStartStep(db.Operations(), db.Instances()), 51 }, 52 { 53 stage: createRuntimeStageName, 54 step: provisioning.NewInitialisationStep(db.Operations(), db.Instances(), inputFactory, runtimeVerConfigurator), 55 }, 56 { 57 stage: createRuntimeStageName, 58 step: steps.NewInitKymaTemplate(db.Operations()), 59 }, 60 { 61 stage: createRuntimeStageName, 62 step: provisioning.NewOverrideKymaModules(db.Operations()), 63 }, 64 { 65 stage: createRuntimeStageName, 66 step: provisioning.NewResolveCredentialsStep(db.Operations(), accountProvider), 67 condition: provisioning.SkipForOwnClusterPlan, 68 }, 69 { 70 stage: createRuntimeStageName, 71 step: provisioning.NewInternalEvaluationStep(avsDel, internalEvalAssistant), 72 disabled: cfg.Avs.Disabled, 73 }, 74 { 75 stage: createRuntimeStageName, 76 step: provisioning.NewEDPRegistrationStep(db.Operations(), edpClient, cfg.EDP), 77 disabled: cfg.EDP.Disabled, 78 condition: provisioning.SkipForOwnClusterPlan, 79 }, 80 { 81 stage: createRuntimeStageName, 82 step: provisioning.NewOverridesFromSecretsAndConfigStep(db.Operations(), runtimeOverrides, runtimeVerConfigurator), 83 // Preview plan does not call Reconciler so it does not need overrides 84 condition: skipForPreviewPlan, 85 }, 86 { 87 condition: provisioning.WhenBTPOperatorCredentialsProvided, 88 stage: createRuntimeStageName, 89 step: provisioning.NewBTPOperatorOverridesStep(db.Operations()), 90 }, 91 { 92 condition: provisioning.SkipForOwnClusterPlan, 93 stage: createRuntimeStageName, 94 step: provisioning.NewCreateRuntimeWithoutKymaStep(db.Operations(), db.RuntimeStates(), db.Instances(), provisionerClient), 95 }, 96 { 97 condition: provisioning.DoForOwnClusterPlanOnly, 98 stage: createRuntimeStageName, 99 step: provisioning.NewCreateRuntimeForOwnClusterStep(db.Operations(), db.Instances()), 100 }, 101 { 102 stage: createRuntimeStageName, 103 step: provisioning.NewCheckRuntimeStep(db.Operations(), provisionerClient, cfg.Provisioner.ProvisioningTimeout), 104 condition: provisioning.SkipForOwnClusterPlan, 105 }, 106 { 107 stage: createRuntimeStageName, 108 step: provisioning.NewGetKubeconfigStep(db.Operations(), provisionerClient, k8sClientProvider), 109 }, 110 { 111 condition: provisioning.WhenBTPOperatorCredentialsProvided, 112 stage: createRuntimeStageName, 113 step: provisioning.NewInjectBTPOperatorCredentialsStep(db.Operations(), k8sClientProvider), 114 }, 115 { 116 disabled: cfg.LifecycleManagerIntegrationDisabled, 117 stage: createRuntimeStageName, 118 step: steps.SyncKubeconfig(db.Operations(), cli), 119 }, 120 { 121 disabled: cfg.ReconcilerIntegrationDisabled, 122 stage: createRuntimeStageName, 123 step: provisioning.NewCreateClusterConfiguration(db.Operations(), db.RuntimeStates(), reconcilerClient), 124 condition: skipForPreviewPlan, 125 }, 126 { 127 disabled: cfg.ReconcilerIntegrationDisabled, 128 stage: checkKymaStageName, 129 step: provisioning.NewCheckClusterConfigurationStep(db.Operations(), reconcilerClient, cfg.Reconciler.ProvisioningTimeout), 130 condition: skipForPreviewPlan, 131 }, 132 { 133 disabled: cfg.LifecycleManagerIntegrationDisabled, 134 stage: createKymaResourceStageName, 135 step: provisioning.NewApplyKymaStep(db.Operations(), cli), 136 }, 137 // post actions 138 { 139 stage: postActionsStageName, 140 step: provisioning.NewExternalEvalStep(externalEvalCreator), 141 }, 142 { 143 stage: postActionsStageName, 144 step: provisioning.NewInternalEvaluationStep(avsDel, internalEvalAssistant), 145 disabled: cfg.Avs.Disabled, 146 }, 147 } 148 for _, step := range provisioningSteps { 149 if !step.disabled { 150 err := provisionManager.AddStep(step.stage, step.step, step.condition) 151 if err != nil { 152 fatalOnError(err) 153 } 154 } 155 } 156 157 queue := process.NewQueue(provisionManager, logs) 158 queue.Run(ctx.Done(), workersAmount) 159 160 return queue 161 }