Skip to content

Commit

Permalink
Merge branch 'master' into dashboard-fetch-rate-limit
Browse files Browse the repository at this point in the history
  • Loading branch information
addreas committed Jul 5, 2022
2 parents 741e334 + 6c0c2e4 commit 96dffa6
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 8 deletions.
3 changes: 2 additions & 1 deletion api/integreatly/v1alpha1/grafana_types.go
Expand Up @@ -40,7 +40,7 @@ type GrafanaSpec struct {
ReadinessProbeSpec *ReadinessProbeSpec `json:"readinessProbeSpec,omitempty"`

// DashboardContentCacheDuration sets a default for when a `GrafanaDashboard` resource doesn't specify a `contentCacheDuration`.
// If left unset or 0 the default behaviour is to cache indefinitely.
// If left unset or 0 the default behavior is to cache indefinitely.
DashboardContentCacheDuration *metav1.Duration `json:"dashboardContentCacheDuration,omitempty"`
}

Expand Down Expand Up @@ -130,6 +130,7 @@ type GrafanaHttpProxy struct {
Enabled bool `json:"enabled"`
URL string `json:"url,omitempty"`
SecureURL string `json:"secureUrl,omitempty"`
NoProxy string `json:"noProxy,omitempty"`
}

// GrafanaIngress provides a means to configure the ingress created
Expand Down
2 changes: 1 addition & 1 deletion api/integreatly/v1alpha1/grafanadashboard_types.go
Expand Up @@ -134,7 +134,7 @@ func (d *GrafanaDashboard) Hash() string {
}

if d.Status.Content != "" {
io.WriteString(hash, d.Status.Content)
io.WriteString(hash, d.Status.Content) //nolint
}

return fmt.Sprintf("%x", hash.Sum(nil))
Expand Down
4 changes: 3 additions & 1 deletion config/crd/bases/integreatly.org_grafanas.yaml
Expand Up @@ -1842,7 +1842,7 @@ spec:
dashboardContentCacheDuration:
description: DashboardContentCacheDuration sets a default for when
a `GrafanaDashboard` resource doesn't specify a `contentCacheDuration`.
If left unset or 0 the default behaviour is to cache indefinitely.
If left unset or 0 the default behavior is to cache indefinitely.
type: string
dashboardLabelSelector:
items:
Expand Down Expand Up @@ -4415,6 +4415,8 @@ spec:
properties:
enabled:
type: boolean
noProxy:
type: string
secureUrl:
type: string
url:
Expand Down
10 changes: 8 additions & 2 deletions controllers/grafanadashboard/dashboard_pipeline.go
Expand Up @@ -54,6 +54,9 @@ type DashboardPipelineImpl struct {
}

