core: treat cluster as not existing if the cleanup policy is set
The cluster CR can be forcefully deleted and cleanup the cluster resources if the yes-really-destroy-data policy is set on the CR. In this case, the other controllers should treat the cluster CR as not existing and allow the finalizers to be removed on those resources if they are requested for deletion. Signed-off-by: Travis Nielsen <tnielsen@redhat.com>
This commit is contained in:
13 files changed
+110
-14
No files matched your search
@@ -17,12 +17,18 @@ limitations under the License.
|
||||
package controller
|
||||
|
||||
import (
|
||||
ctx "context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
||||
"github.com/rook/rook/pkg/client/clientset/versioned/scheme"
|
||||
"github.com/rook/rook/pkg/util/exec"
|
||||
"github.com/stretchr/testify/assert"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||
)
|
||||
|
||||
func CreateTestClusterFromStatusDetails(details map[string]cephv1.CephHealthMessage) cephv1.CephCluster {
|
||||
@@ -85,3 +91,88 @@ func TestSetCephCommandsTimeout(t *testing.T) {
|
||||
SetCephCommandsTimeout(map[string]string{"ROOK_CEPH_COMMANDS_TIMEOUT_SECONDS": "1"})
|
||||
assert.Equal(t, 1*time.Second, exec.CephCommandsTimeout)
|
||||
}
|
||||
|
||||
func TestIsReadyToReconcile(t *testing.T) {
|
||||
scheme := scheme.Scheme
|
||||
scheme.AddKnownTypes(cephv1.SchemeGroupVersion, &cephv1.CephCluster{}, &cephv1.CephClusterList{})
|
||||
|
||||
controllerName := "testing"
|
||||
clusterName := types.NamespacedName{Name: "mycluster", Namespace: "myns"}
|
||||
|
||||
t.Run("non-existent cephcluster", func(t *testing.T) {
|
||||
client := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects().Build()
|
||||
c, ready, clusterExists, reconcileResult := IsReadyToReconcile(ctx.TODO(), client, clusterName, controllerName)
|
||||
assert.NotNil(t, c)
|
||||
assert.False(t, ready)
|
||||
assert.False(t, clusterExists)
|
||||
assert.Equal(t, WaitForRequeueIfCephClusterNotReady, reconcileResult)
|
||||
})
|
||||
|
||||
t.Run("valid cephcluster", func(t *testing.T) {
|
||||
cephCluster := &cephv1.CephCluster{}
|
||||
objects := []runtime.Object{cephCluster}
|
||||
client := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(objects...).Build()
|
||||
c, ready, clusterExists, reconcileResult := IsReadyToReconcile(ctx.TODO(), client, clusterName, controllerName)
|
||||
assert.NotNil(t, c)
|
||||
assert.False(t, ready)
|
||||
assert.False(t, clusterExists)
|
||||
assert.Equal(t, WaitForRequeueIfCephClusterNotReady, reconcileResult)
|
||||
})
|
||||
|
||||
t.Run("deleted cephcluster with no cleanup policy", func(t *testing.T) {
|
||||
cephCluster := &cephv1.CephCluster{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: clusterName.Name,
|
||||
Namespace: clusterName.Namespace,
|
||||
DeletionTimestamp: &metav1.Time{Time: time.Now()},
|
||||
},
|
||||
}
|
||||
|
||||
objects := []runtime.Object{cephCluster}
|
||||
client := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(objects...).Build()
|
||||
c, ready, clusterExists, reconcileResult := IsReadyToReconcile(ctx.TODO(), client, clusterName, controllerName)
|
||||
assert.NotNil(t, c)
|
||||
assert.False(t, ready)
|
||||
assert.True(t, clusterExists)
|
||||
assert.Equal(t, WaitForRequeueIfCephClusterNotReady, reconcileResult)
|
||||
})
|
||||
|
||||
t.Run("cephcluster with cleanup policy when not deleted", func(t *testing.T) {
|
||||
cephCluster := &cephv1.CephCluster{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: clusterName.Name,
|
||||
Namespace: clusterName.Namespace,
|
||||
},
|
||||
Spec: cephv1.ClusterSpec{
|
||||
CleanupPolicy: cephv1.CleanupPolicySpec{
|
||||
Confirmation: cephv1.DeleteDataDirOnHostsConfirmation,
|
||||
},
|
||||
}}
|
||||
objects := []runtime.Object{cephCluster}
|
||||
client := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(objects...).Build()
|
||||
c, ready, clusterExists, _ := IsReadyToReconcile(ctx.TODO(), client, clusterName, controllerName)
|
||||
assert.NotNil(t, c)
|
||||
assert.False(t, ready)
|
||||
assert.True(t, clusterExists)
|
||||
})
|
||||
|
||||
t.Run("cephcluster with cleanup policy when deleted", func(t *testing.T) {
|
||||
cephCluster := &cephv1.CephCluster{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: clusterName.Name,
|
||||
Namespace: clusterName.Namespace,
|
||||
DeletionTimestamp: &metav1.Time{Time: time.Now()},
|
||||
},
|
||||
Spec: cephv1.ClusterSpec{
|
||||
CleanupPolicy: cephv1.CleanupPolicySpec{
|
||||
Confirmation: cephv1.DeleteDataDirOnHostsConfirmation,
|
||||
},
|
||||
}}
|
||||
objects := []runtime.Object{cephCluster}
|
||||
client := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(objects...).Build()
|
||||
c, ready, clusterExists, _ := IsReadyToReconcile(ctx.TODO(), client, clusterName, controllerName)
|
||||
assert.NotNil(t, c)
|
||||
assert.False(t, ready)
|
||||
assert.False(t, clusterExists)
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user