Skip to content

Commit 51c9e05

Browse files
committed
add review comments
Signed-off-by: Mario Fernandez <[email protected]>
1 parent 2a67c3f commit 51c9e05

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

pkg/manifests/amcfg.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package manifests
22

33
import (
44
"fmt"
5+
"net/url"
56

7+
"golang.org/x/net/http/httpproxy"
68
v1 "k8s.io/api/core/v1"
79
)
810

@@ -183,16 +185,30 @@ func (f *Factory) ConvertToThanosAlertmanagerConfiguration(ta []AdditionalAlertm
183185

184186
cfg.StaticConfigs = a.StaticConfigs
185187

186-
switch cfg.Scheme {
187-
case "http":
188-
if proxy := f.proxy.HTTPProxy(); proxy != "" {
189-
cfg.ProxyURL = proxy
188+
httpConfig := httpproxy.Config{
189+
HTTPProxy: f.proxy.HTTPProxy(),
190+
HTTPSProxy: f.proxy.HTTPSProxy(),
191+
NoProxy: f.proxy.NoProxy(),
192+
}
193+
194+
proxyFunc := httpConfig.ProxyFunc()
195+
196+
if len(cfg.StaticConfigs) > 0 && cfg.StaticConfigs[0] != "" {
197+
u := &url.URL{
198+
Scheme: cfg.Scheme,
199+
Host: cfg.StaticConfigs[0],
190200
}
191-
case "https":
192-
if proxy := f.proxy.HTTPSProxy(); proxy != "" {
193-
cfg.ProxyURL = proxy
201+
202+
proxyURL, err := proxyFunc(u)
203+
if err != nil {
204+
return nil, err
205+
}
206+
207+
if proxyURL != nil {
208+
cfg.ProxyURL = proxyURL.String()
194209
}
195210
}
211+
196212
result[i] = cfg
197213
}
198214

pkg/manifests/manifests_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,6 +2533,33 @@ func TestThanosRulerAdditionalAlertManagerConfigsSecret(t *testing.T) {
25332533
- alertmanager1-remote.com
25342534
- alertmanager1-remotex.com
25352535
proxy_url: http://example.com:8080/
2536+
`,
2537+
},
2538+
{
2539+
name: "no proxy",
2540+
userWorkloadConfig: `thanosRuler:
2541+
additionalAlertmanagerConfigs:
2542+
- apiVersion: v2
2543+
pathPrefix: /path-prefix
2544+
scheme: http
2545+
staticConfigs:
2546+
- local.example.com
2547+
`,
2548+
expected: `alertmanagers:
2549+
- scheme: https
2550+
api_version: v2
2551+
http_config:
2552+
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
2553+
tls_config:
2554+
ca_file: /etc/prometheus/configmaps/serving-certs-ca-bundle/service-ca.crt
2555+
server_name: alertmanager-main.openshift-monitoring.svc
2556+
static_configs:
2557+
- dnssrv+_web._tcp.alertmanager-operated.openshift-monitoring.svc
2558+
- scheme: http
2559+
path_prefix: /path-prefix
2560+
api_version: v2
2561+
static_configs:
2562+
- local.example.com
25362563
`,
25372564
},
25382565
}

0 commit comments

Comments
 (0)