11package environment
22
33import (
4+ "bufio"
45 "context"
56 "fmt"
67 "github.com/pkg/errors"
78 "github.com/rs/zerolog/log"
89 "helm.sh/helm/v3/pkg/chartutil"
9- "io/ioutil "
10+ "os "
1011 "path/filepath"
1112 "strconv"
1213 "strings"
@@ -214,21 +215,27 @@ func NewMockserverHelmChart() *HelmChart {
214215}
215216
216217// NewPrometheusManifest creates new k8s manifest for prometheus
217- func NewPrometheusManifest () * K8sManifest {
218- rulesFilePath := filepath .Join (tools .ProjectRoot , "/environment/templates/prometheus/rules/ocr.rules.yml" )
219- content , err := ioutil .ReadFile (rulesFilePath )
220- if err != nil {
221- return nil
218+ func NewPrometheusManifest (rules map [string ]* os.File ) * K8sManifest {
219+ vals := map [string ]interface {}{}
220+ for val , file := range rules {
221+ scanner := bufio .NewScanner (file )
222+ var txtlines []string
223+ for scanner .Scan () {
224+ txtlines = append (txtlines , scanner .Text ())
225+ }
226+ for index , line := range txtlines {
227+ txtlines [index ] = fmt .Sprintf (" %s" , line )
228+ }
229+ vals [val ] = strings .Join (txtlines , "\n " )
222230 }
231+
223232 return & K8sManifest {
224233 id : "prometheus" ,
225234 DeploymentFile : filepath .Join (tools .ProjectRoot , "/environment/templates/prometheus/prometheus-deployment.yml" ),
226235 ServiceFile : filepath .Join (tools .ProjectRoot , "/environment/templates/prometheus/prometheus-service.yml" ),
227236 ConfigMapFile : filepath .Join (tools .ProjectRoot , "/environment/templates/prometheus/prometheus-config-map.yml" ),
228237
229- values : map [string ]interface {}{
230- "ocrRulesYml" : string (content ),
231- },
238+ values : vals ,
232239 }
233240}
234241
@@ -546,14 +553,14 @@ func OtpeGroup() K8sEnvSpecInit {
546553}
547554
548555// PrometheusGroup contains manifests for prometheus
549- func PrometheusGroup () K8sEnvSpecInit {
556+ func PrometheusGroup (rules map [ string ] * os. File ) K8sEnvSpecInit {
550557 return func (config * config.NetworkConfig ) (string , K8sEnvSpecs ) {
551558 var specs K8sEnvSpecs
552559 prometheusDependencyGroup := & K8sManifestGroup {
553560 id : "PrometheusDependencyGroup" ,
554- manifests : []K8sEnvResource {NewPrometheusManifest ()},
561+ manifests : []K8sEnvResource {NewPrometheusManifest (rules )},
555562 }
556563 specs = append (specs , prometheusDependencyGroup )
557564 return "" , specs
558565 }
559- }
566+ }
0 commit comments