Skip to content

Commit 3845c52

Browse files
committed
Add proxyURL
Signed-off-by: Mario Fernandez <[email protected]>
1 parent 884f872 commit 3845c52

File tree

9 files changed

+234
-13
lines changed

9 files changed

+234
-13
lines changed

assets/prometheus-k8s/prometheus.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,14 @@ spec:
154154
volumeMounts:
155155
- mountPath: /etc/tls/grpc
156156
name: secret-grpc-tls
157-
- name: prometheus
157+
- env:
158+
- name: HTTP_PROXY
159+
value: ""
160+
- name: HTTPS_PROXY
161+
value: ""
162+
- name: NO_PROXY
163+
value: ""
164+
name: prometheus
158165
terminationMessagePolicy: FallbackToLogsOnError
159166
volumeMounts:
160167
- mountPath: /etc/pki/ca-trust/extracted/pem/

assets/prometheus-user-workload/prometheus.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,14 @@ spec:
168168
volumeMounts:
169169
- mountPath: /etc/tls/grpc
170170
name: secret-grpc-tls
171-
- name: prometheus
171+
- env:
172+
- name: HTTP_PROXY
173+
value: ""
174+
- name: HTTPS_PROXY
175+
value: ""
176+
- name: NO_PROXY
177+
value: ""
178+
name: prometheus
172179
terminationMessagePolicy: FallbackToLogsOnError
173180
volumeMounts:
174181
- mountPath: /etc/pki/ca-trust/extracted/pem/

assets/thanos-ruler/thanos-ruler.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ spec:
2424
key: alertmanagers.yaml
2525
name: thanos-ruler-alertmanagers-config
2626
containers:
27+
- env:
28+
- name: HTTP_PROXY
29+
value: ""
30+
- name: HTTPS_PROXY
31+
value: ""
32+
- name: NO_PROXY
33+
value: ""
34+
name: thanos-ruler
35+
terminationMessagePolicy: FallbackToLogsOnError
2736
- name: thanos-ruler
2837
securityContext:
2938
allowPrivilegeEscalation: false

