From 8f2f36fafc1e79daa1dc33ac738d32d9da3741f5 Mon Sep 17 00:00:00 2001 From: Rewant Soni Date: Mon, 4 Nov 2024 19:54:11 +0530 Subject: [PATCH] provider: enable csiomap generator for client send a configMap from provider to client to enable csi-omap generator required for DR on client cluster Signed-off-by: Rewant Soni --- services/provider/server/server.go | 38 ++++++++++++++++++++++++- services/provider/server/server_test.go | 7 +++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/services/provider/server/server.go b/services/provider/server/server.go index f12e7e021f..1c0b9c33e3 100644 --- a/services/provider/server/server.go +++ b/services/provider/server/server.go @@ -200,10 +200,16 @@ func (s *OCSProviderServer) GetStorageConfig(ctx context.Context, req *pb.Storag return nil, err } + storageClusterPeers, err := s.getStorageClusterPeer(ctx) + if err != nil { + return nil, err + } + desiredClientConfigHash := getDesiredClientConfigHash( channelName, consumerObj, isEncryptionInTransitEnabled(storageCluster.Spec.Network), + len(storageClusterPeers.Items) > 0, ) klog.Infof("successfully returned the config details to the consumer.") @@ -404,6 +410,20 @@ func (s *OCSProviderServer) getExternalResources(ctx context.Context, consumerRe } + //Enable CSI-OMAP is storageClusterPeer is present + storageClusterPeers, err := s.getStorageClusterPeer(ctx) + if err != nil { + return nil, err + } + + extR = append(extR, &pb.ExternalResource{ + Name: "ocs-ceph-csi-config", + Kind: "ConfigMap", + Data: mustMarshal(map[string]string{ + "CSI_ENABLE_OMAP_GENERATOR": strconv.FormatBool(len(storageClusterPeers.Items) > 0), + }), + }) + // Fetch noobaa remote secret and management address and append to extResources consumerName := consumerResource.Name noobaaOperatorSecret := &v1.Secret{} @@ -860,10 +880,16 @@ func (s *OCSProviderServer) ReportStatus(ctx context.Context, req *pb.ReportStat return nil, err } + storageClusterPeers, err := s.getStorageClusterPeer(ctx) + if err != nil { + return nil, err + } + desiredClientConfigHash := getDesiredClientConfigHash( channelName, storageConsumer, isEncryptionInTransitEnabled(storageCluster.Spec.Network), + len(storageClusterPeers.Items) > 0, ) return &pb.ReportStatusResponse{ @@ -872,11 +898,12 @@ func (s *OCSProviderServer) ReportStatus(ctx context.Context, req *pb.ReportStat }, nil } -func getDesiredClientConfigHash(channelName string, storageConsumer *ocsv1alpha1.StorageConsumer, encryptionInTransit bool) string { +func getDesiredClientConfigHash(channelName string, storageConsumer *ocsv1alpha1.StorageConsumer, encryptionInTransit bool, enableOmap bool) string { var arr = []any{ channelName, storageConsumer.Spec.StorageQuotaInGiB, encryptionInTransit, + enableOmap, } return util.CalculateMD5Hash(arr) } @@ -924,6 +951,15 @@ func (s *OCSProviderServer) getStorageCluster(ctx context.Context) (*ocsv1.Stora return foundSc, nil } +func (s *OCSProviderServer) getStorageClusterPeer(ctx context.Context) (*ocsv1.StorageClusterPeerList, error) { + storageClusterPeers := &ocsv1.StorageClusterPeerList{} + err := s.client.List(ctx, storageClusterPeers, client.InNamespace(s.namespace)) + if err != nil { + return nil, fmt.Errorf("failed to list storage cluster peers. %v", err) + } + return storageClusterPeers, nil +} + func isEncryptionInTransitEnabled(networkSpec *rookCephv1.NetworkSpec) bool { return networkSpec != nil && networkSpec.Connections != nil && diff --git a/services/provider/server/server_test.go b/services/provider/server/server_test.go index 36d0628ec7..8ad9a12f7d 100644 --- a/services/provider/server/server_test.go +++ b/services/provider/server/server_test.go @@ -95,6 +95,13 @@ var mockExtR = map[string]*externalResource{ "QuotaForConsumer": fmt.Sprintf("%+v\n", clusterResourceQuotaSpec), }, }, + "ocs-ceph-csi-config": { + Name: "ocs-ceph-csi-config", + Kind: "ConfigMap", + Data: map[string]string{ + "CSI_ENABLE_OMAP_GENERATOR": "false", + }, + }, "noobaa-remote-join-secret": { Name: "noobaa-remote-join-secret", Kind: "Secret",