Skip to content

Commit

Permalink
Add reload truststore cassandraTask.
Browse files Browse the repository at this point in the history
  • Loading branch information
Miles-Garnsey committed Aug 21, 2024
1 parent 735c506 commit 01f3137
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions apis/control/v1alpha1/cassandratask_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const (
CommandGarbageCollect CassandraCommand = "garbagecollect"
CommandFlush CassandraCommand = "flush"
CommandRefresh CassandraCommand = "refresh"
CommandTSReload CassandraCommand = "tsreload"
)

type CassandraJob struct {
Expand Down
2 changes: 2 additions & 0 deletions internal/controllers/control/cassandratask_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions internal/controllers/control/cassandratask_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
16 changes: 16 additions & 0 deletions internal/controllers/control/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions pkg/httphelper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 01f3137

Please sign in to comment.