From e387183cbccee98ae13d5f55bd8649247f37c105 Mon Sep 17 00:00:00 2001 From: Moulick Aggarwal Date: Wed, 9 Mar 2022 17:04:38 +0530 Subject: [PATCH] correct spec.deployment.annotations add the spec.deployment.annotations in grafana CR to the grafana deployment Signed-off-by: Moulick Aggarwal --- Makefile | 2 +- controllers/model/grafanaDeployment.go | 27 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index fc7deedff..27998f85a 100644 --- a/Makefile +++ b/Makefile @@ -208,4 +208,4 @@ catalog-build: opm .PHONY: catalog-push catalog-push: ## Push the catalog image. - $(MAKE) docker-push IMG=$(CATALOG_IMG) \ No newline at end of file + $(MAKE) docker-push IMG=$(CATALOG_IMG) diff --git a/controllers/model/grafanaDeployment.go b/controllers/model/grafanaDeployment.go index 49bcb1842..0cb0612b4 100644 --- a/controllers/model/grafanaDeployment.go +++ b/controllers/model/grafanaDeployment.go @@ -3,15 +3,16 @@ package model import ( "fmt" - "github.com/grafana-operator/grafana-operator/v4/api/integreatly/v1alpha1" - "github.com/grafana-operator/grafana-operator/v4/controllers/config" - "github.com/grafana-operator/grafana-operator/v4/controllers/constants" v1 "k8s.io/api/apps/v1" v13 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" v12 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/grafana-operator/grafana-operator/v4/api/integreatly/v1alpha1" + "github.com/grafana-operator/grafana-operator/v4/controllers/config" + "github.com/grafana-operator/grafana-operator/v4/controllers/constants" ) const ( @@ -124,6 +125,19 @@ func getDeploymentLabels(cr *v1alpha1.Grafana) map[string]string { return labels } +func getDeploymentAnnotations(cr *v1alpha1.Grafana, existing map[string]string) map[string]string { + var annotations = map[string]string{} + // Add fixed annotations + annotations["prometheus.io/scrape"] = "true" + annotations["prometheus.io/port"] = fmt.Sprintf("%v", GetGrafanaPort(cr)) + annotations = MergeAnnotations(annotations, existing) + + if cr.Spec.Deployment != nil { + annotations = MergeAnnotations(cr.Spec.Deployment.Annotations, annotations) + } + return annotations +} + func getRollingUpdateStrategy() *v1.RollingUpdateDeployment { var maxUnaval intstr.IntOrString = intstr.FromInt(25) var maxSurge intstr.IntOrString = intstr.FromInt(25) @@ -720,9 +734,10 @@ func getDeploymentSpec(cr *v1alpha1.Grafana, annotations map[string]string, conf func GrafanaDeployment(cr *v1alpha1.Grafana, configHash, dsHash string) *v1.Deployment { return &v1.Deployment{ ObjectMeta: v12.ObjectMeta{ - Name: constants.GrafanaDeploymentName, - Namespace: cr.Namespace, - Labels: getDeploymentLabels(cr), + Name: constants.GrafanaDeploymentName, + Namespace: cr.Namespace, + Labels: getDeploymentLabels(cr), + Annotations: getDeploymentAnnotations(cr, nil), }, Spec: getDeploymentSpec(cr, nil, configHash, "", dsHash), }