Skip to content

Commit f13d161

Browse files
committed
Add external Prometheus on OpenShift E2E
1 parent 2cf276f commit f13d161

File tree

1 file changed

+112
-7
lines changed

1 file changed

+112
-7
lines changed

test/e2e/set/scylladbmonitoring/scylladbmonitoring.go

Lines changed: 112 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
corev1 "k8s.io/api/core/v1"
4040
rbacv1 "k8s.io/api/rbac/v1"
4141
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
42-
"k8s.io/apimachinery/pkg/util/intstr"
42+
apimachineryutilintstr "k8s.io/apimachinery/pkg/util/intstr"
4343
"k8s.io/client-go/util/cert"
4444
"k8s.io/klog/v2"
4545
)
@@ -71,7 +71,7 @@ var _ = g.Describe("ScyllaDBMonitoring", func() {
7171
f := framework.NewFramework("scylladbmonitoring")
7272

7373
// Disabled on OpenShift because of https://github.com/scylladb/scylla-operator/issues/2319#issuecomment-2643287819
74-
g.DescribeTable("should setup monitoring stack TESTCASE_DISABLED_ON_OPENSHIFT", func(ctx g.SpecContext, e *scyllaDBMonitoringEntry) {
74+
g.DescribeTable("should setup monitoring stack", func(ctx g.SpecContext, e *scyllaDBMonitoringEntry) {
7575
framework.By("Creating a ScyllaCluster with a single node")
7676
sc := createTestScyllaCluster(ctx, f)
7777

@@ -89,8 +89,10 @@ var _ = g.Describe("ScyllaDBMonitoring", func() {
8989
framework.By("Waiting for the ScyllaDBMonitoring to roll out")
9090
awaitScyllaDBMonitoringRollout(ctx, f, sm)
9191

92-
framework.By("Verifying that Prometheus is configured correctly")
93-
e.VerifyPrometheusFn(ctx, f, sm)
92+
if e.VerifyPrometheusFn != nil {
93+
framework.By("Verifying that Prometheus is configured correctly")
94+
e.VerifyPrometheusFn(ctx, f, sm)
95+
}
9496

9597
framework.By("Verifying that Grafana is configured correctly")
9698
e.VerifyGrafanaFn(ctx, f, sm)
@@ -147,7 +149,7 @@ var _ = g.Describe("ScyllaDBMonitoring", func() {
147149
VerifyPrometheusFn: verifyExternalPrometheusWithoutTLS,
148150
VerifyGrafanaFn: verifyManagedGrafanaWithDashboards(getExpectedPlatformDashboards()),
149151
}),
150-
g.FEntry(describeEntry, &scyllaDBMonitoringEntry{
152+
g.Entry(describeEntry, &scyllaDBMonitoringEntry{
151153
Description: "Platform type with external Prometheus with TLS",
152154
ScyllaDBMonitoringModifierFn: func(sm *scyllav1alpha1.ScyllaDBMonitoring) {
153155
sm.Spec.Type = pointer.Ptr(scyllav1alpha1.ScyllaDBMonitoringTypePlatform)
@@ -173,6 +175,40 @@ var _ = g.Describe("ScyllaDBMonitoring", func() {
173175
VerifyPrometheusFn: verifyExternalPrometheusWithTLS,
174176
VerifyGrafanaFn: verifyManagedGrafanaWithDashboards(getExpectedPlatformDashboards()),
175177
}),
178+
g.FEntry(describeEntry, &scyllaDBMonitoringEntry{
179+
Description: "Platform type with Thanos Querier on OpenShift",
180+
ScyllaDBMonitoringModifierFn: func(sm *scyllav1alpha1.ScyllaDBMonitoring) {
181+
sm.Spec.Components.Prometheus.Mode = scyllav1alpha1.PrometheusModeExternal
182+
sm.Spec.Components.Grafana.Datasources = []scyllav1alpha1.GrafanaDatasourceSpec{
183+
{
184+
Name: "prometheus",
185+
Type: scyllav1alpha1.GrafanaDatasourceTypePrometheus,
186+
URL: "https://thanos-querier.openshift-monitoring.svc:9091",
187+
PrometheusOptions: &scyllav1alpha1.GrafanaPrometheusDatasourceOptions{
188+
TLS: &scyllav1alpha1.GrafanaDatasourceTLSSpec{
189+
InsecureSkipVerify: false,
190+
CACertConfigMapRef: &scyllav1alpha1.LocalObjectKeySelector{
191+
Name: "openshift-service-ca.crt",
192+
Key: "service-ca.crt",
193+
},
194+
},
195+
Auth: &scyllav1alpha1.GrafanaPrometheusDatasourceAuthSpec{
196+
Type: scyllav1alpha1.GrafanaPrometheusDatasourceAuthTypeBearerToken,
197+
BearerTokenOptions: &scyllav1alpha1.GrafanaPrometheusDatasourceBearerTokenAuthOptions{
198+
SecretRef: &scyllav1alpha1.LocalObjectKeySelector{
199+
Name: monitoringAccessServiceAccountNameOnOpenShift(sm),
200+
Key: "token",
201+
},
202+
},
203+
},
204+
},
205+
},
206+
}
207+
},
208+
PrepareExternalPrometheusFn: prepareOpenShiftMonitoring,
209+
VerifyPrometheusFn: nil, // Nothing to verify, we trust OpenShift.
210+
VerifyGrafanaFn: verifyManagedGrafanaWithDashboards(getExpectedPlatformDashboards()),
211+
}),
176212
)
177213
})
178214

@@ -753,7 +789,7 @@ func createExternalPrometheusInstanceWithoutTLS(ctx context.Context, f *framewor
753789
Alertmanagers: []monitoringv1.AlertmanagerEndpoints{
754790
{
755791
Name: "scylla-monitoring",
756-
Port: intstr.FromString("web"),
792+
Port: apimachineryutilintstr.FromString("web"),
757793
},
758794
},
759795
},
@@ -821,7 +857,7 @@ func createExternalPrometheusInstanceWithTLS(ctx context.Context, f *framework.F
821857
Alertmanagers: []monitoringv1.AlertmanagerEndpoints{
822858
{
823859
Name: "scylla-monitoring",
824-
Port: intstr.FromString("web"),
860+
Port: apimachineryutilintstr.FromString("web"),
825861
},
826862
},
827863
},
@@ -839,6 +875,71 @@ func createExternalPrometheusInstanceWithTLS(ctx context.Context, f *framework.F
839875
return prom
840876
}
841877

878+
func prepareOpenShiftMonitoring(ctx context.Context, f *framework.Framework, sm *scyllav1alpha1.ScyllaDBMonitoring) {
879+
g.GinkgoHelper()
880+
881+
framework.By("Creating a ServiceAccount for monitoring access on OpenShift")
882+
sa := createMonitoringAccessServiceAccountOnOpenShift(ctx, f, sm)
883+
884+
framework.By("Binding cluster-monitoring-view ClusterRole to the ServiceAccount")
885+
bindClusterMonitoringViewClusterRoleToServiceAccount(ctx, f, sa)
886+
887+
framework.By("Creating a Secret with the ServiceAccount token")
888+
createServiceAccountTokenSecret(ctx, f, sa)
889+
}
890+
891+
func createMonitoringAccessServiceAccountOnOpenShift(ctx context.Context, f *framework.Framework, sm *scyllav1alpha1.ScyllaDBMonitoring) *corev1.ServiceAccount {
892+
sa, err := f.KubeAdminClient().CoreV1().ServiceAccounts(f.Namespace()).Create(ctx, &corev1.ServiceAccount{
893+
ObjectMeta: metav1.ObjectMeta{
894+
Name: monitoringAccessServiceAccountNameOnOpenShift(sm),
895+
Namespace: f.Namespace(),
896+
},
897+
}, metav1.CreateOptions{
898+
FieldManager: f.FieldManager(),
899+
})
900+
o.Expect(err).NotTo(o.HaveOccurred())
901+
return sa
902+
}
903+
904+
func bindClusterMonitoringViewClusterRoleToServiceAccount(ctx context.Context, f *framework.Framework, sa *corev1.ServiceAccount) {
905+
_, err := f.KubeAdminClient().RbacV1().ClusterRoleBindings().Create(ctx, &rbacv1.ClusterRoleBinding{
906+
ObjectMeta: metav1.ObjectMeta{
907+
Name: sa.Name,
908+
},
909+
Subjects: []rbacv1.Subject{
910+
{
911+
Kind: rbacv1.ServiceAccountKind,
912+
Name: sa.Name,
913+
Namespace: sa.Namespace,
914+
},
915+
},
916+
RoleRef: rbacv1.RoleRef{
917+
APIGroup: "rbac.authorization.k8s.io",
918+
Kind: "ClusterRole",
919+
Name: "cluster-monitoring-view",
920+
},
921+
}, metav1.CreateOptions{
922+
FieldManager: f.FieldManager(),
923+
})
924+
o.Expect(err).NotTo(o.HaveOccurred())
925+
}
926+
927+
func createServiceAccountTokenSecret(ctx context.Context, f *framework.Framework, sa *corev1.ServiceAccount) {
928+
_, err := f.KubeAdminClient().CoreV1().Secrets(f.Namespace()).Create(ctx, &corev1.Secret{
929+
ObjectMeta: metav1.ObjectMeta{
930+
Name: sa.Name,
931+
Namespace: f.Namespace(),
932+
Annotations: map[string]string{
933+
"kubernetes.io/service-account.name": sa.Name,
934+
},
935+
},
936+
Type: corev1.SecretTypeServiceAccountToken,
937+
}, metav1.CreateOptions{
938+
FieldManager: f.FieldManager(),
939+
})
940+
o.Expect(err).NotTo(o.HaveOccurred())
941+
}
942+
842943
func verifyExternalPrometheusWithoutTLS(ctx context.Context, f *framework.Framework, sm *scyllav1alpha1.ScyllaDBMonitoring) {
843944
g.GinkgoHelper()
844945

@@ -927,3 +1028,7 @@ func prometheusCACertConfigMapNameForScyllaDBMonitoring(sm *scyllav1alpha1.Scyll
9271028
func prometheusTLSSecretNameForScyllaDBMonitoring(sm *scyllav1alpha1.ScyllaDBMonitoring) string {
9281029
return fmt.Sprintf("%s-prometheus-tls", sm.Name)
9291030
}
1031+
1032+
func monitoringAccessServiceAccountNameOnOpenShift(sm *scyllav1alpha1.ScyllaDBMonitoring) string {
1033+
return fmt.Sprintf("%s-monitoring-access", sm.Name)
1034+
}

0 commit comments

Comments
 (0)