Skip to content

Commit

Permalink
Merge pull request #8 from pb82/configurable-image
Browse files Browse the repository at this point in the history
Configurable image
  • Loading branch information
pb82 committed Apr 24, 2019
2 parents 47a0985 + ef21071 commit c1b4237
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ORG=integr8ly
NAMESPACE=application-monitoring
ORG=integreatly
NAMESPACE=middleware-monitoring
PROJECT=grafana-operator
REG=quay.io
SHELL=/bin/bash
Expand Down
17 changes: 15 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"flag"
"fmt"
"github.com/integr8ly/grafana-operator/pkg/controller/grafana"
"os"
"runtime"

Expand All @@ -21,16 +22,23 @@ import (
)

var log = logf.Log.WithName("cmd")
var flagImage string
var flagImageTag string

func printVersion() {
log.Info(fmt.Sprintf("Go Version: %s", runtime.Version()))
log.Info(fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH))
log.Info(fmt.Sprintf("operator-sdk Version: %v", sdkVersion.Version))
}

func main() {
flag.Parse()
func init() {
flagset := flag.CommandLine
flagset.StringVar(&flagImage, "grafana-image", "", "Overrides the default Grafana image")
flagset.StringVar(&flagImageTag, "grafana-image-tag", "", "Overrides the default Grafana image tag")
flagset.Parse(os.Args[1:])
}

func main() {
// The logger instantiated here can be changed to any logger
// implementing the logr.Logger interface. This logger will
// be propagated through the whole operator, generating
Expand All @@ -39,6 +47,11 @@ func main() {

printVersion()

// Controller configuration
controllerConfig := grafana.GetControllerConfig()
controllerConfig.AddConfigItem(grafana.ConfigGrafanaImage, flagImage)
controllerConfig.AddConfigItem(grafana.ConfigGrafanaImageTag, flagImageTag)

namespace, err := k8sutil.GetWatchNamespace()
if err != nil {
log.Error(err, "failed to get watch namespace")
Expand Down
42 changes: 42 additions & 0 deletions pkg/controller/grafana/controller_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package grafana

import "sync"

const (
ConfigGrafanaImage = "grafana.image.url"
ConfigGrafanaImageTag = "grafana.image.tag"
)

type ControllerConfig struct {
Values map[string]string
}

var instance *ControllerConfig
var once sync.Once

func GetControllerConfig() *ControllerConfig {
once.Do(func() {
instance = &ControllerConfig{
Values: map[string]string{},
}
})
return instance
}

func (c *ControllerConfig) AddConfigItem(key, value string) {
if key != "" && value != "" {
c.Values[key] = value
}
}

func (c *ControllerConfig) GetConfigItem(key, defaultValue string) string {
if c.HasConfigItem(key) {
return c.Values[key]
}
return defaultValue
}

func (c *ControllerConfig) HasConfigItem(key string) bool {
_, ok := c.Values[key]
return ok
}
6 changes: 4 additions & 2 deletions pkg/controller/grafana/templateHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ type GrafanaTemplateHelper struct {
// templates properties. Some of them (like the hostname) are set
// by the user in the custom resource
func newTemplateHelper(cr *integreatly.Grafana) *GrafanaTemplateHelper {
controllerConfig := GetControllerConfig()

param := GrafanaParamaeters{
GrafanaImage: GrafanaImage,
GrafanaVersion: GrafanaVersion,
GrafanaImage: controllerConfig.GetConfigItem(ConfigGrafanaImage, GrafanaImage),
GrafanaVersion: controllerConfig.GetConfigItem(ConfigGrafanaImageTag, GrafanaVersion),
Namespace: cr.Namespace,
GrafanaConfigMapName: GrafanaConfigMapName,
GrafanaProvidersConfigMapName: GrafanaProvidersConfigMapName,
Expand Down

0 comments on commit c1b4237

Please sign in to comment.