Skip to content

Commit

Permalink
Forbid enabling vector on a CP reaper
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvoncek committed Jul 29, 2024
1 parent 2066607 commit 7fc882b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
6 changes: 4 additions & 2 deletions apis/reaper/v1alpha1/reaper_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ func (r *Reaper) validateReaper() error {
if r.Spec.HasReaperRef() {
return nil
}

if r.Spec.IsControlPlane() && r.Spec.StorageType != StorageTypeLocal {
return fmt.Errorf("a CONTROL_PLANE reaper can only use local storage")
return fmt.Errorf("a Control Plane reaper can only use local storage")
}
if r.Spec.IsControlPlane() && r.Spec.Telemetry != nil && r.Spec.Telemetry.IsVectorEnabled() {
return fmt.Errorf("a Control Plane reaper cannot have vector enabled")
}
if r.Spec.StorageType == StorageTypeLocal {
return r.validateReaperWithLocalStorage()
Expand Down
24 changes: 21 additions & 3 deletions apis/reaper/v1alpha1/reaper_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"crypto/tls"
"fmt"
telemetryapi "github.com/k8ssandra/k8ssandra-operator/apis/telemetry/v1alpha1"
"net"
"path/filepath"
"testing"
Expand Down Expand Up @@ -149,10 +150,27 @@ func testReaper(t *testing.T) {
createNamespace(require, "reaper-namespace")
reaper := createMinimalReaperObj("test-reaper", "reaper-namespace")

reaper.Spec.DatacenterRef = createDatacenterRef()
reaper.Spec.ReaperRef = createReaperRef()
err := k8sClient.Create(ctx, reaper)
reaperWithBothRefs := reaper.DeepCopy()
reaperWithBothRefs.Spec.DatacenterRef = createDatacenterRef()
reaperWithBothRefs.Spec.ReaperRef = createReaperRef()
err := k8sClient.Create(ctx, reaperWithBothRefs)
require.Error(err)

reaperWithTelemetry := reaper.DeepCopy()
reaperWithTelemetry.Spec.StorageType = StorageTypeLocal
reaperWithTelemetry.Spec.StorageConfig = createTestStorageConfig()
reaperWithTelemetry.Spec.Telemetry = &telemetryapi.TelemetrySpec{
Vector: &telemetryapi.VectorSpec{
Enabled: ptr.To(true),
},
}
err = k8sClient.Create(ctx, reaper)
require.Error(err)

reaperWithoutTelemetry := reaperWithTelemetry.DeepCopy()
reaperWithoutTelemetry.Spec.Telemetry.Vector.Enabled = ptr.To(false)
err = k8sClient.Create(ctx, reaperWithoutTelemetry)
require.NoError(err)
}

func testLocalStorage(t *testing.T) {
Expand Down

0 comments on commit 7fc882b

Please sign in to comment.