/
componenttemplate_reconciler.go
57 lines (48 loc) · 2.11 KB
/
componenttemplate_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
package elasticsearchapi
import (
"context"
"time"
eshandler "github.com/disaster37/es-handler/v8"
"github.com/disaster37/operator-sdk-extra/pkg/controller"
"github.com/disaster37/operator-sdk-extra/pkg/object"
olivere "github.com/olivere/elastic/v7"
"github.com/sirupsen/logrus"
elasticsearchapicrd "github.com/webcenter-fr/elasticsearch-operator/apis/elasticsearchapi/v1"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)
type componentTemplateReconciler struct {
controller.RemoteReconcilerAction[*elasticsearchapicrd.ComponentTemplate, *olivere.IndicesGetComponentTemplate, eshandler.ElasticsearchHandler]
controller.BaseReconciler
}
func newComponentTemplateReconciler(client client.Client, logger *logrus.Entry, recorder record.EventRecorder) controller.RemoteReconcilerAction[*elasticsearchapicrd.ComponentTemplate, *olivere.IndicesGetComponentTemplate, eshandler.ElasticsearchHandler] {
return &componentTemplateReconciler{
RemoteReconcilerAction: controller.NewRemoteReconcilerAction[*elasticsearchapicrd.ComponentTemplate, *olivere.IndicesGetComponentTemplate, eshandler.ElasticsearchHandler](
client,
logger,
recorder,
),
BaseReconciler: controller.BaseReconciler{
Client: client,
Log: logger,
Recorder: recorder,
},
}
}
func (h *componentTemplateReconciler) GetRemoteHandler(ctx context.Context, req ctrl.Request, o object.RemoteObject) (handler controller.RemoteExternalReconciler[*elasticsearchapicrd.ComponentTemplate, *olivere.IndicesGetComponentTemplate, eshandler.ElasticsearchHandler], res ctrl.Result, err error) {
ct := o.(*elasticsearchapicrd.ComponentTemplate)
esClient, err := GetElasticsearchHandler(ctx, ct, ct.Spec.ElasticsearchRef, h.BaseReconciler.Client, h.BaseReconciler.Log)
if err != nil && ct.DeletionTimestamp.IsZero() {
return nil, res, err
}
// Elastic not ready
if esClient == nil {
if ct.DeletionTimestamp.IsZero() {
return nil, ctrl.Result{RequeueAfter: 60 * time.Second}, nil
}
return nil, res, nil
}
handler = newComponentTemplateApiClient(esClient)
return handler, res, nil
}