Skip to content

Commit

Permalink
adding DB password reference to secret (#4)
Browse files Browse the repository at this point in the history
* adding DB password reference to secret

* addresing PR comments
  • Loading branch information
alavrovinfb authored Jul 8, 2020
1 parent f483ffc commit dcf49b7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions deploy/crds/Grafana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,6 @@ spec:
items:
type: object
description: Label selector or match expressions
dbpasswordref:
type: object
description: Reference to DB password secret
1 change: 1 addition & 0 deletions pkg/apis/integreatly/v1alpha1/grafana_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type GrafanaSpec struct {
ServiceAccount *GrafanaServiceAccount `json:"serviceAccount,omitempty"`
Client *GrafanaClient `json:"client,omitempty"`
Compat *GrafanaCompat `json:"compat"`
DBPasswordRef *v1.SecretKeySelector `json:"dbpasswordref,omitempty"`
}

// Backwards compatibility switches
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/integreatly/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/controller/model/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ const (
GrafanaAdminPasswordEnvVar = "GF_SECURITY_ADMIN_PASSWORD"
GrafanaHttpPort int = 3000
GrafanaHttpPortName = "grafana"
GrafanaDBPasswordEnvVar = "GF_DATABASE_PASSWORD"
)
15 changes: 13 additions & 2 deletions pkg/controller/model/grafanaDeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package model

import (
"fmt"

"github.com/integr8ly/grafana-operator/v3/pkg/apis/integreatly/v1alpha1"
"github.com/integr8ly/grafana-operator/v3/pkg/controller/config"
v1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -296,7 +297,7 @@ func getContainers(cr *v1alpha1.Grafana, configHash, dsHash string) []v13.Contai
image := cfg.GetConfigString(config.ConfigGrafanaImage, GrafanaImage)
tag := cfg.GetConfigString(config.ConfigGrafanaImageTag, GrafanaVersion)

containers = append(containers, v13.Container{
container := v13.Container{
Name: "grafana",
Image: fmt.Sprintf("%s:%s", image, tag),
Args: []string{"-config=/etc/grafana/grafana.ini"},
Expand Down Expand Up @@ -347,8 +348,18 @@ func getContainers(cr *v1alpha1.Grafana, configHash, dsHash string) []v13.Contai
TerminationMessagePath: "/dev/termination-log",
TerminationMessagePolicy: "File",
ImagePullPolicy: "IfNotPresent",
})
}

if cr.Spec.DBPasswordRef != nil {
envRef := v13.EnvVar{
Name: GrafanaDBPasswordEnvVar,
ValueFrom: &v13.EnvVarSource{
SecretKeyRef: cr.Spec.DBPasswordRef,
},
}
container.Env = append(container.Env, envRef)
}
containers = append(containers, container)
// Add extra containers
for _, container := range cr.Spec.Containers {
container.VolumeMounts = getExtraContainerVolumeMounts(cr, container.VolumeMounts)
Expand Down

0 comments on commit dcf49b7

Please sign in to comment.