From b357f31fb373c02e07e7f0049fe4387dec1b7ca1 Mon Sep 17 00:00:00 2001 From: Radovan Zvoncek Date: Fri, 17 Jan 2025 16:28:33 +0200 Subject: [PATCH] K8OP-303 Use namespaced service name when registering k8ssandra cluster to Reaper --- CHANGELOG/CHANGELOG-1.21.md | 3 +- pkg/reaper/manager.go | 3 +- test/e2e/cluster_scope_test.go | 22 +++++++++++++ .../multi-dc-cluster-scope/k8ssandra.yaml | 6 ++++ .../multi-dc-cluster-scope/kustomization.yaml | 1 + .../multi-dc-cluster-scope/reaper.yaml | 31 +++++++++++++++++++ 6 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 test/testdata/fixtures/multi-dc-cluster-scope/reaper.yaml diff --git a/CHANGELOG/CHANGELOG-1.21.md b/CHANGELOG/CHANGELOG-1.21.md index 3e2a9a65c..3162c799b 100644 --- a/CHANGELOG/CHANGELOG-1.21.md +++ b/CHANGELOG/CHANGELOG-1.21.md @@ -22,4 +22,5 @@ When cutting a new release, update the `unreleased` heading to the tag being gen * [BUGFIX] [#1454](https://github.com/k8ssandra/k8ssandra-operator/issues/1454) Do not try to work out backup status if there are no pods * [BUGFIX] [#1383](https://github.com/k8ssandra/k8ssandra-operator/issues/1383) Do not create MedusaBackup if MedusaBakupJob did not fully succeed * [BUGFIX] [#1460](https://github.com/k8ssandra/k8ssandra-operator/issues/1460) Fix podName calculations in medusa's hostmap.go to account for unbalanced racks also -* [BUGFIX] [#1466](https://github.com/k8ssandra/k8ssandra-operator/issues/1466) Do not overwrite existing status fields or forget to write the changes. Also, add new ContextName for the Datacenter to know where it used to be. \ No newline at end of file +* [BUGFIX] [#1466](https://github.com/k8ssandra/k8ssandra-operator/issues/1466) Do not overwrite existing status fields or forget to write the changes. Also, add new ContextName for the Datacenter to know where it used to be. +* [BUGFIX] [#1471](https://github.com/k8ssandra/k8ssandra-operator/issues/1471) Use namespaced service name when registering k8ssandra cluster to Reaper diff --git a/pkg/reaper/manager.go b/pkg/reaper/manager.go index d8287b0fb..d5d9a99c3 100644 --- a/pkg/reaper/manager.go +++ b/pkg/reaper/manager.go @@ -68,7 +68,8 @@ func (r *restReaperManager) connect(ctx context.Context, reaperSvc, username, pa } func (r *restReaperManager) AddClusterToReaper(ctx context.Context, cassdc *cassdcapi.CassandraDatacenter) error { - return r.reaperClient.AddCluster(ctx, cassdcapi.CleanupForKubernetes(cassdc.Spec.ClusterName), cassdc.GetSeedServiceName()) + namespacedServiceName := cassdc.GetSeedServiceName() + "." + cassdc.Namespace + return r.reaperClient.AddCluster(ctx, cassdcapi.CleanupForKubernetes(cassdc.Spec.ClusterName), namespacedServiceName) } func (r *restReaperManager) VerifyClusterIsConfigured(ctx context.Context, cassdc *cassdcapi.CassandraDatacenter) (bool, error) { diff --git a/test/e2e/cluster_scope_test.go b/test/e2e/cluster_scope_test.go index 7cdd913e2..8d732d458 100644 --- a/test/e2e/cluster_scope_test.go +++ b/test/e2e/cluster_scope_test.go @@ -15,6 +15,7 @@ func multiDcMultiCluster(t *testing.T, ctx context.Context, klusterNamespace str dc1Namespace := "test-1" dc2Namespace := "test-2" + reaperNamespace := "k8ssandra-operator" t.Log("check that the K8ssandraCluster was created") k8ssandra := &api.K8ssandraCluster{} @@ -84,4 +85,25 @@ func multiDcMultiCluster(t *testing.T, ctx context.Context, klusterNamespace str t.Log("check nodes in dc2 see nodes in dc1") pod = DcPrefix(t, f, dc2Key) + "-rack1-sts-0" checkNodeToolStatus(t, f, f.DataPlaneContexts[1], dc2Namespace, pod, count, 0, "-u", username, "-pw", password) + + t.Log("check that cluster was registered in Reaper") + reaperKey := framework.ClusterKey{K8sContext: f.ControlPlaneContext, NamespacedName: types.NamespacedName{Namespace: reaperNamespace, Name: "reaper1"}} + dcKey := framework.ClusterKey{K8sContext: f.DataPlaneContexts[0], NamespacedName: types.NamespacedName{Namespace: dc1Namespace, Name: "dc1"}} + dcPrefix := DcPrefix(t, f, dcKey) + checkReaperReady(t, f, ctx, reaperKey) + checkDatacenterReady(t, ctx, dcKey, f) + createKeyspaceAndTable(t, f, ctx, f.DataPlaneContexts[0], k8ssandra.Namespace, k8ssandra.Name, dcPrefix+"-default-sts-0", "test_ks", "test_table", 2) + + t.Log("deploying Reaper ingress routes in context", f.ControlPlaneContext) + reaperRestHostAndPort := ingressConfigs[f.ControlPlaneContext].ReaperRest + f.DeployReaperIngresses(t, f.ControlPlaneContext, k8ssandra.Namespace, "reaper1-service", reaperRestHostAndPort) + defer f.UndeployAllIngresses(t, f.ControlPlaneContext, k8ssandra.Namespace) + checkReaperApiReachable(t, ctx, reaperRestHostAndPort) + + t.Run("TestReaperApi[0]", func(t *testing.T) { + t.Log("test Reaper API in context", f.ControlPlaneContext) + secretKey := framework.ClusterKey{K8sContext: f.ControlPlaneContext, NamespacedName: types.NamespacedName{Namespace: k8ssandra.Namespace, Name: "reaper-ui-secret"}} + username, password := retrieveCredentials(t, f, ctx, secretKey) + testReaperApi(t, ctx, f.ControlPlaneContext, DcClusterName(t, f, dcKey), "test_ks", username, password) + }) } diff --git a/test/testdata/fixtures/multi-dc-cluster-scope/k8ssandra.yaml b/test/testdata/fixtures/multi-dc-cluster-scope/k8ssandra.yaml index f4d545db9..4aa17e826 100644 --- a/test/testdata/fixtures/multi-dc-cluster-scope/k8ssandra.yaml +++ b/test/testdata/fixtures/multi-dc-cluster-scope/k8ssandra.yaml @@ -69,3 +69,9 @@ spec: nodeAffinityLabels: "topology.kubernetes.io/zone": region2-zone2 mgmtAPIHeap: 64Mi + reaper: + reaperRef: + name: reaper1 + namespace: k8ssandra-operator + uiUserSecretRef: + name: reaper-ui-secret diff --git a/test/testdata/fixtures/multi-dc-cluster-scope/kustomization.yaml b/test/testdata/fixtures/multi-dc-cluster-scope/kustomization.yaml index 03cca31b9..c38d6b1da 100644 --- a/test/testdata/fixtures/multi-dc-cluster-scope/kustomization.yaml +++ b/test/testdata/fixtures/multi-dc-cluster-scope/kustomization.yaml @@ -2,4 +2,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - medusa-config.yaml + - reaper.yaml - k8ssandra.yaml diff --git a/test/testdata/fixtures/multi-dc-cluster-scope/reaper.yaml b/test/testdata/fixtures/multi-dc-cluster-scope/reaper.yaml new file mode 100644 index 000000000..95c100e4c --- /dev/null +++ b/test/testdata/fixtures/multi-dc-cluster-scope/reaper.yaml @@ -0,0 +1,31 @@ +apiVersion: v1 +kind: Secret +metadata: + name: reaper-ui-secret + namespace: k8ssandra-opeartor +data: + # username: reaper-jmx (actually) + username: cmVhcGVyLWpteA== + # password: R3ap3r + password: UjNhcDNy +--- +apiVersion: reaper.k8ssandra.io/v1alpha1 +kind: Reaper +metadata: + name: reaper1 + namespace: k8ssandra-opeartor +spec: + storageType: local + storageConfig: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 256Mi + httpManagement: + enabled: true + heapSize: 256Mi + autoScheduling: + enabled: false + uiUserSecretRef: + name: reaper-ui-secret