Skip to content

Commit

Permalink
modification in the logic and alignment of test according to the curr…
Browse files Browse the repository at this point in the history
…ent method
  • Loading branch information
Bharadwajshivam28 committed Oct 14, 2024
1 parent 9f9211a commit 09876d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
15 changes: 4 additions & 11 deletions metrics-operator/controllers/common/providers/prometheus/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,12 @@ func (r RoundTripperRetriever) GetRoundTripper(ctx context.Context, provider met
return nil, err
}

baseTransport := promapi.DefaultRoundTripper

if provider.Spec.InsecureSkipTlsVerify {
if httpTransport, ok := baseTransport.(*http.Transport); ok {
newTransport := httpTransport.Clone()
newTransport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
baseTransport = newTransport
}
transport := promapi.DefaultRoundTripper.(*http.Transport).Clone()
transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: provider.Spec.InsecureSkipTlsVerify,
}

return config.NewBasicAuthRoundTripper(secret.User, secret.Password, "", "", baseTransport), nil
return config.NewBasicAuthRoundTripper(secret.User, secret.Password, "", "", transport), nil
}

func getPrometheusSecret(ctx context.Context, provider metricsapi.KeptnMetricsProvider, k8sClient client.Client) (*SecretData, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package prometheus

import (
"context"
"crypto/tls"
"net/http"
"net/http/httptest"
"reflect"
Expand Down Expand Up @@ -137,11 +138,18 @@ func Test_GetRoundtripper(t *testing.T) {
Key: "",
Optional: nil,
},
InsecureSkipTlsVerify: true,
},
},
k8sClient: fake.NewClient(goodsecret),
want: config.NewBasicAuthRoundTripper("myuser", "mytoken", "", "", promapi.DefaultRoundTripper),
wantErr: false,
want: func() http.RoundTripper {
transport := promapi.DefaultRoundTripper.(*http.Transport).Clone()
transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
return config.NewBasicAuthRoundTripper("myuser", "mytoken", "", "", transport)
}(),
wantErr: false,
},
{
name: "TestSecretNotDefined",
Expand Down

0 comments on commit 09876d9

Please sign in to comment.