-
Notifications
You must be signed in to change notification settings - Fork 53
/
logging_opniopensearch_controller.go
63 lines (52 loc) · 2.2 KB
/
logging_opniopensearch_controller.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
//go:build !minimal
package controllers
import (
"context"
loggingv1beta1 "github.com/rancher/opni/apis/logging/v1beta1"
"github.com/rancher/opni/pkg/resources"
"github.com/rancher/opni/pkg/resources/opniopensearch"
"github.com/rancher/opni/pkg/util/k8sutil"
"k8s.io/apimachinery/pkg/runtime"
opsterv1 "opensearch.opster.io/api/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)
type LoggingOpniOpensearchReconciler struct {
client.Client
scheme *runtime.Scheme
Opts []opniopensearch.ReconcilerOption
}
// +kubebuilder:rbac:groups=logging.opni.io,resources=opniopensearches,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=logging.opni.io,resources=opniopensearches/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=logging.opni.io,resources=opniopensearches/finalizers,verbs=update
// +kubebuilder:rbac:groups=opensearch.opster.io,resources=opensearchclusters,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=opensearch.opster.io,resources=opensearchclusters/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=opensearch.opster.io,resources=opensearchclusters/finalizers,verbs=update
func (r *LoggingOpniOpensearchReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
opniOpensearch := &loggingv1beta1.OpniOpensearch{}
err := r.Get(ctx, req.NamespacedName, opniOpensearch)
if err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
}
opniOpensearchReconciler := opniopensearch.NewReconciler(ctx, opniOpensearch, r.Client, r.Opts...)
reconcilers := []resources.ComponentReconciler{
opniOpensearchReconciler.Reconcile,
}
for _, rec := range reconcilers {
op := k8sutil.LoadResult(rec())
if op.ShouldRequeue() {
return op.Result()
}
}
return k8sutil.DoNotRequeue().Result()
}
// SetupWithManager sets up the controller with the Manager.
func (r *LoggingOpniOpensearchReconciler) SetupWithManager(mgr ctrl.Manager) error {
r.Client = mgr.GetClient()
r.scheme = mgr.GetScheme()
return ctrl.NewControllerManagedBy(mgr).
For(&loggingv1beta1.OpniOpensearch{}).
Owns(&opsterv1.OpenSearchCluster{}).
Owns(&loggingv1beta1.MulticlusterRoleBinding{}).
Complete(r)
}