-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaccount_controller.go
More file actions
80 lines (62 loc) · 2.57 KB
/
account_controller.go
File metadata and controls
80 lines (62 loc) · 2.57 KB
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
70
71
72
73
74
75
76
77
78
79
80
package controller
import (
"context"
"github.com/platform-mesh/subroutines"
"github.com/platform-mesh/subroutines/conditions"
"github.com/platform-mesh/subroutines/lifecycle"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
mcbuilder "sigs.k8s.io/multicluster-runtime/pkg/builder"
mcmanager "sigs.k8s.io/multicluster-runtime/pkg/manager"
mcreconcile "sigs.k8s.io/multicluster-runtime/pkg/reconcile"
"k8s.io/client-go/rest"
"github.com/platform-mesh/account-operator/api/v1alpha1"
"github.com/platform-mesh/account-operator/internal/config"
"github.com/platform-mesh/account-operator/pkg/subroutines/manageaccountinfo"
"github.com/platform-mesh/account-operator/pkg/subroutines/workspace"
"github.com/platform-mesh/account-operator/pkg/subroutines/workspaceready"
"github.com/platform-mesh/account-operator/pkg/subroutines/workspacetype"
)
const accountReconcilerName = "AccountReconciler"
// AccountReconciler orchestrates Account resources across logical clusters.
type AccountReconciler struct {
cfg config.OperatorConfig
lifecycle *lifecycle.Lifecycle
}
func NewAccountReconciler(mgr mcmanager.Manager, cfg config.OperatorConfig, orgsClient client.Client) *AccountReconciler { // coverage-ignore
localMgr := mgr.GetLocalManager()
localCfg := rest.CopyConfig(localMgr.GetConfig())
serverCA := string(localCfg.CAData)
subs := []subroutines.Subroutine{}
if cfg.Subroutines.WorkspaceType.Enabled {
subs = append(subs, workspacetype.New(orgsClient))
}
if cfg.Subroutines.Workspace.Enabled {
subs = append(subs, workspace.New(mgr, orgsClient))
}
if cfg.Subroutines.AccountInfo.Enabled {
subs = append(subs, manageaccountinfo.New(mgr, serverCA))
}
if cfg.Subroutines.WorkspaceReady.Enabled {
subs = append(subs, workspaceready.New(mgr))
}
lc := lifecycle.New(mgr, accountReconcilerName, func() client.Object { return &v1alpha1.Account{} }, subs...).
WithConditions(conditions.NewManager())
return &AccountReconciler{
cfg: cfg,
lifecycle: lc,
}
}
func (r *AccountReconciler) SetupWithManager(mgr mcmanager.Manager, eventPredicates ...predicate.Predicate) error { // coverage-ignore
builder := mcbuilder.ControllerManagedBy(mgr).
Named(accountReconcilerName).
For(&v1alpha1.Account{})
for _, p := range eventPredicates {
builder = builder.WithEventFilter(p)
}
return builder.Complete(r)
}
func (r *AccountReconciler) Reconcile(ctx context.Context, req mcreconcile.Request) (reconcile.Result, error) { // coverage-ignore
return r.lifecycle.Reconcile(ctx, req)
}