Skip to content

Commit

Permalink
Merge pull request #39 from integr8ly/customize-pod-label
Browse files Browse the repository at this point in the history
Customize pod label
  • Loading branch information
pb82 authored Aug 28, 2019
2 parents 46ed4ce + 73bf5ea commit 3106d08
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var flagImage string
var flagImageTag string
var flagPluginsInitContainerImage string
var flagPluginsInitContainerTag string
var flagPodLabelValue string
var scanAll bool
var openshift bool

Expand All @@ -44,6 +45,7 @@ func init() {
flagset.StringVar(&flagImageTag, "grafana-image-tag", "", "Overrides the default Grafana image tag")
flagset.StringVar(&flagPluginsInitContainerImage, "grafana-plugins-init-container-image", "", "Overrides the default Grafana Plugins Init Container image")
flagset.StringVar(&flagPluginsInitContainerTag, "grafana-plugins-init-container-tag", "", "Overrides the default Grafana Plugins Init Container tag")
flagset.StringVar(&flagPodLabelValue, "pod-label-value", common.PodLabelDefaultValue, "Overrides the default value of the app label")
flagset.BoolVar(&scanAll, "scan-all", false, "Scans all namespaces for dashboards")
flagset.BoolVar(&openshift, "openshift", false, "Use Route instead of Ingress")
flagset.Parse(os.Args[1:])
Expand Down Expand Up @@ -96,6 +98,7 @@ func main() {
controllerConfig.AddConfigItem(common.ConfigGrafanaImageTag, flagImageTag)
controllerConfig.AddConfigItem(common.ConfigPluginsInitContainerImage, flagPluginsInitContainerImage)
controllerConfig.AddConfigItem(common.ConfigPluginsInitContainerTag, flagPluginsInitContainerTag)
controllerConfig.AddConfigItem(common.ConfigPodLabelValue, flagPodLabelValue)
controllerConfig.AddConfigItem(common.ConfigOperatorNamespace, namespace)
controllerConfig.AddConfigItem(common.ConfigDashboardLabelSelector, "")
controllerConfig.AddConfigItem(common.ConfigOpenshift, openshift)
Expand Down
2 changes: 2 additions & 0 deletions documentation/deploy_grafana.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ The operator accepts a number of flags that can be passed in the `args` section
* *--grafana-plugins-init-container-tag*: overrides the Grafana Plugins Init Container tag, defaults to `0.0.2`.
* *--scan-all*: watch for dashboards in all namespaces. This requires the the operator service account to have cluster wide permissions to `get`, `list`, `update` and `watch` dashboards. See `deploy/cluster_roles`.
* *--openshift*: force the operator to use a [route](https://docs.openshift.com/container-platform/3.11/architecture/networking/routes.html) instead of an [ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/). Note that routes are only supported on OpenShift.
* *--pod-label-value*: override the value of the `app` label that gets attached to pods and other resources.


See `deploy/operator.yaml` for an example.

Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/common/controller_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
ConfigGrafanaImageTag = "grafana.image.tag"
ConfigPluginsInitContainerImage = "grafana.plugins.init.container.image.url"
ConfigPluginsInitContainerTag = "grafana.plugins.init.container.image.tag"
ConfigPodLabelValue = "grafana.pod.label"
ConfigOperatorNamespace = "grafana.operator.namespace"
ConfigDashboardLabelSelector = "grafana.dashboard.selector"
ConfigGrafanaPluginsUpdated = "grafana.plugins.updated"
Expand Down Expand Up @@ -41,6 +42,7 @@ const (
InitContainerName = "grafana-plugins-init"
ResourceFinalizerName = "grafana.cleanup"
RequeueDelay = time.Second * 15
PodLabelDefaultValue = "grafana"
)

type ControllerConfig struct {
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/common/kubeHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ func (h KubeHelperImpl) DeleteDashboard(d *v1alpha1.GrafanaDashboard) error {
}

func (h KubeHelperImpl) getGrafanaPod(namespaceName string) (*core.Pod, error) {
podLabel := h.config.GetConfigString(ConfigPodLabelValue, PodLabelDefaultValue)

opts := metav1.ListOptions{
LabelSelector: "app=grafana",
LabelSelector: fmt.Sprintf("app=%s", podLabel),
}

pods, err := h.k8client.CoreV1().Pods(namespaceName).List(opts)
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/grafana/templateHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type GrafanaParamaeters struct {
Hostname string
AdminUser string
AdminPassword string
PodLabelValue string
BasicAuth bool
DisableLoginForm bool
DisableSignoutMenu bool
Expand Down Expand Up @@ -102,6 +103,7 @@ func newTemplateHelper(cr *integreatly.Grafana) *TemplateHelper {
DisableLoginForm: cr.Spec.DisableLoginForm,
DisableSignoutMenu: cr.Spec.DisableSignoutMenu,
Anonymous: cr.Spec.Anonymous,
PodLabelValue: controllerConfig.GetConfigString(common.ConfigPodLabelValue, common.PodLabelDefaultValue),
}

templatePath := os.Getenv("TEMPLATE_PATH")
Expand Down
6 changes: 3 additions & 3 deletions templates/grafana-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: grafana
app: {{ .PodLabelValue }}
name: {{ .GrafanaDeploymentName }}
namespace: {{ .Namespace }}
spec:
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: grafana
app: {{ .PodLabelValue }}
strategy:
rollingUpdate:
maxSurge: 1
Expand All @@ -20,7 +20,7 @@ spec:
metadata:
creationTimestamp: null
labels:
app: grafana
app: {{ .PodLabelValue }}
name: grafana
spec:
initContainers:
Expand Down
2 changes: 1 addition & 1 deletion templates/grafana-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: {{ .GrafanaIngressName }}
namespace: {{ .Namespace }}
labels:
app: grafana
app: {{ .PodLabelValue }}
spec:
rules:
- host: {{ .Hostname }}
Expand Down
2 changes: 1 addition & 1 deletion templates/grafana-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ spec:
protocol: TCP
targetPort: grafana-http
selector:
app: grafana
app: {{ .PodLabelValue }}

0 comments on commit 3106d08

Please sign in to comment.