From 01f3137c45dae46099eee8c78d7d94f2915d9734 Mon Sep 17 00:00:00 2001 From: Miles Garnsey Date: Wed, 21 Aug 2024 11:34:45 +0200 Subject: [PATCH] Add reload truststore cassandraTask. --- apis/control/v1alpha1/cassandratask_types.go | 1 + .../control/cassandratask_controller.go | 2 ++ .../control/cassandratask_controller_test.go | 13 +++++++++ internal/controllers/control/jobs.go | 16 +++++++++++ pkg/httphelper/client.go | 27 +++++++++++++++++++ 5 files changed, 59 insertions(+) diff --git a/apis/control/v1alpha1/cassandratask_types.go b/apis/control/v1alpha1/cassandratask_types.go index d02703b3..ffc1b701 100644 --- a/apis/control/v1alpha1/cassandratask_types.go +++ b/apis/control/v1alpha1/cassandratask_types.go @@ -81,6 +81,7 @@ const ( CommandGarbageCollect CassandraCommand = "garbagecollect" CommandFlush CassandraCommand = "flush" CommandRefresh CassandraCommand = "refresh" + CommandTSReload CassandraCommand = "tsreload" ) type CassandraJob struct { diff --git a/internal/controllers/control/cassandratask_controller.go b/internal/controllers/control/cassandratask_controller.go index 45bd78fd..dc152d0b 100644 --- a/internal/controllers/control/cassandratask_controller.go +++ b/internal/controllers/control/cassandratask_controller.go @@ -317,6 +317,8 @@ JobDefinition: } completed = taskConfig.Completed break JobDefinition + case api.CommandTSReload: + tsReload(taskConfig) default: err = fmt.Errorf("unknown job command: %s", job.Command) return ctrl.Result{}, err diff --git a/internal/controllers/control/cassandratask_controller_test.go b/internal/controllers/control/cassandratask_controller_test.go index 8e1396ef..4a019845 100644 --- a/internal/controllers/control/cassandratask_controller_test.go +++ b/internal/controllers/control/cassandratask_controller_test.go @@ -622,10 +622,23 @@ var _ = Describe("CassandraTask controller tests", func() { Expect(callDetails.URLCounts["/api/v0/ops/executor/job"]).To(Equal(0)) Expect(callDetails.URLCounts["/api/v0/metadata/versions/features"]).To(BeNumerically(">", 1)) + // verifyPodsHaveAnnotations(testNamespaceName, string(task.UID)) + Expect(completedTask.Status.Succeeded).To(BeNumerically(">=", 1)) + }) + It("Runs a ts reload task against a pod", func() { + By("Creating a task for tsreload") + taskKey, task := buildTask(api.CommandTSReload, testNamespaceName) + Expect(k8sClient.Create(context.Background(), task)).Should(Succeed()) + + completedTask := waitForTaskCompletion(taskKey) + + Expect(callDetails.URLCounts["/api/v0/ops/node/reload-truststore"]).To(Equal(1)) + // verifyPodsHaveAnnotations(testNamespaceName, string(task.UID)) Expect(completedTask.Status.Succeeded).To(BeNumerically(">=", 1)) }) }) + Context("Task TTL", func() { var testNamespaceName string BeforeEach(func() { diff --git a/internal/controllers/control/jobs.go b/internal/controllers/control/jobs.go index 3fa41f7f..4a95ffa9 100644 --- a/internal/controllers/control/jobs.go +++ b/internal/controllers/control/jobs.go @@ -442,6 +442,22 @@ func (r *CassandraTaskReconciler) refreshDatacenter(ctx context.Context, dc *cas } } return ctrl.Result{RequeueAfter: JobRunningRequeue}, nil + +} + +// Compaction functionality + +func TSReloadAsync(nodeMgmtClient httphelper.NodeMgmtClient, pod *corev1.Pod, taskConfig *TaskConfiguration) (string, error) { + return nodeMgmtClient.CallCompaction(pod, createCompactRequest(taskConfig)) +} + +func tsReload(taskConfig *TaskConfiguration) { + taskConfig.PodFilter = genericPodFilter + taskConfig.SyncFunc = tsReloadSync +} + +func tsReloadSync(nodeMgmtClient httphelper.NodeMgmtClient, pod *corev1.Pod, taskConfig *TaskConfiguration) error { + return nodeMgmtClient.CallTSReloadEndpoint(pod) } // Common functions diff --git a/pkg/httphelper/client.go b/pkg/httphelper/client.go index bfece9f2..472e31f6 100644 --- a/pkg/httphelper/client.go +++ b/pkg/httphelper/client.go @@ -585,6 +585,33 @@ func (client *NodeMgmtClient) CallCompactionEndpoint(pod *corev1.Pod, compactReq return nil } +// CallTSReloadEndpoint calls the async version of TSReload +func (client *NodeMgmtClient) CallTSReloadEndpoint(pod *corev1.Pod) error { + client.Log.Info( + "calling Management API TS REload endpoint - POST /api/v0/nodes/reload-truststore", + "pod", pod.Name, + ) + podHost, podPort, err := BuildPodHostFromPod(pod) + if err != nil { + return err + } + + request := nodeMgmtRequest{ + endpoint: "/api/v0/nodes/reload-truststore", + host: podHost, + port: podPort, + method: http.MethodGet, + timeout: 60 * time.Second, + } + + _, err = callNodeMgmtEndpoint(client, request, "application/json") + if err != nil { + return err + } + + return nil +} + type ScrubRequest struct { DisableSnapshot bool `json:"disable_snapshot"` SkipCorrupted bool `json:"skip_corrupted"`