ceph: convert the CephCluster controller to the controller-runtime

This is the final conversion to controller-runtime conversion. This time the
CephCluster CRD has been converted to use the controller-runtime
library.
The controller incorporates all the previous watchers too, so the Node
and hot-plug configmap are been watched too.
Only the operator setting configmap is not being watcher since it's not
related to the CephCluster CRD.
Not only the patch converts to controller-runtime but also tries to
re-organize the tree of the repo to actually make the code more
readable and have better functions/methods/tests separations.

Closes: https://github.com/rook/rook/issues/4939
Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
Sébastien Han committed 2020-04-28 09:40:35 +02:00
1 parent 008670bc79
commit f27fd207ce
55 files changed
+2635 -1848

No files matched your search

+134 -2
View File
@@ -21,7 +21,10 @@ import (
"testing"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
"github.com/rook/rook/pkg/operator/ceph/config"
"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
@@ -65,13 +68,13 @@ func TestObjectChanged(t *testing.T) {
}
// Identical
changed, err := objectChanged(oldObject, newObject)
changed, err := objectChanged(oldObject, newObject, "foo")
assert.NoError(t, err)
assert.False(t, changed)
// Replica size changed
oldObject.Spec.Replicated.Size = newReplicas
changed, err = objectChanged(oldObject, newObject)
changed, err = objectChanged(oldObject, newObject, "foo")
assert.NoError(t, err)
assert.True(t, changed)
}
@@ -102,3 +105,132 @@ func TestIsUpgrade(t *testing.T) {
b = isUpgrade(oldLabel, newLabel)
assert.True(t, b, fmt.Sprintf("%v,%v", oldLabel, newLabel))
}
func TestIsValidEvent(t *testing.T) {
obj := "rook-ceph-mon-a"
valid := []byte(`{
"metadata": {},
"spec": {},
"status": {
"conditions": [
{
"message": "ReplicaSet \"rook-ceph-mon-b-784fc58bf8\" is progressing.",
"reason": "ReplicaSetUpdated",
"type": "Progressing"
}
]
}
}`)
b := isValidEvent(valid, obj)
assert.True(t, b)
valid = []byte(`{"foo": "bar"}`)
b = isValidEvent(valid, obj)
assert.True(t, b)
invalid := []byte(`{
"metadata": {},
"status": {},
}`)
b = isValidEvent(invalid, obj)
assert.False(t, b)
}
func TestIsCanary(t *testing.T) {
dum := &cephv1.CephBlockPool{}
b := isCanary(dum)
assert.False(t, b)
d := &appsv1.Deployment{}
b = isCanary(d)
assert.False(t, b)
d.Labels = map[string]string{
"foo": "bar",
}
b = isCanary(d)
assert.False(t, b)
d.Labels["mon_canary"] = "true"
b = isCanary(d)
assert.True(t, b)
}
func TestIsCMToIgnoreOnUpdate(t *testing.T) {
dum := &cephv1.CephBlockPool{}
b := isCMTConfigOverride(dum)
assert.False(t, b)
cm := &corev1.ConfigMap{}
b = isCMTConfigOverride(cm)
assert.False(t, b)
cm.Name = "rook-ceph-mon-endpoints"
b = isCMTConfigOverride(cm)
assert.False(t, b)
cm.Name = "rook-config-override"
b = isCMTConfigOverride(cm)
assert.True(t, b)
}
func TestIsCMToIgnoreOnDelete(t *testing.T) {
dum := &cephv1.CephBlockPool{}
b := isCMToIgnoreOnDelete(dum)
assert.False(t, b)
cm := &corev1.ConfigMap{}
b = isCMToIgnoreOnDelete(cm)
assert.False(t, b)
cm.Name = "rook-ceph-mon-endpoints"
b = isCMToIgnoreOnDelete(cm)
assert.False(t, b)
cm.Name = "rook-ceph-osd-minikube-status"
b = isCMToIgnoreOnDelete(cm)
assert.True(t, b)
}
func TestIsSecretToIgnoreOnUpdate(t *testing.T) {
dum := &cephv1.CephBlockPool{}
b := isSecretToIgnoreOnUpdate(dum)
assert.False(t, b)
s := &corev1.Secret{}
b = isSecretToIgnoreOnUpdate(s)
assert.False(t, b)
s.Name = "foo"
b = isSecretToIgnoreOnUpdate(s)
assert.False(t, b)
s.Name = config.StoreName
b = isSecretToIgnoreOnUpdate(s)
assert.True(t, b)
}
func TestIsDoNotReconcile(t *testing.T) {
l := map[string]string{
"foo": "bar",
}
// value not present
b := isDoNotReconcile(l)
assert.False(t, b)
// good value wrong content
l["do_not_reconcile"] = "false"
b = isDoNotReconcile(l)
assert.False(t, b)
// good value and good content
l["do_not_reconcile"] = "true"
b = isDoNotReconcile(l)
assert.True(t, b)
}