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 8, 2024
1 parent c079ab8 commit 3325edc
Show file tree
Hide file tree
Showing 3 changed files with 54 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 (
ClientMappingConfigMapName = "client-mapping-config"
)

// StorageClusterPeerReconciler reconciles a StorageClusterPeer object
// nolint:revive
type StorageClusterPeerReconciler struct {
Expand Down
44 changes: 43 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,17 @@ func (s *OCSProviderServer) GetStorageConfig(ctx context.Context, req *pb.Storag
return nil, err
}

clientMappingConfig, err := s.getClientMapping(ctx)
if err != nil {
return nil, err
}
_, hasClientId := clientMappingConfig.Data[req.StorageConsumerUUID]

Check failure on line 232 in services/provider/server/server.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.22)

var-naming: var hasClientId should be hasClientID (revive)

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

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

}

//Enable CSI-OMAP is storageClusterPeer is present
clientMappingConfig, err := s.getClientMapping(ctx)
if err != nil {
return nil, err
}
_, hasClientId := clientMappingConfig.Data[string(consumerResource.UID)]

Check failure on line 434 in services/provider/server/server.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.22)

var-naming: var hasClientId should be hasClientID (revive)

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

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

clientMappingConfig, err := s.getClientMapping(ctx)
if err != nil {
return nil, err
}
_, hasClientId := clientMappingConfig.Data[req.StorageConsumerUUID]

Check failure on line 904 in services/provider/server/server.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.22)

var-naming: var hasClientId should be hasClientID (revive)

desiredClientConfigHash := getDesiredClientConfigHash(
channelName,
storageConsumer,
isEncryptionInTransitEnabled(storageCluster.Spec.Network),
hasClientId,
)

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

func (s *OCSProviderServer) getClientMapping(ctx context.Context) (*corev1.ConfigMap, error) {
clientMappingConfig := &corev1.ConfigMap{}
clientMappingConfig.Name = storageclusterpeer.ClientMappingConfigMapName
clientMappingConfig.Namespace = s.namespace
err := s.client.Get(ctx, client.ObjectKeyFromObject(clientMappingConfig), clientMappingConfig)
if err != nil {
return nil, fmt.Errorf("failed to list storage cluster peers. %v", err)
}
return clientMappingConfig, 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 3325edc

Please sign in to comment.