Skip to content

Commit

Permalink
Make Reaper's backend configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvoncek committed Jul 2, 2024
1 parent 63ff0fe commit fbc32af
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
8 changes: 8 additions & 0 deletions apis/reaper/v1alpha1/reaper_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ const (

type ReaperTemplate struct {

// The storage backend to store Reaper's data. Defaults to "cassandra" which causes Reaper to be stateless and store
// its state to a Cassandra cluster it repairs (implying there must be one Reaper for each Cassandra cluster).
// The "memory" option makes Reaper to store its state locally, allowing a single Reaper to repair several clusters.
// +kubebuilder:validation:Enum=cassandra;memory
// +kubebuilder:default="cassandra"
// +optional
StorageType string `json:"storageType,omitempty"`

// The keyspace to use to store Reaper's state. Will default to "reaper_db" if unspecified. Will be created if it
// does not exist, and if this Reaper resource is managed by K8ssandra.
// +kubebuilder:default="reaper_db"
Expand Down
12 changes: 12 additions & 0 deletions charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28672,6 +28672,12 @@ spec:
type: string
type: object
type: object
storageType:
default: cassandra
enum:
- cassandra
- memory
type: string
telemetry:
description: |-
Telemetry defines the desired telemetry integrations to deploy targeting the Reaper pods for all DCs in this cluster
Expand Down Expand Up @@ -34560,6 +34566,12 @@ spec:
if you know that the schema is already up-to-date, or if you know upfront that QUORUM cannot be achieved (for
example, because a DC is down).
type: boolean
storageType:
default: cassandra
enum:
- cassandra
- memory
type: string
telemetry:
description: |-
Telemetry defines the desired telemetry integrations to deploy targeting the Reaper pods for all DCs in this cluster
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28610,6 +28610,12 @@ spec:
type: string
type: object
type: object
storageType:
default: cassandra
enum:
- cassandra
- memory
type: string
telemetry:
description: |-
Telemetry defines the desired telemetry integrations to deploy targeting the Reaper pods for all DCs in this cluster
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/reaper.k8ssandra.io_reapers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2257,6 +2257,12 @@ spec:
if you know that the schema is already up-to-date, or if you know upfront that QUORUM cannot be achieved (for
example, because a DC is down).
type: boolean
storageType:
default: cassandra
enum:
- cassandra
- memory
type: string
telemetry:
description: |-
Telemetry defines the desired telemetry integrations to deploy targeting the Reaper pods for all DCs in this cluster
Expand Down
2 changes: 1 addition & 1 deletion pkg/reaper/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewDeployment(reaper *api.Reaper, dc *cassdcapi.CassandraDatacenter, keysto
envVars := []corev1.EnvVar{
{
Name: "REAPER_STORAGE_TYPE",
Value: "cassandra",
Value: reaper.Spec.StorageType,
},
{
Name: "REAPER_ENABLE_DYNAMIC_SEED_LIST",
Expand Down
23 changes: 22 additions & 1 deletion pkg/reaper/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,26 @@ func TestSkipSchemaMigration(t *testing.T) {
assert.Len(t, deployment.Spec.Template.Spec.InitContainers, 0, "expected pod template to not have any init container")
}

func TestStorageTypes(t *testing.T) {
tests := []struct {
name string
storageType string
}{
{"memory type test", "memory"},
{"cassandra type test", "cassandra"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
reaper := newTestReaper()
reaper.Spec.StorageType = tt.storageType
logger := testlogr.NewTestLogger(t)
deployment := NewDeployment(reaper, newTestDatacenter(), nil, nil, logger)
assert.Len(t, deployment.Spec.Template.Spec.Containers, 1)
assert.Equal(t, tt.storageType, deployment.Spec.Template.Spec.Containers[0].Env[0].Value)
})
}
}

func newTestReaper() *reaperapi.Reaper {
namespace := "service-test"
reaperName := "test-reaper"
Expand All @@ -502,7 +522,8 @@ func newTestReaper() *reaperapi.Reaper {
Namespace: namespace,
},
ReaperTemplate: reaperapi.ReaperTemplate{
Keyspace: "reaper_db",
Keyspace: "reaper_db",
StorageType: "cassandra",
ResourceMeta: &meta.ResourceMeta{
CommonLabels: map[string]string{"common": "everywhere", "override": "commonLevel"},
Pods: meta.Tags{
Expand Down

0 comments on commit fbc32af

Please sign in to comment.