From 636644ace83042e6328430eaf84caab1076fb730 Mon Sep 17 00:00:00 2001 From: Ayoub Mrini Date: Fri, 17 Oct 2025 12:54:37 +0200 Subject: [PATCH] chore(prometheus/remotewrite): clarify that the in-cluster proxy env vars set in prometheus container can be used in all configs that support proxyConfig.proxyFromEnvironment --- pkg/manifests/manifests.go | 6 ++++-- pkg/manifests/manifests_test.go | 17 +++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/pkg/manifests/manifests.go b/pkg/manifests/manifests.go index 3642321fed..f05e4240d9 100644 --- a/pkg/manifests/manifests.go +++ b/pkg/manifests/manifests.go @@ -1456,7 +1456,8 @@ func (f *Factory) PrometheusK8s(grpcTLS *v1.Secret, telemetrySecret *v1.Secret) for i, container := range p.Spec.Containers { switch container.Name { case "prometheus": - // Inject the proxy env vars into the Prometheus container for configuring external Alertmanagers + // Inject the proxy env vars into the Prometheus container + // Mainly intended for all configs that support proxyConfig.proxyFromEnvironment f.injectProxyVariables(&p.Spec.Containers[i]) case "kube-rbac-proxy", "kube-rbac-proxy-web", "kube-rbac-proxy-thanos": p.Spec.Containers[i].Image = f.config.Images.KubeRbacProxy @@ -1801,7 +1802,8 @@ func (f *Factory) PrometheusUserWorkload(grpcTLS *v1.Secret) (*monv1.Prometheus, PeriodSeconds: 15, FailureThreshold: 240, } - // Inject the proxy env vars into the Prometheus container for configuring external Alertmanagers + // Inject the proxy env vars into the Prometheus container + // Mainly intended for all configs that support proxyConfig.proxyFromEnvironment f.injectProxyVariables(&p.Spec.Containers[i]) case "kube-rbac-proxy-metrics", "kube-rbac-proxy-federate", "kube-rbac-proxy-thanos": p.Spec.Containers[i].Image = f.config.Images.KubeRbacProxy diff --git a/pkg/manifests/manifests_test.go b/pkg/manifests/manifests_test.go index a040194a01..fa779c4484 100644 --- a/pkg/manifests/manifests_test.go +++ b/pkg/manifests/manifests_test.go @@ -1235,6 +1235,7 @@ func TestPrometheusK8sRemoteWriteOauth2(t *testing.T) { "param2": "value2", }, } + expectedOauth2Config.ProxyFromEnvironment = ptr.To(true) c, err := NewConfigFromString(`prometheusK8s: remoteWrite: - url: https://test.remotewrite.com/api/write @@ -1254,6 +1255,7 @@ func TestPrometheusK8sRemoteWriteOauth2(t *testing.T) { endpointParams: param1: value1 param2: value2 + proxyFromEnvironment: true `, false) if err != nil { t.Fatal(err) @@ -1264,18 +1266,9 @@ func TestPrometheusK8sRemoteWriteOauth2(t *testing.T) { &v1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}, nil, ) - if err != nil { - t.Fatal(err) - } - - if p.Spec.RemoteWrite[0].URL != "https://test.remotewrite.com/api/write" { - t.Errorf("want remote write URL https://test.remotewrite.com/api/write, got %v", p.Spec.RemoteWrite[0].URL) - } - - if !reflect.DeepEqual(p.Spec.RemoteWrite[0].OAuth2, &expectedOauth2Config) { - t.Errorf("want OAuth2 config %v, got %v", expectedOauth2Config, p.Spec.RemoteWrite[0].OAuth2) - } - + require.NoError(t, err) + require.Equal(t, p.Spec.RemoteWrite[0].URL, "https://test.remotewrite.com/api/write") + require.Equal(t, p.Spec.RemoteWrite[0].OAuth2, &expectedOauth2Config) } func TestRemoteWriteAuthorizationConfig(t *testing.T) { for _, tc := range []struct {