Skip to content

Commit

Permalink
add server implementation for revokeBlockPoolPeering rpc call
Browse files Browse the repository at this point in the history
Signed-off-by: Rewant Soni <resoni@redhat.com>
  • Loading branch information
rewantsoni committed Apr 29, 2024
1 parent a4678b3 commit bb9d7f3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions services/provider/server/cephblockpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c *cephBlockPoolManager) SetBootstrapSecretRef(ctx context.Context, cephBl
return nil
}

func (c *cephBlockPoolManager) UnSetBootstrapSecretRef(ctx context.Context, secretName string, cephBlockPool *rookCephv1.CephBlockPool) error {
func (c *cephBlockPoolManager) UnSetAndDeleteBootstrapSecret(ctx context.Context, secretName string, cephBlockPool *rookCephv1.CephBlockPool) error {

// remove the secret ref
index := slices.IndexFunc(cephBlockPool.Spec.Mirroring.Peers.SecretNames, func(s string) bool {
Expand All @@ -92,7 +92,9 @@ func (c *cephBlockPoolManager) UnSetBootstrapSecretRef(ctx context.Context, secr
bootstrapSecret.Name = secretName
bootstrapSecret.Namespace = c.namespace
err = c.client.Delete(ctx, bootstrapSecret)
if err != nil {
// there might be a case where the bootstrap secret was deleted but request failed after this and there was a retry,
// if error is IsNotFound, that means it is safe to proceed as we have deleted the bootstrap secret
if err != nil && !kerrors.IsNotFound(err) {
return fmt.Errorf("failed to delete the bootstrap secret %q: %v", secretName, err)
}
return nil
Expand Down
8 changes: 7 additions & 1 deletion services/provider/server/cephrbdmirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,11 @@ func (c *cephRBDMirrorManager) Delete(ctx context.Context) error {
Namespace: c.namespace,
},
}
return c.client.Delete(ctx, cephRBDMirrorObj)
err := c.client.Delete(ctx, cephRBDMirrorObj)
// there might be a case where the RBDMirror was deleted but request failed after this and there was a retry,
// if error is IsNotFound, that means it is safe to proceed as we have deleted the RBDMirror instance
if err != nil && !kerrors.IsNotFound(err) {
return err
}
return nil
}
10 changes: 3 additions & 7 deletions services/provider/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,10 +780,8 @@ func (s *OCSProviderServer) RevokeBlockPoolPeering(ctx context.Context, req *pb.
}

// delete secret and unset ref on the blockPool
err = s.cephBlockPoolManager.UnSetBootstrapSecretRef(ctx, req.SecretName, cephBlockPool)
// there might be a case where the bootstrap secret was deleted but request failed after this and there was a retry,
// if error is IsNotFound, that means it is safe to proceed as we have deleted the bootstrap secret
if err != nil && !kerrors.IsNotFound(err) {
err = s.cephBlockPoolManager.UnSetAndDeleteBootstrapSecret(ctx, req.SecretName, cephBlockPool)
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to unset bootstrap secret ref for CephBlockPool resource %s: %v", req.Pool, err)
}

Expand All @@ -801,9 +799,7 @@ func (s *OCSProviderServer) RevokeBlockPoolPeering(ctx context.Context, req *pb.
if !isRBDMirrorRequired {
klog.Infof("No bootstrap secret found for any block pools, removing the rbd mirror instance")
err := s.cephRBDMirrorManager.Delete(ctx)
// there might be a case where the RBDMirror was deleted but request failed after this and there was a retry,
// if error is IsNotFound, that means it is safe to proceed as we have deleted the RBDMirror instance
if err != nil && !kerrors.IsNotFound(err) {
if err != nil {
klog.Errorf("Failed to delete CephRBDMirror instance: %v", err)
return nil, status.Errorf(codes.Internal, "Failed to delete CephRBDMirror instance: %v", err)
}
Expand Down

0 comments on commit bb9d7f3

Please sign in to comment.