1
0
mirror of https://github.com/coreos/prometheus-operator.git synced 2026-02-05 06:45:27 +01:00

chore: unify HTTP configuration for ServiceMonitor CRD (#8139)

* chore: unify HTTP configuration for ServiceMonitor CRD

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* test: fix Alertmanager unit tests

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* test: fix Prometheus unit tests

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* test: fix e2e tests

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* test: fix pkg/apis/monitoring tests

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

---------

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier
2025-12-19 13:11:51 +01:00
committed by GitHub
parent 00165220bf
commit 4fc65465fa
29 changed files with 2237 additions and 1135 deletions

View File

@@ -1785,28 +1785,30 @@ func testUserDefinedAlertmanagerConfigFromCustomResource(t *testing.T) {
ResolveTimeout: "30s",
HTTPConfigWithProxy: &monitoringv1.HTTPConfigWithProxy{
HTTPConfig: monitoringv1.HTTPConfig{
OAuth2: &monitoringv1.OAuth2{
ClientID: monitoringv1.SecretOrConfigMap{
ConfigMap: &v1.ConfigMapKeySelector{
HTTPConfigWithoutTLS: monitoringv1.HTTPConfigWithoutTLS{
OAuth2: &monitoringv1.OAuth2{
ClientID: monitoringv1.SecretOrConfigMap{
ConfigMap: &v1.ConfigMapKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: "webhook-client-id",
},
Key: "test",
},
},
ClientSecret: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: "webhook-client-id",
Name: "webhook-client-secret",
},
Key: "test",
},
},
ClientSecret: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: "webhook-client-secret",
TokenURL: "https://test.com",
Scopes: []string{"any"},
EndpointParams: map[string]string{
"some": "value",
},
Key: "test",
},
TokenURL: "https://test.com",
Scopes: []string{"any"},
EndpointParams: map[string]string{
"some": "value",
},
FollowRedirects: ptr.To(true),
},
FollowRedirects: ptr.To(true),
},
},
},

View File

