@@ -19,8 +19,8 @@ import (
19
19
"fmt"
20
20
21
21
ctrl "sigs.k8s.io/controller-runtime"
22
- "sigs.k8s.io/controller-runtime/pkg/builder"
23
22
"sigs.k8s.io/controller-runtime/pkg/client"
23
+ "sigs.k8s.io/controller-runtime/pkg/reconcile"
24
24
25
25
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/controller/atlas"
26
26
internalbuilder "github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/controller/builder"
@@ -34,7 +34,8 @@ import (
34
34
"github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/state"
35
35
)
36
36
37
- type Reconciler struct {
37
+ type AtlasThirdPartyIntegrationHandler struct {
38
+ ctrlstate.StateHandler [akov2next.AtlasThirdPartyIntegration ]
38
39
reconciler.AtlasReconciler
39
40
}
40
41
@@ -44,23 +45,23 @@ type reconcileRequest struct {
44
45
Service thirdpartyintegration.ThirdPartyIntegrationService
45
46
}
46
47
47
- func NewAtlasThirdPartyIntegrationsReconciler () * Reconciler {
48
- return & Reconciler {}
48
+ func NewAtlasThirdPartyIntegrationsReconciler () * ctrlstate. Reconciler [akov2next. AtlasThirdPartyIntegration ] {
49
+ return ctrlstate . NewStateReconciler ( & AtlasThirdPartyIntegrationHandler {})
49
50
}
50
51
51
- func (r * Reconciler ) NewBuilderWithManager (mgr ctrl.Manager ) * builder. Builder {
52
- r .Client = mgr .GetClient ()
52
+ func (h * AtlasThirdPartyIntegrationHandler ) SetupWithManager (mgr ctrl.Manager , rec reconcile. Reconciler ) error {
53
+ h .Client = mgr .GetClient ()
53
54
obj := & akov2next.AtlasThirdPartyIntegration {}
54
- return internalbuilder .NewDefaultControllerBuilder (mgr , obj )
55
+ return internalbuilder .NewDefaultSetupWithManager (mgr , rec , obj )
55
56
}
56
57
57
- func (r * Reconciler ) HandleInitial (ctx context.Context , integration * akov2next.AtlasThirdPartyIntegration ) (ctrlstate.Result , error ) {
58
- req , err := r .newReconcileRequest (ctx , integration )
58
+ func (h * AtlasThirdPartyIntegrationHandler ) HandleInitial (ctx context.Context , integration * akov2next.AtlasThirdPartyIntegration ) (ctrlstate.Result , error ) {
59
+ req , err := h .newReconcileRequest (ctx , integration )
59
60
if err != nil {
60
61
return result .Error (state .StateInitial , fmt .Errorf ("failed to build reconcile request: %w" , err ))
61
62
}
62
63
63
- integrationSpec , err := r .populateIntegration (ctx , integration )
64
+ integrationSpec , err := h .populateIntegration (ctx , integration )
64
65
if err != nil {
65
66
return result .Error (state .StateInitial , fmt .Errorf ("failed to populate integration: %w" , err ))
66
67
}
@@ -71,28 +72,29 @@ func (r *Reconciler) HandleInitial(ctx context.Context, integration *akov2next.A
71
72
integration .Spec .Type , err ))
72
73
}
73
74
integration .Status .ID = createdIntegration .ID
74
- return result .NextState (state .StateCreating ,
75
+ // patch the status here (think about improvements for autogen)
76
+ return result .NextState (state .StateCreated ,
75
77
fmt .Sprintf ("Creating Atlas Third Party Integration for %s" , integration .Spec .Type ))
76
78
}
77
79
78
- func (r * Reconciler ) newReconcileRequest (ctx context.Context , integration * akov2next.AtlasThirdPartyIntegration ) (* reconcileRequest , error ) {
80
+ func (h * AtlasThirdPartyIntegrationHandler ) newReconcileRequest (ctx context.Context , integration * akov2next.AtlasThirdPartyIntegration ) (* reconcileRequest , error ) {
79
81
req := reconcileRequest {}
80
- sdkClientSet , err := r .ResolveSDKClientSet (ctx , integration )
82
+ sdkClientSet , err := h .ResolveSDKClientSet (ctx , integration )
81
83
if err != nil {
82
84
return nil , fmt .Errorf ("failed to resolve connection config: %w" , err )
83
85
}
84
86
req .ClientSet = sdkClientSet
85
87
req .Service = thirdpartyintegration .NewThirdPartyIntegrationServiceFromClientSet (sdkClientSet )
86
- project , err := r .ResolveProject (ctx , sdkClientSet .SdkClient20231115008 , integration )
88
+ project , err := h .ResolveProject (ctx , sdkClientSet .SdkClient20231115008 , integration )
87
89
if err != nil {
88
90
return nil , fmt .Errorf ("failed to fetch referenced project: %w" , err )
89
91
}
90
92
req .Project = project
91
93
return & req , nil
92
94
}
93
95
94
- func (r * Reconciler ) populateIntegration (ctx context.Context , integration * akov2next.AtlasThirdPartyIntegration ) (* thirdpartyintegration.ThirdPartyIntegration , error ) {
95
- secrets , err := fetchIntegrationSecrets (ctx , r .Client , integration )
96
+ func (h * AtlasThirdPartyIntegrationHandler ) populateIntegration (ctx context.Context , integration * akov2next.AtlasThirdPartyIntegration ) (* thirdpartyintegration.ThirdPartyIntegration , error ) {
97
+ secrets , err := fetchIntegrationSecrets (ctx , h .Client , integration )
96
98
if err != nil {
97
99
return nil , fmt .Errorf ("failed to fetch integration secrets: %w" , err )
98
100
}
0 commit comments