From a2f0c50945733ce48433316bab7ec0ece524e030 Mon Sep 17 00:00:00 2001 From: Radovan Zvoncek Date: Mon, 22 Jul 2024 19:14:19 +0300 Subject: [PATCH] In tests, don't expect reaper's keyspace if its a STS + allow getting pod specs if reaper not set --- test/e2e/reaper_test.go | 3 ++- test/e2e/suite_test.go | 26 +++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/test/e2e/reaper_test.go b/test/e2e/reaper_test.go index 99ae6ef0c..34bc97745 100644 --- a/test/e2e/reaper_test.go +++ b/test/e2e/reaper_test.go @@ -81,12 +81,13 @@ func createSingleReaper(t *testing.T, ctx context.Context, namespace string, f * f.DeployReaperIngresses(t, f.DataPlaneContexts[0], namespace, dcPrefix+"-reaper-service", reaperRestHostAndPort) defer f.UndeployAllIngresses(t, f.DataPlaneContexts[0], namespace) checkReaperApiReachable(t, ctx, reaperRestHostAndPort) + makeDummyKeyspace(t, f, ctx, f.DataPlaneContexts[0], namespace, kc.SanitizedName(), dcPrefix+"-default-sts-0", "dummy_keyspace") t.Run("TestReaperApi[0]", func(t *testing.T) { t.Log("test Reaper API in context", f.DataPlaneContexts[0]) reaperUiSecretKey := framework.ClusterKey{K8sContext: f.DataPlaneContexts[0], NamespacedName: types.NamespacedName{Namespace: namespace, Name: "mycluster-reaper-ui"}} username, password := retrieveCredentials(t, f, ctx, reaperUiSecretKey) - testReaperApi(t, ctx, f.DataPlaneContexts[0], DcClusterName(t, f, dcKey), "reaper_db", username, password) + testReaperApi(t, ctx, f.DataPlaneContexts[0], DcClusterName(t, f, dcKey), "dummy_keyspace", username, password) }) } diff --git a/test/e2e/suite_test.go b/test/e2e/suite_test.go index b1e2d779c..801170be4 100644 --- a/test/e2e/suite_test.go +++ b/test/e2e/suite_test.go @@ -1973,6 +1973,22 @@ func checkKeyspaceReplication( }, 1*time.Minute, 3*time.Second) } +func makeDummyKeyspace(t *testing.T, + f *framework.E2eFramework, + ctx context.Context, + k8sContext, namespace, clusterName, pod, keyspace string, +) { + assert.Eventually(t, func() bool { + dcKey := framework.ClusterKey{K8sContext: f.DataPlaneContexts[0], NamespacedName: types.NamespacedName{Namespace: namespace, Name: "dc1"}} + _, err := f.ExecuteCql(ctx, k8sContext, namespace, clusterName, pod, "CREATE KEYSPACE reaper_db WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', '"+DcName(t, f, dcKey)+"' : 3} ") + if err != nil { + t.Logf("failed to create keyspace %s: %v", keyspace, err) + return false + } + return true + }, 1*time.Minute, 3*time.Second) +} + // assertCassandraDatacenterK8cStatusReady polls the K8ssandraCluster object, checking its status to // verify the CassandraDatacenter specified by dcName is ready. func assertCassandraDatacenterK8cStatusReady( @@ -2221,11 +2237,15 @@ func checkVectorConfigMapDeleted(t *testing.T, ctx context.Context, f *framework } -func getPodTemplateSpec(t *testing.T, ctx context.Context, f *framework.E2eFramework, dcKey framework.ClusterKey, kc *api.K8ssandraCluster) *corev1.PodTemplateSpec { +func getPodTemplateSpec(t *testing.T, ctx context.Context, f *framework.E2eFramework, appKey framework.ClusterKey, kc *api.K8ssandraCluster) *corev1.PodTemplateSpec { + // this gets called for other pods than reapers (eg stargate). before reaper gained the option of being a STS, everything was a deployment + if kc.Spec.Reaper == nil { + return getPodTemplateSpecForDeployment(t, ctx, f, appKey) + } if kc.Spec.Reaper.StorageType == reaperapi.StorageTypeCassandra { - return getPodTemplateSpecForDeployment(t, ctx, f, dcKey) + return getPodTemplateSpecForDeployment(t, ctx, f, appKey) } else { - return getPodTemplateSpecForStatefulSet(t, ctx, f, dcKey) + return getPodTemplateSpecForStatefulSet(t, ctx, f, appKey) } }