github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/deprovisioning/avs_evaluations.go (about) 1 package deprovisioning 2 3 import ( 4 "time" 5 6 "github.com/kyma-project/kyma-environment-broker/internal/broker" 7 8 "github.com/kyma-project/kyma-environment-broker/internal/process" 9 10 "github.com/kyma-project/kyma-environment-broker/internal" 11 "github.com/kyma-project/kyma-environment-broker/internal/avs" 12 "github.com/kyma-project/kyma-environment-broker/internal/storage" 13 "github.com/sirupsen/logrus" 14 ) 15 16 type AvsEvaluationRemovalStep struct { 17 delegator *avs.Delegator 18 externalEvalAssistant avs.EvalAssistant 19 internalEvalAssistant avs.EvalAssistant 20 deProvisioningManager *process.OperationManager 21 } 22 23 func NewAvsEvaluationsRemovalStep(delegator *avs.Delegator, operationsStorage storage.Operations, externalEvalAssistant, internalEvalAssistant avs.EvalAssistant) *AvsEvaluationRemovalStep { 24 return &AvsEvaluationRemovalStep{ 25 delegator: delegator, 26 externalEvalAssistant: externalEvalAssistant, 27 internalEvalAssistant: internalEvalAssistant, 28 deProvisioningManager: process.NewOperationManager(operationsStorage), 29 } 30 } 31 32 func (ars *AvsEvaluationRemovalStep) Name() string { 33 return "De-provision_AVS_Evaluations" 34 } 35 36 func (ars *AvsEvaluationRemovalStep) Run(operation internal.Operation, logger logrus.FieldLogger) (internal.Operation, time.Duration, error) { 37 logger.Infof("Avs lifecycle %+v", operation.Avs) 38 39 // the delegator saves the operation (update in the storage) - it is executed inside the DeleteAvsEvaluation 40 41 operation, err := ars.delegator.DeleteAvsEvaluation(operation, logger, ars.internalEvalAssistant) 42 if err != nil { 43 logger.Warnf("unable to delete internal evaluation: %s", err.Error()) 44 return ars.deProvisioningManager.RetryOperationWithoutFail(operation, ars.Name(), "error while deleting avs internal evaluation", 10*time.Second, 1*time.Minute, logger) 45 } 46 47 if broker.IsTrialPlan(operation.ProvisioningParameters.PlanID) || broker.IsFreemiumPlan(operation.ProvisioningParameters.PlanID) { 48 logger.Info("skipping AVS external evaluation deletion for trial/freemium plan") 49 return operation, 0, nil 50 } 51 operation, err = ars.delegator.DeleteAvsEvaluation(operation, logger, ars.externalEvalAssistant) 52 if err != nil { 53 logger.Warnf("unable to delete external evaluation: %s", err.Error()) 54 return ars.deProvisioningManager.RetryOperationWithoutFail(operation, ars.Name(), "error while deleting avs external evaluation", 10*time.Second, 1*time.Minute, logger) 55 } 56 57 return operation, 0, nil 58 59 }