Skip to content

Commit

Permalink
Add the IsControlPlane function and use it to skip some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvoncek committed Jul 19, 2024
1 parent dd70c87 commit 318d480
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
6 changes: 6 additions & 0 deletions apis/reaper/v1alpha1/reaper_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ type ReaperSpec struct {
SkipSchemaMigration bool `json:"skipSchemaMigration,omitempty"`
}

func (in *ReaperSpec) IsControlPlane() bool {
return in != nil &&
in.ReaperRef.Name == "" && in.ReaperRef.Namespace == "" &&
in.DatacenterRef.Name == "" && in.DatacenterRef.Namespace == ""
}

// ReaperProgress is a word summarizing the state of a Reaper resource.
type ReaperProgress string

Expand Down
26 changes: 26 additions & 0 deletions apis/reaper/v1alpha1/reaper_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,29 @@ limitations under the License.
*/

package v1alpha1

import (
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
"testing"
)

func TestReaperSpec(t *testing.T) {
t.Run("IsControlPlane", testIsControlPlane)
}

func testIsControlPlane(t *testing.T) {
reaper := &ReaperSpec{}
assert.True(t, reaper.IsControlPlane())
reaper.ReaperRef = v1.ObjectReference{Name: "foo"}
assert.False(t, reaper.IsControlPlane())
reaper.ReaperRef = v1.ObjectReference{Name: "foo", Namespace: "bar"}
assert.False(t, reaper.IsControlPlane())

reaper = &ReaperSpec{}
reaper.DatacenterRef = CassandraDatacenterRef{Name: "foo"}
assert.False(t, reaper.IsControlPlane())

reaper.ReaperRef = v1.ObjectReference{Name: "foo"}
assert.False(t, reaper.IsControlPlane())
}
21 changes: 15 additions & 6 deletions controllers/reaper/reaper_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,16 @@ func (r *ReaperReconciler) reconcile(ctx context.Context, actualReaper *reaperap
actualReaper.Status.Progress = reaperapi.ReaperProgressPending
actualReaper.Status.SetNotReady()

reconciledDc, result, err := r.reconcileDatacenter(ctx, actualReaper, logger)
if !result.IsZero() || err != nil {
return result, err
var actualDc *cassdcapi.CassandraDatacenter
if actualReaper.Spec.IsControlPlane() {
actualDc = &cassdcapi.CassandraDatacenter{}
} else {
reconciledDc, result, err := r.reconcileDatacenter(ctx, actualReaper, logger)
if !result.IsZero() || err != nil {
return result, err
}
actualDc = reconciledDc.DeepCopy()
}
actualDc := reconciledDc.DeepCopy()

actualReaper.Status.Progress = reaperapi.ReaperProgressDeploying

Expand All @@ -108,8 +113,12 @@ func (r *ReaperReconciler) reconcile(ctx context.Context, actualReaper *reaperap

actualReaper.Status.Progress = reaperapi.ReaperProgressConfiguring

if result, err := r.configureReaper(ctx, actualReaper, actualDc, logger); !result.IsZero() || err != nil {
return result, err
if actualReaper.Spec.IsControlPlane() {
logger.Info("skipping adding DC to Reaper because its a Control Plane Reaper")
} else {
if result, err := r.configureReaper(ctx, actualReaper, actualDc, logger); !result.IsZero() || err != nil {
return result, err
}
}

actualReaper.Status.Progress = reaperapi.ReaperProgressRunning
Expand Down

0 comments on commit 318d480

Please sign in to comment.