Skip to content

Commit

Permalink
provider: add server side implementation of rpc calls
Browse files Browse the repository at this point in the history
Signed-off-by: Rewant Soni <[email protected]>
  • Loading branch information
rewantsoni committed Nov 6, 2024
1 parent 49aa084 commit 041ad20
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions controllers/storageconsumer/storageconsumer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
StorageProfileLabel = "ocs.openshift.io/storageprofile"
ConsumerUUIDLabel = "ocs.openshift.io/storageconsumer-uuid"
StorageConsumerNameLabel = "ocs.openshift.io/storageconsumer-name"
MaintenanceModeLabel = "ocs.openshift.io/maintenanceMode"
)

// StorageConsumerReconciler reconciles a StorageConsumer object
Expand Down
8 changes: 8 additions & 0 deletions services/provider/server/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,11 @@ func (c *ocsConsumerManager) UpdateConsumerStatus(ctx context.Context, id string
klog.Infof("successfully updated Status for StorageConsumer %v", consumerObj.Name)
return nil
}

func (c *ocsConsumerManager) Update(ctx context.Context, consumer *ocsv1alpha1.StorageConsumer) error {
if err := c.client.Update(ctx, consumer); err != nil {
return fmt.Errorf("failed to update StorageConsumer %v: %v", consumer.Name, err)
}
klog.Infof("successfully updated StorageConsumer %v", consumer.Name)
return nil
}
52 changes: 52 additions & 0 deletions 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"
appsv1 "k8s.io/api/apps/v1"
"math"
"net"
"slices"
Expand Down Expand Up @@ -949,3 +950,54 @@ func extractMonitorIps(data string) ([]string, error) {
func (s *OCSProviderServer) PeerStorageCluster(_ context.Context, _ *pb.PeerStorageClusterRequest) (*pb.PeerStorageClusterResponse, error) {
return &pb.PeerStorageClusterResponse{}, nil
}

func (s *OCSProviderServer) StartMaintenanceMode(ctx context.Context, req *pb.StartMaintenanceModeRequest) (*pb.StartMaintenanceModeResponse, error) {
// Get storage consumer resource using UUID
consumer, err := s.consumerManager.Get(ctx, req.StorageConsumerUUID)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}

util.AddLabel(consumer, controllers.MaintenanceModeLabel, "")
err = s.consumerManager.Update(ctx, consumer)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}

return &pb.StartMaintenanceModeResponse{}, nil
}

func (s *OCSProviderServer) StopMaintenanceMode(ctx context.Context, req *pb.StopMaintenanceModeRequest) (*pb.StopMaintenanceModeResponse, error) {
// Get storage consumer resource using UUID
consumer, err := s.consumerManager.Get(ctx, req.StorageConsumerUUID)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}

//TODO: Remove Label

if err := s.consumerManager.Update(ctx, consumer); err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}

return &pb.StopMaintenanceModeResponse{}, nil
}

func (s *OCSProviderServer) GetMaintenanceModeStatus(ctx context.Context, req *pb.GetMaintenanceModeStatusRequest) (*pb.GetMaintenanceModeStatusResponse, error) {
// Get storage consumer resource using UUID
_, err := s.consumerManager.Get(ctx, req.StorageConsumerUUID)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}

rbdMirrorDeployments := &appsv1.DeploymentList{}
err = s.client.List(ctx, rbdMirrorDeployments, client.InNamespace(s.namespace), client.MatchingLabels{"app": "rook-ceph-rbd-mirror"}, client.Limit(1))
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}
replicas := rbdMirrorDeployments.Items[0].Status.Replicas
if replicas == 1 {
return &pb.GetMaintenanceModeStatusResponse{MmintenanceStatus: pb.GetMaintenanceModeStatusResponse_Progressing}, nil
}
return &pb.GetMaintenanceModeStatusResponse{MmintenanceStatus: pb.GetMaintenanceModeStatusResponse_Completed}, nil
}

0 comments on commit 041ad20

Please sign in to comment.