Skip to content

Commit

Permalink
pkg/cluster/spec: add supported configuration for grafana (#1566)
Browse files Browse the repository at this point in the history
  • Loading branch information
haiboumich authored Sep 27, 2021
1 parent 7ad8f97 commit a9a260a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions embed/templates/config/grafana.ini.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ admin_password = {{.Password}}
;login_hint = email or username

# Default UI theme ("dark" or "light")
{{- if .DefaultTheme}}
default_theme = {{.DefaultTheme}}
{{- else}}
;default_theme = dark
{{- end}}

############### Set Cookie Name for Multiple Instances #######################
[auth]
Expand All @@ -182,10 +186,18 @@ enabled = true
{{- end}}

# specify organization name that should be used for unauthenticated users
{{- if .OrgName}}
org_name = {{.OrgName}}
{{- else}}
;org_name = Main Org.
{{- end}}

# specify role for unauthenticated users
{{- if .OrgRole}}
org_role = {{.OrgRole}}
{{- else}}
;org_role = Viewer
{{- end}}

#################################### Basic Auth ##########################
[auth.basic]
Expand Down
6 changes: 6 additions & 0 deletions pkg/cluster/spec/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ type GrafanaSpec struct {
AnonymousEnable bool `yaml:"anonymous_enable" default:"false" validate:"anonymous_enable:editable"`
RootURL string `yaml:"root_url" validate:"root_url:editable"`
Domain string `yaml:"domain" validate:"domain:editable"`
DefaultTheme string `yaml:"default_theme,omitempty" validate:"default_theme:editable"`
OrgName string `yaml:"org_name,omitempty" validate:"org_name:editable"`
OrgRole string `yaml:"org_role,omitempty" validate:"org_role:editable"`
}

// Role returns the component role of the instance
Expand Down Expand Up @@ -166,6 +169,9 @@ func (i *GrafanaInstance) InitConfig(
WithAnonymousenable(spec.AnonymousEnable).
WithRootURL(spec.RootURL).
WithDomain(spec.Domain).
WithDefaultTheme(spec.DefaultTheme).
WithOrgName(spec.OrgName).
WithOrgRole(spec.OrgRole).
ConfigToFile(fp); err != nil {
return err
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/cluster/template/config/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type GrafanaConfig struct {
AnonymousEnable bool // anonymous enable
RootURL string // root_url
Domain string // domain
DefaultTheme string // default_theme
OrgName string // org_name
OrgRole string // org_role
}

// NewGrafanaConfig returns a GrafanaConfig
Expand Down Expand Up @@ -79,6 +82,24 @@ func (c *GrafanaConfig) WithDomain(domain string) *GrafanaConfig {
return c
}

// WithDefaultTheme sets defaultTheme of default theme
func (c *GrafanaConfig) WithDefaultTheme(defaultTheme string) *GrafanaConfig {
c.DefaultTheme = defaultTheme
return c
}

// WithOrgName sets orgName of org name
func (c *GrafanaConfig) WithOrgName(orgName string) *GrafanaConfig {
c.OrgName = orgName
return c
}

// WithOrgRole sets orgName of org role
func (c *GrafanaConfig) WithOrgRole(orgRole string) *GrafanaConfig {
c.OrgRole = orgRole
return c
}

// Config generate the config file data.
func (c *GrafanaConfig) Config() ([]byte, error) {
fp := path.Join("templates", "config", "grafana.ini.tpl")
Expand Down

0 comments on commit a9a260a

Please sign in to comment.