github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/update/init_kyma_step.go (about) 1 package update 2 3 import ( 4 "time" 5 6 "github.com/kyma-project/kyma-environment-broker/internal/storage/dberr" 7 8 "github.com/kyma-project/kyma-environment-broker/internal" 9 "github.com/kyma-project/kyma-environment-broker/internal/process" 10 "github.com/kyma-project/kyma-environment-broker/internal/runtimeversion" 11 "github.com/kyma-project/kyma-environment-broker/internal/storage" 12 "github.com/sirupsen/logrus" 13 ) 14 15 type InitKymaVersionStep struct { 16 operationManager *process.OperationManager 17 runtimeVerConfigurator *runtimeversion.RuntimeVersionConfigurator 18 runtimeStatesDb storage.RuntimeStates 19 } 20 21 func NewInitKymaVersionStep(os storage.Operations, rvc *runtimeversion.RuntimeVersionConfigurator, runtimeStatesDb storage.RuntimeStates) *InitKymaVersionStep { 22 return &InitKymaVersionStep{ 23 operationManager: process.NewOperationManager(os), 24 runtimeVerConfigurator: rvc, 25 runtimeStatesDb: runtimeStatesDb, 26 } 27 } 28 29 func (s *InitKymaVersionStep) Name() string { 30 return "Update_Init_Kyma_Version" 31 } 32 33 func (s *InitKymaVersionStep) Run(operation internal.Operation, log logrus.FieldLogger) (internal.Operation, time.Duration, error) { 34 var version *internal.RuntimeVersionData 35 var err error 36 if operation.RuntimeVersion.IsEmpty() { 37 version, err = s.runtimeVerConfigurator.ForUpdating(operation) 38 if err != nil { 39 return s.operationManager.RetryOperation(operation, "error while getting runtime version", err, 5*time.Second, 1*time.Minute, log) 40 } 41 } else { 42 version = &operation.RuntimeVersion 43 } 44 var lrs internal.RuntimeState 45 // try to find latest reconciler request 46 lrs, err = s.runtimeStatesDb.GetLatestWithReconcilerInputByRuntimeID(operation.RuntimeID) 47 if dberr.IsNotFound(err) { 48 // if there is no such runtime state (reconciler was not called - for example preview plan) then do not filter by type 49 // todo: this will be simplified when the integration with Reconciler is removed 50 lrs, err = s.runtimeStatesDb.GetLatestByRuntimeID(operation.RuntimeID) 51 } 52 if err != nil { 53 return s.operationManager.RetryOperation(operation, "error while getting latest runtime state", err, 5*time.Second, 1*time.Minute, log) 54 } 55 op, delay, _ := s.operationManager.UpdateOperation(operation, func(op *internal.Operation) { 56 if version != nil { 57 op.RuntimeVersion = *version 58 } 59 op.LastRuntimeState = lrs 60 }, log) 61 log.Info("Init runtime version: ", op.RuntimeVersion.MajorVersion, ", last runtime state: ", op.LastRuntimeState.ID) 62 return op, delay, nil 63 }