github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/ctrlcrd/boom/boom.go (about) 1 package boom 2 3 import ( 4 "context" 5 "fmt" 6 "path/filepath" 7 8 "github.com/caos/orbos/internal/api/boom" 9 10 v1 "github.com/caos/orbos/internal/api/boom/v1" 11 "github.com/caos/orbos/internal/operator/boom/app" 12 gconfig "github.com/caos/orbos/internal/operator/boom/application/applications/monitoring/config" 13 "github.com/caos/orbos/mntr" 14 "github.com/caos/orbos/pkg/kubernetes" 15 "k8s.io/apimachinery/pkg/runtime" 16 ctrl "sigs.k8s.io/controller-runtime" 17 ) 18 19 type Reconciler struct { 20 kubernetes.ClientInt 21 Monitor mntr.Monitor 22 Scheme *runtime.Scheme 23 ToolsDirectoryPath string 24 Version string 25 } 26 27 func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.Result, err error) { 28 internalMonitor := r.Monitor.WithFields(map[string]interface{}{ 29 "kind": "Boom", 30 "name": req.NamespacedName, 31 }) 32 33 defer func() { 34 r.Monitor.Error(err) 35 }() 36 37 if req.Namespace != boom.Namespace || req.Name != boom.Name { 38 return res, fmt.Errorf("resource must be named %s and namespaced in %s", boom.Name, boom.Namespace) 39 } 40 41 desired, err := boom.ReadCRD(r) 42 if err != nil { 43 return res, err 44 } 45 46 gconfig.DashboardsDirectoryPath = filepath.Join(r.ToolsDirectoryPath, "dashboards") 47 appStruct := app.New(internalMonitor, r.ToolsDirectoryPath) 48 49 return res, appStruct.ReconcileCrd(req.NamespacedName.String(), desired) 50 } 51 52 func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error { 53 return ctrl.NewControllerManagedBy(mgr). 54 For(&v1.Boom{}). 55 Complete(r) 56 }