From 4d1b5801f1b7e58659e94b1096d4dc8fbb5c569a Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 7 Sep 2022 13:01:00 +0530 Subject: [PATCH] csi: remove findCSIChange from predicate findCSIChange will work only for single line values/configration in the configmap, If the value is multiline the regex will not be able to indentify the change because of this one no configurations will be applied to the csi driver. Removing this check so that if there is any update on the configmap we will reconcile the csi driver. Note:- This might looks heavy but updating of config map is not a frequent event. Signed-off-by: Madhu Rajanna (cherry picked from commit 5b843a17a1704f771ed3ab3a4e19328a555c7029) --- pkg/operator/ceph/csi/predicate.go | 19 +--- pkg/operator/ceph/csi/predicate_test.go | 111 ------------------------ 2 files changed, 3 insertions(+), 127 deletions(-) diff --git a/pkg/operator/ceph/csi/predicate.go b/pkg/operator/ceph/csi/predicate.go index 8962a96e6..d04a8ac5f 100644 --- a/pkg/operator/ceph/csi/predicate.go +++ b/pkg/operator/ceph/csi/predicate.go @@ -18,7 +18,6 @@ package csi import ( "context" - "regexp" "github.com/google/go-cmp/cmp" cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" @@ -80,7 +79,9 @@ func predicateController(ctx context.Context, c client.Client, opNamespace strin if old.Name == opcontroller.OperatorSettingConfigMapName && new.Name == opcontroller.OperatorSettingConfigMapName { diff := cmp.Diff(old.Data, new.Data, resourceQtyComparer) logger.Debugf("operator configmap diff:\n %s", diff) - return findCSIChange(diff) + if diff != "" { + return true + } } } } @@ -109,17 +110,3 @@ func predicateController(ctx context.Context, c client.Client, opNamespace strin }, } } - -func findCSIChange(str string) bool { - var re = regexp.MustCompile(`(?m)^(\+|-).*(\"ROOK_CSI_|\"CSI_).*,$`) - found := re.FindAllString(str, -1) - if len(found) > 0 { - for _, match := range found { - // logger.Debugf("ceph csi config changed with: %q", match) - logger.Infof("ceph csi config changed with: %q", match) - } - return true - } - - return false -} diff --git a/pkg/operator/ceph/csi/predicate_test.go b/pkg/operator/ceph/csi/predicate_test.go index 95f86820d..ae3ff720b 100644 --- a/pkg/operator/ceph/csi/predicate_test.go +++ b/pkg/operator/ceph/csi/predicate_test.go @@ -31,108 +31,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/predicate" ) -func Test_findCSIChange(t *testing.T) { - t.Run("no match", func(t *testing.T) { - var str = ` map[string]string{ - "CSI_FORCE_CEPHFS_KERNEL_CLIENT": "true", - "ROOK_CSI_ALLOW_UNSUPPORTED_VERSION": "false", - "ROOK_CSI_ENABLE_GRPC_METRICS": "true", - "ROOK_CSI_ENABLE_RBD": "true", - "ROOK_ENABLE_DISCOVERY_DAEMON": "false", -- "ROOK_LOG_LEVEL": "INFO", -+ "ROOK_LOG_LEVEL": "DEBUG", - "ROOK_OBC_WATCH_OPERATOR_NAMESPACE": "true", - }` - b := findCSIChange(str) - assert.False(t, b) - }) - - t.Run("match on addition", func(t *testing.T) { - var str = ` map[string]string{ - "CSI_FORCE_CEPHFS_KERNEL_CLIENT": "true", - "ROOK_CSI_ALLOW_UNSUPPORTED_VERSION": "false", -+ "ROOK_CSI_ENABLE_CEPHFS": "false", - "ROOK_CSI_ENABLE_GRPC_METRICS": "true", - "ROOK_CSI_ENABLE_RBD": "true", - "ROOK_ENABLE_DISCOVERY_DAEMON": "false", -- "ROOK_LOG_LEVEL": "INFO", -+ "ROOK_LOG_LEVEL": "DEBUG", - "ROOK_OBC_WATCH_OPERATOR_NAMESPACE": "true", - }` - b := findCSIChange(str) - assert.True(t, b) - }) - - t.Run("match on deletion", func(t *testing.T) { - var str = ` map[string]string{ - "CSI_FORCE_CEPHFS_KERNEL_CLIENT": "true", - "ROOK_CSI_ALLOW_UNSUPPORTED_VERSION": "false", -- "ROOK_CSI_ENABLE_CEPHFS": "true", - "ROOK_CSI_ENABLE_GRPC_METRICS": "true", - "ROOK_CSI_ENABLE_RBD": "true", - "ROOK_ENABLE_DISCOVERY_DAEMON": "false", -- "ROOK_LOG_LEVEL": "INFO", -+ "ROOK_LOG_LEVEL": "DEBUG", - "ROOK_OBC_WATCH_OPERATOR_NAMESPACE": "true", - }` - b := findCSIChange(str) - assert.True(t, b) - }) - - t.Run("match on addition and deletion", func(t *testing.T) { - var str = ` map[string]string{ - "CSI_FORCE_CEPHFS_KERNEL_CLIENT": "true", - "ROOK_CSI_ALLOW_UNSUPPORTED_VERSION": "false", -- "ROOK_CSI_ENABLE_CEPHFS": "true", -+ "ROOK_CSI_ENABLE_CEPHFS": "false", - "ROOK_CSI_ENABLE_GRPC_METRICS": "true", - "ROOK_CSI_ENABLE_RBD": "true", - "ROOK_ENABLE_DISCOVERY_DAEMON": "false", -- "ROOK_LOG_LEVEL": "INFO", -+ "ROOK_LOG_LEVEL": "DEBUG", - "ROOK_OBC_WATCH_OPERATOR_NAMESPACE": "true", - }` - b := findCSIChange(str) - assert.True(t, b) - }) - - t.Run("match with CSI_ name", func(t *testing.T) { - var str = ` map[string]string{ - "CSI_FORCE_CEPHFS_KERNEL_CLIENT": "true", - "ROOK_CSI_ALLOW_UNSUPPORTED_VERSION": "false", -- "CSI_PROVISIONER_TOLERATIONS": "true", -+ "CSI_PROVISIONER_TOLERATIONS": "false", - "ROOK_CSI_ENABLE_GRPC_METRICS": "true", - "ROOK_CSI_ENABLE_RBD": "true", - "ROOK_ENABLE_DISCOVERY_DAEMON": "false", -- "ROOK_LOG_LEVEL": "INFO", -+ "ROOK_LOG_LEVEL": "DEBUG", - "ROOK_OBC_WATCH_OPERATOR_NAMESPACE": "true", - }` - b := findCSIChange(str) - assert.True(t, b) - }) - - t.Run("match with CSI_ and ROOK_CSI_ name", func(t *testing.T) { - var str = ` map[string]string{ - "CSI_FORCE_CEPHFS_KERNEL_CLIENT": "true", - "ROOK_CSI_ALLOW_UNSUPPORTED_VERSION": "false", -- "CSI_PROVISIONER_TOLERATIONS": "true", -+ "CSI_PROVISIONER_TOLERATIONS": "false", -- "ROOK_CSI_ENABLE_CEPHFS": "true", -+ "ROOK_CSI_ENABLE_CEPHFS": "false", - "ROOK_CSI_ENABLE_GRPC_METRICS": "true", - "ROOK_CSI_ENABLE_RBD": "true", - "ROOK_ENABLE_DISCOVERY_DAEMON": "false", -- "ROOK_LOG_LEVEL": "INFO", -+ "ROOK_LOG_LEVEL": "DEBUG", - "ROOK_OBC_WATCH_OPERATOR_NAMESPACE": "true", - }` - b := findCSIChange(str) - assert.True(t, b) - }) -} - func Test_predicateController(t *testing.T) { capnslog.SetGlobalLogLevel(capnslog.DEBUG) var ( @@ -189,15 +87,6 @@ func Test_predicateController(t *testing.T) { assert.False(t, p.Update(u)) }) - t.Run("update event is a CM and the content changed but with incorrect setting", func(t *testing.T) { - cm.Data = map[string]string{"foo": "bar"} - cm2.Name = "rook-ceph-operator-config" - cm2.Data = map[string]string{"foo": "ooo"} - u = event.UpdateEvent{ObjectOld: &cm, ObjectNew: &cm2} - p = predicateController(context.TODO(), client, "rook-ceph") - assert.False(t, p.Update(u)) - }) - t.Run("update event is a CM and the content changed with correct setting", func(t *testing.T) { cm.Data = map[string]string{"foo": "bar"} cm2.Name = "rook-ceph-operator-config"