generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 12
/
reconciler.go
69 lines (55 loc) · 1.67 KB
/
reconciler.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
58
59
60
61
62
63
64
65
66
67
68
69
package scope
import (
"context"
"github.com/kyma-project/cloud-manager/components/lib/composed"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
type ScopeReconciler interface {
reconcile.Reconciler
}
func NewScopeReconciler(stateFactory StateFactory) ScopeReconciler {
return &scopeReconciler{
stateFactory: stateFactory,
}
}
type scopeReconciler struct {
stateFactory StateFactory
}
func (r *scopeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
state := r.newState(req)
action := r.newAction()
return composed.Handle(action(ctx, state))
}
func (r *scopeReconciler) newState(req ctrl.Request) *State {
return r.stateFactory.NewState(req)
}
func (r *scopeReconciler) newAction() composed.Action {
// Deprovisioning is done from the skr.CloudManager module CR loop
// it will determine if all cloud resources are deleted from SKR
// and if so will delete installed CRDs, remove finalizers from Kyma and Scope,
// and remove skr from the looper
//
// This Scope/Kyma loop is handling provisioning only, and
// if module is present in the Kyma and in Ready state it has to
// * add finalizer to Kyma
// * create Scope with finalizer
// * add SKR to the looper
return composed.ComposeActions(
"kymaMain",
loadKyma, // stops if Kyma not found
findKymaModuleState, // stops if module not present
// module is in Ready state
addKymaFinalizer,
loadScopeObj, // stops if Scope exists
// scope does not exist
createGardenerClient,
loadShoot,
loadGardenerCredentials,
createScope,
ensureScopeCommonFields,
saveScope,
skrActivate,
composed.StopAndForgetAction,
)
}