/
sc_migration_check_step.go
57 lines (50 loc) · 2.34 KB
/
sc_migration_check_step.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package update
import (
"fmt"
"time"
reconcilerApi "github.com/kyma-incubator/reconciler/pkg/keb"
"github.com/kyma-project/control-plane/components/kyma-environment-broker/internal"
kebError "github.com/kyma-project/control-plane/components/kyma-environment-broker/internal/error"
"github.com/kyma-project/control-plane/components/kyma-environment-broker/internal/process"
"github.com/kyma-project/control-plane/components/kyma-environment-broker/internal/reconciler"
"github.com/kyma-project/control-plane/components/kyma-environment-broker/internal/storage"
"github.com/sirupsen/logrus"
)
type CheckReconcilerState struct {
operationManager *process.OperationManager
reconcilerClient reconciler.Client
}
func NewCheckReconcilerState(os storage.Operations, reconcilerClient reconciler.Client) *CheckReconcilerState {
return &CheckReconcilerState{
operationManager: process.NewOperationManager(os),
reconcilerClient: reconcilerClient,
}
}
func (s *CheckReconcilerState) Name() string {
return "CheckReconcilerState"
}
func (s *CheckReconcilerState) Run(operation internal.Operation, log logrus.FieldLogger) (internal.Operation, time.Duration, error) {
state, err := s.reconcilerClient.GetCluster(operation.RuntimeID, operation.ClusterConfigurationVersion)
if kebError.IsTemporaryError(err) {
log.Errorf("Reconciler GetCluster method failed (temporary error, retrying): %v", err)
return operation, 1 * time.Minute, nil
} else if err != nil {
return s.operationManager.OperationFailed(operation, "failed to get cluster status", err, log)
}
switch state.Status {
case reconcilerApi.StatusReconciling, reconcilerApi.StatusReconcilePending:
log.Infof("Reconciler status %v", state.Status)
return operation, 30 * time.Second, nil
case reconcilerApi.StatusReconcileErrorRetryable:
log.Infof("Reconciler failed with retryable, rechecking in 10 minutes.")
return operation, 10 * time.Minute, nil
case reconcilerApi.StatusReady:
return operation, 0, nil
case reconcilerApi.StatusError:
msg := fmt.Sprintf("Reconciler failed %v: %v", state.Status, reconciler.PrettyFailures(state))
return s.operationManager.OperationFailed(operation, msg, nil, log)
default:
msg := fmt.Sprintf("Unknown reconciler cluster state %v, error: %v", state.Status, reconciler.PrettyFailures(state))
return s.operationManager.OperationFailed(operation, msg, nil, log)
}
}