@@ -139,31 +139,36 @@ func deployInstrumentedApplicationWithTLS(name, ns string) error {
Port: "mtls",
Interval: "1s",
Scheme: ptr.To(monitoringv1.SchemeHTTPS),
TLSConfig: &monitoringv1.TLSConfig{
SafeTLSConfig: monitoringv1.SafeTLSConfig{
ServerName: ptr.To("caandserver.com"),
CA: monitoringv1.SecretOrConfigMap{
Secret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: testFramework.ScrapingTLSSecret,
HTTPConfigWithProxyAndTLSFiles: monitoringv1.HTTPConfigWithProxyAndTLSFiles{
HTTPConfigWithTLSFiles: monitoringv1.HTTPConfigWithTLSFiles{
TLSConfig: &monitoringv1.TLSConfig{
SafeTLSConfig: monitoringv1.SafeTLSConfig{
ServerName: ptr.To("caandserver.com"),
CA: monitoringv1.SecretOrConfigMap{
Secret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: testFramework.ScrapingTLSSecret,
},
Key: testFramework.CAKey,
},
},
Key: testFramework.CAKey,
},
},
Cert: monitoringv1.SecretOrConfigMap{
Secret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: testFramework.ScrapingTLSSecret,
Cert: monitoringv1.SecretOrConfigMap{
Secret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: testFramework.ScrapingTLSSecret,
},
Key: testFramework.CertKey,
},
},
KeySecret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: testFramework.ScrapingTLSSecret,
},
Key: testFramework.PrivateKey,
},
Key: testFramework.CertKey,
},
},
KeySecret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: testFramework.ScrapingTLSSecret,
},
Key: testFramework.PrivateKey,
},
},
},
},
@@ -2980,11 +2985,17 @@ func testPromArbitraryFSAcc(t *testing.T) {
},
endpoint: monitoringv1.Endpoint{
Port: "web",
BearerTokenSecret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
HTTPConfigWithProxyAndTLSFiles: monitoringv1.HTTPConfigWithProxyAndTLSFiles{
HTTPConfigWithTLSFiles: monitoringv1.HTTPConfigWithTLSFiles{
HTTPConfigWithoutTLS: monitoringv1.HTTPConfigWithoutTLS{
BearerTokenSecret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
},
Key: "bearer-token",
},
},
},
Key: "bearer-token",
},
},
expectTargets: true,
@@ -2999,10 +3010,16 @@ func testPromArbitraryFSAcc(t *testing.T) {
},
endpoint: monitoringv1.Endpoint{
Port: "web",
TLSConfig: &monitoringv1.TLSConfig{
CAFile: "/etc/ca-certificates/cert.pem",
CertFile: "/etc/ca-certificates/cert.pem",
KeyFile: "/etc/ca-certificates/key.pem",
HTTPConfigWithProxyAndTLSFiles: monitoringv1.HTTPConfigWithProxyAndTLSFiles{
HTTPConfigWithTLSFiles: monitoringv1.HTTPConfigWithTLSFiles{
TLSConfig: &monitoringv1.TLSConfig{
TLSFilesConfig: monitoringv1.TLSFilesConfig{
CAFile: "/etc/ca-certificates/cert.pem",
CertFile: "/etc/ca-certificates/cert.pem",
KeyFile: "/etc/ca-certificates/key.pem",
},
},
},
},
},
expectTargets: true,
@@ -3014,10 +3031,16 @@ func testPromArbitraryFSAcc(t *testing.T) {
},
endpoint: monitoringv1.Endpoint{
Port: "web",
TLSConfig: &monitoringv1.TLSConfig{
CAFile: "/etc/ca-certificates/cert.pem",
CertFile: "/etc/ca-certificates/cert.pem",
KeyFile: "/etc/ca-certificates/key.pem",
HTTPConfigWithProxyAndTLSFiles: monitoringv1.HTTPConfigWithProxyAndTLSFiles{
HTTPConfigWithTLSFiles: monitoringv1.HTTPConfigWithTLSFiles{
TLSConfig: &monitoringv1.TLSConfig{
TLSFilesConfig: monitoringv1.TLSFilesConfig{
CAFile: "/etc/ca-certificates/cert.pem",
CertFile: "/etc/ca-certificates/cert.pem",
KeyFile: "/etc/ca-certificates/key.pem",
},
},
},
},
},
expectTargets: false,
@@ -3029,31 +3052,35 @@ func testPromArbitraryFSAcc(t *testing.T) {
},
endpoint: monitoringv1.Endpoint{
Port: "web",
TLSConfig: &monitoringv1.TLSConfig{
SafeTLSConfig: monitoringv1.SafeTLSConfig{
InsecureSkipVerify: ptr.To(true),
CA: monitoringv1.SecretOrConfigMap{
Secret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
HTTPConfigWithProxyAndTLSFiles: monitoringv1.HTTPConfigWithProxyAndTLSFiles{
HTTPConfigWithTLSFiles: monitoringv1.HTTPConfigWithTLSFiles{
TLSConfig: &monitoringv1.TLSConfig{
SafeTLSConfig: monitoringv1.SafeTLSConfig{
InsecureSkipVerify: ptr.To(true),
CA: monitoringv1.SecretOrConfigMap{
Secret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
},
Key: "cert.pem",
},
},
Key: "cert.pem",
},
},
Cert: monitoringv1.SecretOrConfigMap{
Secret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
Cert: monitoringv1.SecretOrConfigMap{
Secret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
},
Key: "cert.pem",
},
},
KeySecret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
},
Key: "key.pem",
},
Key: "cert.pem",
},
},
KeySecret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
},
Key: "key.pem",
},
},
},
},
@@ -3066,31 +3093,35 @@ func testPromArbitraryFSAcc(t *testing.T) {
},
endpoint: monitoringv1.Endpoint{
Port: "web",
TLSConfig: &monitoringv1.TLSConfig{
SafeTLSConfig: monitoringv1.SafeTLSConfig{
InsecureSkipVerify: ptr.To(true),
CA: monitoringv1.SecretOrConfigMap{
ConfigMap: &v1.ConfigMapKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
HTTPConfigWithProxyAndTLSFiles: monitoringv1.HTTPConfigWithProxyAndTLSFiles{
HTTPConfigWithTLSFiles: monitoringv1.HTTPConfigWithTLSFiles{
TLSConfig: &monitoringv1.TLSConfig{
SafeTLSConfig: monitoringv1.SafeTLSConfig{
InsecureSkipVerify: ptr.To(true),
CA: monitoringv1.SecretOrConfigMap{
ConfigMap: &v1.ConfigMapKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
},
Key: "cert.pem",
},
},
Key: "cert.pem",
},
},
Cert: monitoringv1.SecretOrConfigMap{
ConfigMap: &v1.ConfigMapKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
Cert: monitoringv1.SecretOrConfigMap{
ConfigMap: &v1.ConfigMapKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
},
Key: "cert.pem",
},
},
KeySecret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
},
Key: "key.pem",
},
Key: "cert.pem",
},
},
KeySecret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
},
Key: "key.pem",
},
},
},
},
@@ -3322,23 +3353,27 @@ func testPromTLSConfigViaSecret(t *testing.T) {
Port: "mtls",
Interval: "30s",
Scheme: ptr.To(monitoringv1.SchemeHTTPS),
TLSConfig: &monitoringv1.TLSConfig{
SafeTLSConfig: monitoringv1.SafeTLSConfig{
InsecureSkipVerify: ptr.To(true),
Cert: monitoringv1.SecretOrConfigMap{
Secret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: tlsCertsSecret.Name,
HTTPConfigWithProxyAndTLSFiles: monitoringv1.HTTPConfigWithProxyAndTLSFiles{
HTTPConfigWithTLSFiles: monitoringv1.HTTPConfigWithTLSFiles{
TLSConfig: &monitoringv1.TLSConfig{
SafeTLSConfig: monitoringv1.SafeTLSConfig{
InsecureSkipVerify: ptr.To(true),
Cert: monitoringv1.SecretOrConfigMap{
Secret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: tlsCertsSecret.Name,
},
Key: "cert.pem",
},
},
KeySecret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: tlsCertsSecret.Name,
},
Key: "key.pem",
},
Key: "cert.pem",
},
},
KeySecret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: tlsCertsSecret.Name,
},
Key: "key.pem",
},
},
},
},
@@ -3485,18 +3520,20 @@ func testPromSecurePodMonitor(t *testing.T) {
Port: ptr.To("web"),
HTTPConfigWithProxy: monitoringv1.HTTPConfigWithProxy{
HTTPConfig: monitoringv1.HTTPConfig{
BasicAuth: &monitoringv1.BasicAuth{
Username: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
HTTPConfigWithoutTLS: monitoringv1.HTTPConfigWithoutTLS{
BasicAuth: &monitoringv1.BasicAuth{
Username: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
},
Key: "user",
},
Key: "user",
},
Password: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
Password: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
},
Key: "password",
},
Key: "password",
},
},
},
@@ -3512,11 +3549,13 @@ func testPromSecurePodMonitor(t *testing.T) {
Port: ptr.To("web"),
HTTPConfigWithProxy: monitoringv1.HTTPConfigWithProxy{
HTTPConfig: monitoringv1.HTTPConfig{
BearerTokenSecret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
HTTPConfigWithoutTLS: monitoringv1.HTTPConfigWithoutTLS{
BearerTokenSecret: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
},
Key: "bearer-token",
},
Key: "bearer-token",
},
},
},
@@ -5570,14 +5609,20 @@ func testPrometheusUTF8MetricsSupport(t *testing.T) {
Endpoints: []monitoringv1.Endpoint{{
Port: "web",
Interval: "30s",
BasicAuth: &monitoringv1.BasicAuth{
Username: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{Name: "basic-auth"},
Key: "username",
},
Password: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{Name: "basic-auth"},
Key: "password",
HTTPConfigWithProxyAndTLSFiles: monitoringv1.HTTPConfigWithProxyAndTLSFiles{
HTTPConfigWithTLSFiles: monitoringv1.HTTPConfigWithTLSFiles{
HTTPConfigWithoutTLS: monitoringv1.HTTPConfigWithoutTLS{
BasicAuth: &monitoringv1.BasicAuth{
Username: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{Name: "basic-auth"},
Key: "username",
},
Password: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{Name: "basic-auth"},
Key: "password",
},
},
},
},
},
}},
@@ -5801,14 +5846,20 @@ func testPrometheusUTF8LabelSupport(t *testing.T) {
TargetLabel: "service_clustér_label",
Action: "replace",
}},
BasicAuth: &monitoringv1.BasicAuth{
Username: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{Name: "basic-auth"},
Key: "username",
},
Password: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{Name: "basic-auth"},
Key: "password",
HTTPConfigWithProxyAndTLSFiles: monitoringv1.HTTPConfigWithProxyAndTLSFiles{
HTTPConfigWithTLSFiles: monitoringv1.HTTPConfigWithTLSFiles{
HTTPConfigWithoutTLS: monitoringv1.HTTPConfigWithoutTLS{
BasicAuth: &monitoringv1.BasicAuth{
Username: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{Name: "basic-auth"},
Key: "username",
},
Password: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{Name: "basic-auth"},
Key: "password",
},
},
},
},
},
}},

View File

@@ -351,9 +351,8 @@ func (f *Framework) MakeBasicServiceMonitor(name string) *monitoringv1.ServiceMo
},
Endpoints: []monitoringv1.Endpoint{
{
Port: "web",
Interval: "30s",
BearerTokenSecret: &v1.SecretKeySelector{},
Port: "web",
Interval: "30s",
},
},
},