Skip to content

Commit

Permalink
provider: enable csiomap generator for client
Browse files Browse the repository at this point in the history
send a configMap from provider to client to enable csi-omap
generator required for DR on client cluster

Signed-off-by: Rewant Soni <[email protected]>
  • Loading branch information
rewantsoni committed Nov 5, 2024
1 parent 70fe2f2 commit 8f2f36f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
38 changes: 37 additions & 1 deletion services/provider/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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{
Expand All @@ -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)
}
Expand Down Expand Up @@ -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 &&
Expand Down
7 changes: 7 additions & 0 deletions services/provider/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 8f2f36f

Please sign in to comment.