From facf805941e0deada2c3e7b9aaae1fc5cb1f224d Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 4 Nov 2024 15:12:41 +0100 Subject: [PATCH] rbd: implement GetFenceClients implemented GetFenceClients which connects to the ceph cluster and returns the ceph clusterID and the clientaddress that is used for rados connection. Signed-off-by: Madhu Rajanna --- internal/csi-addons/rbd/network_fence.go | 56 ++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/internal/csi-addons/rbd/network_fence.go b/internal/csi-addons/rbd/network_fence.go index b7f4d6bba..2a258ff7e 100644 --- a/internal/csi-addons/rbd/network_fence.go +++ b/internal/csi-addons/rbd/network_fence.go @@ -114,3 +114,59 @@ func (fcs *FenceControllerServer) UnfenceClusterNetwork( return &fence.UnfenceClusterNetworkResponse{}, nil } + +// GetFenceClients fetches the ceph cluster ID and the client address that need to be fenced. +func (fcs *FenceControllerServer) GetFenceClients( + ctx context.Context, + req *fence.GetFenceClientsRequest, +) (*fence.GetFenceClientsResponse, error) { + options := req.GetParameters() + clusterID, err := util.GetClusterID(options) + if err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + + cr, err := util.NewUserCredentials(req.GetSecrets()) + if err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + defer cr.DeleteCredentials() + + monitors, _ /* clusterID*/, err := util.GetMonsAndClusterID(ctx, clusterID, false) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + // Get the cluster ID of the ceph cluster. + conn := &util.ClusterConnection{} + err = conn.Connect(monitors, cr) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to connect to MONs %q: %s", monitors, err) + } + defer conn.Destroy() + + fsID, err := conn.GetFSID() + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to get cephfs id: %s", err) + } + + address, err := conn.GetAddrs() + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to get client address: %s", err) + } + + resp := &fence.GetFenceClientsResponse{ + Clients: []*fence.ClientDetails{ + { + Id: fsID, + Addresses: []*fence.CIDR{ + { + Cidr: address, + }, + }, + }, + }, + } + + return resp, nil +}