func NewDashboardPipeline(client client.Client, dashboard *v1alpha1.GrafanaDashboard, ctx context.Context) DashboardPipeline {
if dashboard.Spec.ContentCacheDuration == nil {
dashboard.Spec.ContentCacheDuration = &metav1.Duration{Duration: 24 * time.Hour}
}
return &DashboardPipelineImpl{
Client: client,
Dashboard: dashboard,
Expand Down Expand Up @@ -264,8 +267,11 @@ func (r *DashboardPipelineImpl) loadDashboardFromURL() error {
return nil
}

func (r *DashboardPipelineImpl) refreshDashboard() error {
return r.Client.Get(r.Context, types.NamespacedName{Name: r.Dashboard.Name, Namespace: r.Dashboard.Namespace}, r.Dashboard)
func (r *DashboardPipelineImpl) refreshDashboard() {
err := r.Client.Get(r.Context, types.NamespacedName{Name: r.Dashboard.Name, Namespace: r.Dashboard.Namespace}, r.Dashboard)
if err != nil {
r.Logger.V(1).Error(err, "refreshing dashboard generation failed")
}
}

func (r *DashboardPipelineImpl) loadDashboardFromGrafanaCom() error {
Expand Down
3 changes: 2 additions & 1 deletion controllers/grafanadashboard/grafanadashboard_controller.go
Expand Up @@ -264,7 +264,8 @@ func (r *GrafanaDashboardReconciler) reconcileDashboards(request reconcile.Reque
}

// Process new/updated dashboards
for _, dashboard := range namespaceDashboards.Items {
for i := range namespaceDashboards.Items {
dashboard := namespaceDashboards.Items[i]
// Is this a dashboard we care about (matches the label selectors)?
if !r.isMatch(&dashboard) {
log.Log.Info("dashboard found but selectors do not match",
Expand Down
6 changes: 6 additions & 0 deletions controllers/model/grafanaDeployment.go
Expand Up @@ -578,6 +578,12 @@ func getContainers(cr *v1alpha1.Grafana, configHash, dsHash string) []v13.Contai
Value: cr.Spec.Deployment.HttpProxy.SecureURL,
})
}
if cr.Spec.Deployment.HttpProxy.NoProxy != "" {
envVars = append(envVars, v13.EnvVar{
Name: "NO_PROXY",
Value: cr.Spec.Deployment.HttpProxy.NoProxy,
})
}
}

if cr.Spec.Deployment != nil && cr.Spec.Deployment.Env != nil {
Expand Down
69 changes: 69 additions & 0 deletions controllers/model/grafanaDeployment_test.go
@@ -0,0 +1,69 @@
package model

import (
"testing"

grafanav1alpha1 "github.com/grafana-operator/grafana-operator/v4/api/integreatly/v1alpha1"

"github.com/stretchr/testify/assert"
)

func TestGrafanaDeployment_httpProxy(t *testing.T) {
t.Run("noProxy is setting", func(t *testing.T) {
cr := &grafanav1alpha1.Grafana{
Spec: grafanav1alpha1.GrafanaSpec{
Deployment: &grafanav1alpha1.GrafanaDeployment{
HttpProxy: &grafanav1alpha1.GrafanaHttpProxy{
Enabled: true,
URL: "http://1.2.3.4",
SecureURL: "http://1.2.3.4",
NoProxy: ".svc.cluster.local,.svc",
},
},
},
}
deployment := GrafanaDeployment(cr, "", "")
for _, container := range deployment.Spec.Template.Spec.Containers {
if container.Name != "grafana" {
continue
}

noProxyExist := false
for _, env := range container.Env {
if env.Name == "NO_PROXY" {
noProxyExist = true
assert.Equal(t, ".svc.cluster.local,.svc", env.Value)
}
}
assert.True(t, noProxyExist)
}
})

t.Run("noProxy is not setting", func(t *testing.T) {
cr := &grafanav1alpha1.Grafana{
Spec: grafanav1alpha1.GrafanaSpec{
Deployment: &grafanav1alpha1.GrafanaDeployment{
HttpProxy: &grafanav1alpha1.GrafanaHttpProxy{
Enabled: true,
URL: "http://1.2.3.4",
SecureURL: "http://1.2.3.4",
},
},
},
}
deployment := GrafanaDeployment(cr, "", "")
for _, container := range deployment.Spec.Template.Spec.Containers {
if container.Name != "grafana" {
continue
}

noProxyExist := false
for _, env := range container.Env {
if env.Name == "NO_PROXY" {
noProxyExist = true
}
}
assert.False(t, noProxyExist)
}
})
}
4 changes: 3 additions & 1 deletion deploy/manifests/latest/crds.yaml
Expand Up @@ -2465,7 +2465,7 @@ spec:
dashboardContentCacheDuration:
description: DashboardContentCacheDuration sets a default for when
a `GrafanaDashboard` resource doesn't specify a `contentCacheDuration`.
If left unset or 0 the default behaviour is to cache indefinitely.
If left unset or 0 the default behavior is to cache indefinitely.
type: string
dashboardLabelSelector:
items:
Expand Down Expand Up @@ -5038,6 +5038,8 @@ spec:
properties:
enabled:
type: boolean
noProxy:
type: string
secureUrl:
type: string
url:
Expand Down
9 changes: 8 additions & 1 deletion documentation/api.md
Expand Up @@ -1963,7 +1963,7 @@ Grafana is the Schema for the grafanas API
<td><b>dashboardContentCacheDuration</b></td>
<td>string</td>
<td>
DashboardContentCacheDuration sets a default for when a `GrafanaDashboard` resource doesn't specify a `contentCacheDuration`. If left unset or 0 the default behaviour is to cache indefinitely.<br/>
DashboardContentCacheDuration sets a default for when a `GrafanaDashboard` resource doesn't specify a `contentCacheDuration`. If left unset or 0 the default behavior is to cache indefinitely.<br/>
</td>
<td>false</td>
</tr><tr>
Expand Down Expand Up @@ -11868,6 +11868,13 @@ GrafanaHttpProxy provides a means to configure the Grafana deployment to use an
<br/>
</td>
<td>true</td>
</tr><tr>
<td><b>noProxy</b></td>
<td>string</td>
<td>
<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>secureUrl</b></td>
<td>string</td>
Expand Down

0 comments on commit 96dffa6

Please sign in to comment.