jsonnet/components/prometheus-user-workload.libsonnet

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,16 @@ function(params)
563563
// See e.g pkg/manifests/manifests.go where the startup probe is added
564564
{
565565
name: 'prometheus',
566+
env: [{
567+
name: 'HTTP_PROXY',
568+
value: '',
569+
}, {
570+
name: 'HTTPS_PROXY',
571+
value: '',
572+
}, {
573+
name: 'NO_PROXY',
574+
value: '',
575+
}],
566576
volumeMounts+: [
567577
{
568578
name: $.trustedCaBundle.metadata.name,

jsonnet/components/prometheus.libsonnet

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,16 @@ function(params)
562562
},
563563
{
564564
name: 'prometheus',
565+
env: [{
566+
name: 'HTTP_PROXY',
567+
value: '',
568+
}, {
569+
name: 'HTTPS_PROXY',
570+
value: '',
571+
}, {
572+
name: 'NO_PROXY',
573+
value: '',
574+
}],
565575
volumeMounts+: [
566576
{
567577
name: $.trustedCaBundle.metadata.name,

jsonnet/components/thanos-ruler.libsonnet

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,19 @@ function(params)
431431
serviceAccountName: tr.config.name,
432432
priorityClassName: 'openshift-user-critical',
433433
containers: [
434+
{
435+
name: 'thanos-ruler',
436+
env: [{
437+
name: 'HTTP_PROXY',
438+
value: '',
439+
}, {
440+
name: 'HTTPS_PROXY',
441+
value: '',
442+
}, {
443+
name: 'NO_PROXY',
444+
value: '',
445+
}],
446+
},
434447
{
435448
// Note: this is performing strategic-merge-patch for thanos-ruler
436449
// container. the rest of the container configuration is managed by

pkg/manifests/amcfg.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ func (a PrometheusAdditionalAlertmanagerConfigs) MarshalYAML() (interface{}, err
2929

3030
// amConfigPrometheus is our internal representation of the Prometheus alerting configuration.
3131
type amConfigPrometheus struct {
32-
Scheme string `yaml:"scheme,omitempty"`
33-
PathPrefix string `yaml:"path_prefix,omitempty"`
34-
Timeout *string `yaml:"timeout,omitempty"`
35-
APIVersion string `yaml:"api_version,omitempty"`
36-
Authorization amConfigAuthorization `yaml:"authorization,omitempty"`
37-
TLSConfig amConfigTLS `yaml:"tls_config,omitempty"`
38-
StaticConfigs []amConfigStaticConfigs `yaml:"static_configs,omitempty"`
32+
Scheme string `yaml:"scheme,omitempty"`
33+
PathPrefix string `yaml:"path_prefix,omitempty"`
34+
Timeout *string `yaml:"timeout,omitempty"`
35+
APIVersion string `yaml:"api_version,omitempty"`
36+
Authorization amConfigAuthorization `yaml:"authorization,omitempty"`
37+
TLSConfig amConfigTLS `yaml:"tls_config,omitempty"`
38+
StaticConfigs []amConfigStaticConfigs `yaml:"static_configs,omitempty"`
39+
ProxyFromEnvironment bool `yaml:"proxy_from_environment,omitempty"`
3940
}
4041

4142
type amConfigAuthorization struct {
@@ -64,10 +65,11 @@ type prometheusAdditionalAlertmanagerConfig AdditionalAlertmanagerConfig
6465
// compatible with the Prometheus configuration.
6566
func (a prometheusAdditionalAlertmanagerConfig) MarshalYAML() (interface{}, error) {
6667
cfg := amConfigPrometheus{
67-
Scheme: a.Scheme,
68-
PathPrefix: a.PathPrefix,
69-
Timeout: a.Timeout,
70-
APIVersion: a.APIVersion,
68+
Scheme: a.Scheme,
69+
PathPrefix: a.PathPrefix,
70+
Timeout: a.Timeout,
71+
APIVersion: a.APIVersion,
72+
ProxyFromEnvironment: true,
7173
TLSConfig: amConfigTLS{
7274
CA: "",
7375
Cert: "",
@@ -126,6 +128,7 @@ type thanosAlertmanagerConfiguration struct {
126128
APIVersion string `yaml:"api_version,omitempty"`
127129
HTTPConfig amHTTPConfig `yaml:"http_config,omitempty"`
128130
StaticConfigs []string `yaml:"static_configs,omitempty"`
131+
ProxyURL string `yaml:"proxy_url,omitempty"`
129132
}
130133

131134
type amHTTPConfig struct {
@@ -183,6 +186,8 @@ func ConvertToThanosAlertmanagerConfiguration(ta []AdditionalAlertmanagerConfig)
183186
result[i] = cfg
184187
}
185188

189+
// todo mariofer proxyURL
190+
186191
return result, nil
187192
}
188193

pkg/manifests/manifests.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,8 @@ func (f *Factory) PrometheusK8s(grpcTLS *v1.Secret, telemetrySecret *v1.Secret)
14601460

14611461
for i, container := range p.Spec.Containers {
14621462
switch container.Name {
1463+
case "prometheus":
1464+
f.injectProxyVariables(&p.Spec.Containers[i])
14631465
case "kube-rbac-proxy", "kube-rbac-proxy-web", "kube-rbac-proxy-thanos":
14641466
p.Spec.Containers[i].Image = f.config.Images.KubeRbacProxy
14651467
p.Spec.Containers[i].Args = f.setTLSSecurityConfiguration(container.Args, KubeRbacProxyTLSCipherSuitesFlag, KubeRbacProxyMinTLSVersionFlag)
@@ -1795,6 +1797,7 @@ func (f *Factory) PrometheusUserWorkload(grpcTLS *v1.Secret) (*monv1.Prometheus,
17951797
FailureThreshold: 240,
17961798
}
17971799

1800+
f.injectProxyVariables(&p.Spec.Containers[i])
17981801
case "kube-rbac-proxy-metrics", "kube-rbac-proxy-federate", "kube-rbac-proxy-thanos":
17991802
p.Spec.Containers[i].Image = f.config.Images.KubeRbacProxy
18001803
p.Spec.Containers[i].Args = f.setTLSSecurityConfiguration(container.Args, KubeRbacProxyTLSCipherSuitesFlag, KubeRbacProxyMinTLSVersionFlag)
@@ -3222,6 +3225,8 @@ func (f *Factory) ThanosRulerCustomResource(
32223225

32233226
for i, container := range t.Spec.Containers {
32243227
switch container.Name {
3228+
case "thanos-ruler":
3229+
f.injectProxyVariables(&t.Spec.Containers[i])
32253230
case "kube-rbac-proxy-metrics", "kube-rbac-proxy-web":
32263231
t.Spec.Containers[i].Image = f.config.Images.KubeRbacProxy
32273232
t.Spec.Containers[i].Args = f.setTLSSecurityConfiguration(container.Args, KubeRbacProxyTLSCipherSuitesFlag, KubeRbacProxyMinTLSVersionFlag)

pkg/manifests/manifests_test.go

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,6 +2162,23 @@ func TestPrometheusK8sAdditionalAlertManagerConfigsSecret(t *testing.T) {
21622162
`,
21632163
mountedSecrets: []string{"alertmanager-bearer-token", "alertmanager-ca-tls", "alertmanager-cert-tls", "alertmanager-key-tls"},
21642164
},
2165+
{
2166+
name: "proxy from environment",
2167+
config: `prometheusK8s:
2168+
additionalAlertmanagerConfigs:
2169+
- staticConfigs:
2170+
- alertmanager1-remote.com
2171+
- alertmanager1-remotex.com
2172+
proxyFromEnvironment: true
2173+
`,
2174+
expected: `- static_configs:
2175+
- targets:
2176+
- alertmanager1-remote.com
2177+
- alertmanager1-remotex.com
2178+
proxy_from_environment: true
2179+
`,
2180+
mountedSecrets: []string{},
2181+
},
21652182
}
21662183

21672184
for _, tt := range testCases {
@@ -4919,6 +4936,144 @@ func TestAlertmanagerProxy(t *testing.T) {
49194936
}
49204937
}
49214938

4939+
func TestPrometheusProxy(t *testing.T) {
4940+
for _, tc := range []struct {
4941+
proxyReader ProxyReader
4942+
assertFn func(*testing.T, *v1.Container)
4943+
}{
4944+
{
4945+
proxyReader: &fakeProxyReader{},
4946+
assertFn: func(t *testing.T, c *v1.Container) {
4947+
t.Helper()
4948+
4949+
require.Len(t, c.Env, 3)
4950+
require.Equal(t, c.Env[0].Value, "")
4951+
require.Equal(t, c.Env[1].Value, "")
4952+
require.Equal(t, c.Env[2].Value, "")
4953+
},
4954+
},
4955+
{
4956+
proxyReader: &fakeProxyReader{
4957+
httpProxy: "http://example.com:8080/",
4958+
httpsProxy: "https://example.com:8080/",
4959+
noProxy: "local.example.com",
4960+
},
4961+
assertFn: func(t *testing.T, c *v1.Container) {
4962+
t.Helper()
4963+
4964+
require.Len(t, c.Env, 3)
4965+
require.Equal(t, c.Env[0].Name, "HTTP_PROXY")
4966+
require.Equal(t, c.Env[0].Value, "http://example.com:8080/")
4967+
require.Equal(t, c.Env[1].Name, "HTTPS_PROXY")
4968+
require.Equal(t, c.Env[1].Value, "https://example.com:8080/")
4969+
require.Equal(t, c.Env[2].Name, "NO_PROXY")
4970+
require.Equal(t, c.Env[2].Value, "local.example.com")
4971+
},
4972+
},
4973+
} {
4974+
t.Run("", func(t *testing.T) {
4975+
findContainer := func(am *monv1.Prometheus) *v1.Container {
4976+
for _, c := range am.Spec.Containers {
4977+
if c.Name == "prometheus" {
4978+
return &c
4979+
}
4980+
}
4981+
4982+
return nil
4983+
}
4984+
4985+
f := NewFactory("openshift-monitoring", "openshift-user-workload-monitoring", NewDefaultConfig(), defaultInfrastructureReader(), tc.proxyReader, NewAssets(assetsPath), &APIServerConfig{}, &configv1.Console{})
4986+
4987+
t.Run("main", func(t *testing.T) {
4988+
p, err := f.PrometheusK8s(
4989+
&v1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
4990+
nil,
4991+
)
4992+
require.NoError(t, err)
4993+
4994+
amc := findContainer(p)
4995+
require.NotNil(t, amc)
4996+
tc.assertFn(t, amc)
4997+
})
4998+
4999+
t.Run("user", func(t *testing.T) {
5000+
p, err := f.PrometheusUserWorkload(
5001+
&v1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
5002+
)
5003+
require.NoError(t, err)
5004+
5005+
pc := findContainer(p)
5006+
require.NotNil(t, pc)
5007+
tc.assertFn(t, pc)
5008+
})
5009+
})
5010+
}
5011+
}
5012+
5013+
func TestThanosRulerProxy(t *testing.T) {
5014+
for _, tc := range []struct {
5015+
proxyReader ProxyReader
5016+
assertFn func(*testing.T, *v1.Container)
5017+
}{
5018+
{
5019+
proxyReader: &fakeProxyReader{},
5020+
assertFn: func(t *testing.T, c *v1.Container) {
5021+
t.Helper()
5022+
5023+
require.Len(t, c.Env, 3)
5024+
require.Equal(t, c.Env[0].Value, "")
5025+
require.Equal(t, c.Env[1].Value, "")
5026+
require.Equal(t, c.Env[2].Value, "")
5027+
},
5028+
},
5029+
{
5030+
proxyReader: &fakeProxyReader{
5031+
httpProxy: "http://example.com:8080/",
5032+
httpsProxy: "https://example.com:8080/",
5033+
noProxy: "local.example.com",
5034+
},
5035+
assertFn: func(t *testing.T, c *v1.Container) {
5036+
t.Helper()
5037+
5038+
require.Len(t, c.Env, 3)
5039+
require.Equal(t, c.Env[0].Name, "HTTP_PROXY")
5040+
require.Equal(t, c.Env[0].Value, "http://example.com:8080/")
5041+
require.Equal(t, c.Env[1].Name, "HTTPS_PROXY")
5042+
require.Equal(t, c.Env[1].Value, "https://example.com:8080/")
5043+
require.Equal(t, c.Env[2].Name, "NO_PROXY")
5044+
require.Equal(t, c.Env[2].Value, "local.example.com")
5045+
},
5046+
},
5047+
} {
5048+
t.Run("", func(t *testing.T) {
5049+
findContainer := func(am *monv1.ThanosRuler) *v1.Container {
5050+
for _, c := range am.Spec.Containers {
5051+
if c.Name == "thanos-ruler" {
5052+
return &c
5053+
}
5054+
}
5055+
5056+
return nil
5057+
}
5058+
5059+
f := NewFactory("openshift-monitoring", "openshift-user-workload-monitoring", NewDefaultConfig(), defaultInfrastructureReader(), tc.proxyReader, NewAssets(assetsPath), &APIServerConfig{}, &configv1.Console{})
5060+
5061+
t.Run("main", func(t *testing.T) {
5062+
tr, err := f.ThanosRulerCustomResource(
5063+
&v1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
5064+
nil,
5065+
)
5066+
require.NoError(t, err)
5067+
5068+
trc := findContainer(tr)
5069+
require.NotNil(t, trc)
5070+
tc.assertFn(t, trc)
5071+
})
5072+
5073+
})
5074+
}
5075+
}
5076+
49225077
func TestDescriptionWithoutPlaceholder(t *testing.T) {
49235078
tests := []struct {
49245079
name string

0 commit comments

Comments
 (0)