Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider: enable csi omap generator for client #2874

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading