Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions controllers/logging/elasticsearch_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (r *ElasticsearchReconciler) Reconcile(request ctrl.Request) (ctrl.Result,
if apierrors.IsNotFound(err) {
log.Info("Flushing nodes", "objectKey", request.NamespacedName)
k8shandler.FlushNodes(request.NamespacedName.Name, request.NamespacedName.Namespace)
k8shandler.RemoveDashboardConfigMap(r.Client)
return ctrl.Result{}, nil
}

Expand Down
27 changes: 23 additions & 4 deletions internal/k8shandler/dashboards.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package k8shandler

import (
"context"
"io/ioutil"

"github.com/ViaQ/logerr/kverrors"
"github.com/ViaQ/logerr/log"
"github.com/openshift/elasticsearch-operator/internal/utils"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
defaultElasticDashboardFile = "/etc/elasticsearch-operator/files/dashboards/logging-dashboard-elasticsearch.json"
grafanaCMName = "grafana-dashboard-elasticsearch"
grafanaCMNameSpace = "openshift-config-managed"
)

// CreateOrUpdateDashboards creates/updates the cluster logging dashboard ConfigMap
Expand All @@ -26,8 +32,8 @@ func (er *ElasticsearchRequest) CreateOrUpdateDashboards() error {
APIVersion: v1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "grafana-dashboard-elasticsearch",
Namespace: "openshift-config-managed",
Name: grafanaCMName,
Namespace: grafanaCMNameSpace,
Labels: map[string]string{
"console.openshift.io/dashboard": "true",
},
Expand All @@ -37,7 +43,20 @@ func (er *ElasticsearchRequest) CreateOrUpdateDashboards() error {
},
}

er.cluster.AddOwnerRefTo(cm)

return er.CreateOrUpdateConfigMap(cm)
}

// RemoveDashboardConfigMap removes the config map in the grafana dashboard
func RemoveDashboardConfigMap(client client.Client) {
cm := getConfigmap(grafanaCMName, grafanaCMNameSpace, client)
if cm == nil {
return
}
err := client.Delete(context.TODO(), cm)
if err != nil {
if apierrors.IsNotFound(err) {
return
}
log.Error(err, "error deleting grafana configmap")
}
}