Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add noProxy setting n spec.deployment.httpProxy of Grafana resource #778

Merged
merged 6 commits into from Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions api/integreatly/v1alpha1/grafana_types.go
Expand Up @@ -126,6 +126,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 @@ -4410,6 +4410,8 @@ spec:
properties:
enabled:
type: boolean
noProxy:
type: string
secureUrl:
type: string
url:
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 @@ -5005,6 +5005,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 @@ -11763,6 +11763,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