Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(metrics-operator): introduce insecureSkipTlsVerify parameter for prometheus metrics fetch #3742

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e10b14d
feat: Integrating ELK provider
Bharadwajshivam28 Oct 1, 2024
ba03ab3
feat: Implemented TLS round tripper
Bharadwajshivam28 Oct 5, 2024
68f2271
Removed unwanted folders
Bharadwajshivam28 Oct 5, 2024
a3d0d35
fix: removed unwanted lines form go.mod and go.sum files
Bharadwajshivam28 Oct 5, 2024
4f019d3
modified GetRoundTripper function
Bharadwajshivam28 Oct 9, 2024
f6b8797
modified the common.go file
Bharadwajshivam28 Oct 9, 2024
c42cf6f
feat: modified tls method to use exisiting behavior and allow tls skip
Bharadwajshivam28 Oct 10, 2024
9840512
maintaining original DefaultRoundTripper behavior
Bharadwajshivam28 Oct 14, 2024
bf7a379
modification in the logic and alignment of test according to the curr…
Bharadwajshivam28 Oct 14, 2024
6150139
fix: fixed failure of test_case
Bharadwajshivam28 Oct 14, 2024
f9df3af
modifing test file
Bharadwajshivam28 Oct 14, 2024
c3e3962
changes in test file
Bharadwajshivam28 Oct 14, 2024
c4ecd7e
feat: modifing unit test
Bharadwajshivam28 Oct 14, 2024
4672e23
feat: code
Bharadwajshivam28 Oct 15, 2024
1dd3f1d
fix: removed clone() from the logic
Bharadwajshivam28 Oct 15, 2024
aef152e
feat: modifying unit test
Bharadwajshivam28 Oct 15, 2024
f46b6a2
feat: Added InsecureSkipTlsVerify flag
Bharadwajshivam28 Oct 15, 2024
0024f6f
adding tests in the common_test.go
Bharadwajshivam28 Oct 16, 2024
eea2d14
formatted files
Bharadwajshivam28 Oct 16, 2024
6cc8224
Improvde test case
Bharadwajshivam28 Oct 22, 2024
0013e90
Added username and password parameter
Bharadwajshivam28 Oct 23, 2024
6d639d1
formatted file
Bharadwajshivam28 Oct 23, 2024
aa679a0
Merge branch 'main' into feat/client
thschue Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package prometheus

import (
"context"
"crypto/tls"
"errors"
"net/http"

Expand Down Expand Up @@ -40,7 +41,13 @@ func (r RoundTripperRetriever) GetRoundTripper(ctx context.Context, provider met
}
return nil, err
}
return config.NewBasicAuthRoundTripper(secret.User, secret.Password, "", "", promapi.DefaultRoundTripper), nil

transport := promapi.DefaultRoundTripper.(*http.Transport)
transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: provider.Spec.InsecureSkipTlsVerify,
}

return config.NewBasicAuthRoundTripper(secret.User, secret.Password, "", "", transport), nil
odubajDT marked this conversation as resolved.
Show resolved Hide resolved
}

func getPrometheusSecret(ctx context.Context, provider metricsapi.KeptnMetricsProvider, k8sClient client.Client) (*SecretData, error) {
Expand All @@ -51,7 +58,6 @@ func getPrometheusSecret(ctx context.Context, provider metricsapi.KeptnMetricsPr
if err := k8sClient.Get(ctx, types.NamespacedName{Name: provider.Spec.SecretKeyRef.Name, Namespace: provider.Namespace}, secret); err != nil {
return nil, err
}

var secretData SecretData
user, ok := secret.Data[secretKeyUserName]
pw, yes := secret.Data[secretKeyPassword]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"net/http"
"net/http/httptest"
"reflect"
"strings"
"testing"

Expand Down Expand Up @@ -116,12 +115,14 @@ func Test_GetRoundtripper(t *testing.T) {
},
}
tests := []struct {
name string
provider metricsapi.KeptnMetricsProvider
k8sClient client.Client
want http.RoundTripper
wantErr bool
errorStr string
name string
provider metricsapi.KeptnMetricsProvider
k8sClient client.Client
wantUser string
wantPassword string
Comment on lines +121 to +122
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are not asserting these parameters, can you explain why?

wantRoundTripper http.RoundTripper
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is the roundtripper asserted?

wantErr bool
errorStr string
}{
{
name: "TestSuccess",
Expand All @@ -139,16 +140,20 @@ func Test_GetRoundtripper(t *testing.T) {
},
},
},
k8sClient: fake.NewClient(goodsecret),
want: config.NewBasicAuthRoundTripper("myuser", "mytoken", "", "", promapi.DefaultRoundTripper),
wantErr: false,
k8sClient: fake.NewClient(goodsecret),
wantUser: "myuser",
wantPassword: "mytoken",
wantRoundTripper: config.NewBasicAuthRoundTripper("myuser", "mytoken", "", "", promapi.DefaultRoundTripper),
wantErr: false,
},
{
name: "TestSecretNotDefined",
provider: metricsapi.KeptnMetricsProvider{},
k8sClient: fake.NewClient(),
want: promapi.DefaultRoundTripper,
wantErr: false,
name: "TestSecretNotDefined",
provider: metricsapi.KeptnMetricsProvider{},
k8sClient: fake.NewClient(),
wantUser: "myuser",
wantPassword: "mytoken",
wantRoundTripper: config.NewBasicAuthRoundTripper("myuser", "mytoken", "", "", promapi.DefaultRoundTripper),
wantErr: false,
},
{
name: "TestErrorFromGetPrometheusSecretNotExists",
Expand All @@ -166,10 +171,30 @@ func Test_GetRoundtripper(t *testing.T) {
},
},
},
k8sClient: fake.NewClient(),
want: nil,
wantErr: true,
errorStr: "not found",
k8sClient: fake.NewClient(),
wantUser: "myuser",
wantPassword: "mytoken",
wantRoundTripper: config.NewBasicAuthRoundTripper("myuser", "mytoken", "", "", promapi.DefaultRoundTripper),
wantErr: true,
errorStr: "not found",
},
{
name: "TestInsecureSkipTlsVerifyEnabled",
provider: metricsapi.KeptnMetricsProvider{
ObjectMeta: metav1.ObjectMeta{Namespace: "default"},
Spec: metricsapi.KeptnMetricsProviderSpec{
SecretKeyRef: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: "test",
},
Key: "",
Optional: nil,
},
InsecureSkipTlsVerify: true,
},
},
k8sClient: fake.NewClient(goodsecret),
wantErr: false,
},
}

Expand All @@ -185,8 +210,14 @@ func Test_GetRoundtripper(t *testing.T) {
t.Errorf("getRoundtripper() error = %s, wantErr %s", err.Error(), tt.errorStr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("getRoundtripper() got = %v, want %v", got, tt.want)
if !tt.wantErr && got == nil {
t.Errorf("getRoundtripper() returned nil, expected a RoundTripper")
}
if tr, ok := got.(*http.Transport); ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the insecureSkipVerify is not the only parameter that should be tested here, please test also the user and the password of the round tripper

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@odubajDT I have made the changes please verify it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still only a single parameter is verified here, what about user/password and other parameters set in the struct?

if tr.TLSClientConfig.InsecureSkipVerify != tt.provider.Spec.InsecureSkipTlsVerify {
t.Errorf("RoundTripper TLSClientConfig.InsecureSkipVerify = %v, expected %v",
tr.TLSClientConfig.InsecureSkipVerify, tt.provider.Spec.InsecureSkipTlsVerify)
}
}
})
}
Expand Down
Loading