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 13, 2024
1 parent c079ab8 commit 67b79ba
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import (
v1 "github.com/red-hat-storage/ocs-operator/api/v4/v1"
)

const (
OcsClientPeerConfigMapName = "ocs-client-peer-mapping"
)

// StorageClusterPeerReconciler reconciles a StorageClusterPeer object
// nolint:revive
type StorageClusterPeerReconciler struct {
Expand Down
52 changes: 51 additions & 1 deletion services/provider/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/json"
"encoding/pem"
"fmt"
"github.com/red-hat-storage/ocs-operator/v4/controllers/storageclusterpeer"
"math"
"net"
"slices"
Expand Down Expand Up @@ -224,10 +225,20 @@ func (s *OCSProviderServer) GetStorageConfig(ctx context.Context, req *pb.Storag
return nil, err
}

clientMappingConfig, err := s.getPeerClientMapping(ctx)
if err != nil {
return nil, err
}
clientIsMapped := false
if clientMappingConfig != nil && clientMappingConfig[req.StorageConsumerUUID] != "" {
clientIsMapped = true
}

desiredClientConfigHash := getDesiredClientConfigHash(
channelName,
consumerObj,
isEncryptionInTransitEnabled(storageCluster.Spec.Network),
clientIsMapped,
)

klog.Infof("successfully returned the config details to the consumer.")
Expand Down Expand Up @@ -418,6 +429,24 @@ func (s *OCSProviderServer) getExternalResources(ctx context.Context, consumerRe

}

//Enable CSI-OMAP is storageClusterPeer is present
clientMappingConfig, err := s.getPeerClientMapping(ctx)
if err != nil {
return nil, err
}
clientIsMapped := false
if clientMappingConfig != nil && clientMappingConfig[string(consumerResource.UID)] != "" {
clientIsMapped = true
}

extR = append(extR, &pb.ExternalResource{
Name: "ocs-ceph-csi-config",
Kind: "ConfigMap",
Data: mustMarshal(map[string]string{
"CSI_ENABLE_OMAP_GENERATOR": strconv.FormatBool(clientIsMapped),
}),
})

// Fetch noobaa remote secret and management address and append to extResources
consumerName := consumerResource.Name
noobaaOperatorSecret := &v1.Secret{}
Expand Down Expand Up @@ -874,10 +903,19 @@ func (s *OCSProviderServer) ReportStatus(ctx context.Context, req *pb.ReportStat
return nil, err
}

clientMappingConfig, err := s.getPeerClientMapping(ctx)
if err != nil {
return nil, err
}
clientIsMapped := false
if clientMappingConfig != nil && clientMappingConfig[req.StorageConsumerUUID] != "" {
clientIsMapped = true
}
desiredClientConfigHash := getDesiredClientConfigHash(
channelName,
storageConsumer,
isEncryptionInTransitEnabled(storageCluster.Spec.Network),
clientIsMapped,
)

return &pb.ReportStatusResponse{
Expand All @@ -886,11 +924,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 All @@ -910,6 +949,17 @@ func (s *OCSProviderServer) getOCSSubscriptionChannel(ctx context.Context) (stri
return subscription.Spec.Channel, nil
}

func (s *OCSProviderServer) getPeerClientMapping(ctx context.Context) (map[string]string, error) {
clientMappingConfig := &corev1.ConfigMap{}
clientMappingConfig.Name = storageclusterpeer.OcsClientPeerConfigMapName
clientMappingConfig.Namespace = s.namespace
err := s.client.Get(ctx, client.ObjectKeyFromObject(clientMappingConfig), clientMappingConfig)
if err != nil && !kerrors.IsNotFound(err) {
return nil, fmt.Errorf("failed to list storage cluster peers. %v", err)
}
return clientMappingConfig.Data, 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 67b79ba

Please sign in to comment.