diff --git a/metrics-operator/controllers/common/providers/prometheus/common.go b/metrics-operator/controllers/common/providers/prometheus/common.go index f3f8e8fa7a6..ce7bd1e28ca 100644 --- a/metrics-operator/controllers/common/providers/prometheus/common.go +++ b/metrics-operator/controllers/common/providers/prometheus/common.go @@ -4,12 +4,13 @@ import ( "context" "crypto/tls" "errors" + "net/http" + metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1" promapi "github.com/prometheus/client_golang/api" "github.com/prometheus/common/config" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" - "net/http" "sigs.k8s.io/controller-runtime/pkg/client" ) diff --git a/metrics-operator/controllers/common/providers/prometheus/common_test.go b/metrics-operator/controllers/common/providers/prometheus/common_test.go index 92b27bd11a0..e92b23cc80f 100644 --- a/metrics-operator/controllers/common/providers/prometheus/common_test.go +++ b/metrics-operator/controllers/common/providers/prometheus/common_test.go @@ -128,7 +128,8 @@ func Test_GetRoundtripper(t *testing.T) { provider: metricsapi.KeptnMetricsProvider{ ObjectMeta: metav1.ObjectMeta{Namespace: "default"}, Spec: metricsapi.KeptnMetricsProviderSpec{ - TargetServer: "someTargetServer", + Type: "", + TargetServer: "", SecretKeyRef: v1.SecretKeySelector{ LocalObjectReference: v1.LocalObjectReference{ Name: "test", @@ -136,13 +137,40 @@ func Test_GetRoundtripper(t *testing.T) { Key: "", Optional: nil, }, - InsecureSkipTlsVerify: false, }, }, k8sClient: fake.NewClient(goodsecret), want: config.NewBasicAuthRoundTripper("myuser", "mytoken", "", "", promapi.DefaultRoundTripper), wantErr: false, }, + { + name: "TestSecretNotDefined", + provider: metricsapi.KeptnMetricsProvider{}, + k8sClient: fake.NewClient(), + want: promapi.DefaultRoundTripper, + wantErr: false, + }, + { + name: "TestErrorFromGetPrometheusSecretNotExists", + provider: metricsapi.KeptnMetricsProvider{ + ObjectMeta: metav1.ObjectMeta{Namespace: "default"}, + Spec: metricsapi.KeptnMetricsProviderSpec{ + Type: "", + TargetServer: "", + SecretKeyRef: v1.SecretKeySelector{ + LocalObjectReference: v1.LocalObjectReference{ + Name: "test", + }, + Key: "", + Optional: nil, + }, + }, + }, + k8sClient: fake.NewClient(), + want: nil, + wantErr: true, + errorStr: "not found", + }, { name: "TestInsecureSkipTlsVerifyEnabled", provider: metricsapi.KeptnMetricsProvider{