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 ad4b486
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/integreatly/v1alpha1/grafana_types.go
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: 2 additions & 0 deletions config/crd/bases/integreatly.org_grafanas.yaml
Expand Up @@ -4415,6 +4415,8 @@ spec:
properties:
enabled:
type: boolean
noProxy:
type: string
secureUrl:
type: string
url:
Expand Down
3 changes: 3 additions & 0 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
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)
}
})
}
2 changes: 2 additions & 0 deletions deploy/manifests/latest/crds.yaml
Expand Up @@ -5038,6 +5038,8 @@ spec:
properties:
enabled:
type: boolean
noProxy:
type: string
secureUrl:
type: string
url:
Expand Down
7 changes: 7 additions & 0 deletions documentation/api.md
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 ad4b486

Please sign in to comment.