From 67444b550af256eb34aef9fd49bac31d65c826d0 Mon Sep 17 00:00:00 2001 From: Vitalii Parfonov Date: Tue, 15 Nov 2022 23:12:26 +0200 Subject: [PATCH] LOG-2999:Add watcher for Elasticsearch object Signed-off-by: Vitalii Parfonov --- controllers/clusterlogging/clusterlogging_controller.go | 6 +++++- internal/k8shandler/clusterloggingrequest.go | 4 ++-- internal/k8shandler/status.go | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/controllers/clusterlogging/clusterlogging_controller.go b/controllers/clusterlogging/clusterlogging_controller.go index fcf1f3b9d..00e8e9bcd 100644 --- a/controllers/clusterlogging/clusterlogging_controller.go +++ b/controllers/clusterlogging/clusterlogging_controller.go @@ -2,7 +2,7 @@ package clusterlogging import ( "context" - + v1 "github.com/openshift/elasticsearch-operator/apis/logging/v1" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/event" @@ -154,6 +154,10 @@ func (r *ReconcileClusterLogging) SetupWithManager(mgr ctrl.Manager) error { controllerBuilder := ctrl.NewControllerManagedBy(mgr). Watches(&source.Kind{Type: &loggingv1.ClusterLogging{}}, &handler.EnqueueRequestForObject{}). Watches(&source.Kind{Type: &loggingv1.ClusterLogForwarder{}}, &handler.EnqueueRequestForObject{}). + Watches(&source.Kind{Type: &v1.Elasticsearch{}}, &handler.EnqueueRequestForOwner{ + IsController: true, + OwnerType: &loggingv1.ClusterLogging{}, + }). Watches(&source.Kind{Type: &corev1.Service{}}, &handler.EnqueueRequestForOwner{ IsController: true, OwnerType: &loggingv1.ClusterLogging{}, diff --git a/internal/k8shandler/clusterloggingrequest.go b/internal/k8shandler/clusterloggingrequest.go index a1cdda89d..4bb5b6d62 100644 --- a/internal/k8shandler/clusterloggingrequest.go +++ b/internal/k8shandler/clusterloggingrequest.go @@ -36,7 +36,7 @@ func (clusterRequest *ClusterLoggingRequest) IncludesManagedStorage() bool { return clusterRequest.Cluster != nil && clusterRequest.Cluster.Spec.LogStore != nil } -//true if equals "Managed" or empty +// true if equals "Managed" or empty func (clusterRequest *ClusterLoggingRequest) isManaged() bool { return clusterRequest.Cluster.Spec.ManagementState == logging.ManagementStateManaged || clusterRequest.Cluster.Spec.ManagementState == "" @@ -47,7 +47,7 @@ func (clusterRequest *ClusterLoggingRequest) Create(object client.Object) error return err } -//Update the runtime Object or return error +// Update the runtime Object or return error func (clusterRequest *ClusterLoggingRequest) Update(object client.Object) (err error) { if err = clusterRequest.Client.Update(context.TODO(), object); err != nil { log.Error(err, "Error updating ", object.GetObjectKind()) diff --git a/internal/k8shandler/status.go b/internal/k8shandler/status.go index decbee303..259dce1d5 100644 --- a/internal/k8shandler/status.go +++ b/internal/k8shandler/status.go @@ -69,7 +69,7 @@ func (clusterRequest *ClusterLoggingRequest) getElasticsearchStatus() ([]logging } err := clusterRequest.List(map[string]string{}, esList) - status := []logging.ElasticsearchStatus{} + var status []logging.ElasticsearchStatus if err != nil { return status, fmt.Errorf("Unable to get Elasticsearches: %v", err)