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

add rpc call for PeerBlockPool #2457

Closed
wants to merge 4 commits into from
Closed
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
29 changes: 28 additions & 1 deletion deploy/ocs-operator/manifests/provider-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@ rules:
- ""
resources:
- configmaps
- secrets
- services
verbs:
- get
- apiGroups:
- ""
resources:
- secrets
verbs:
- get
- create
- update
- apiGroups:
- ceph.rook.io
resources:
- cephblockpools/finalizers
verbs:
- update
- apiGroups:
- ceph.rook.io
resources:
Expand All @@ -19,6 +32,13 @@ rules:
verbs:
- get
- list
- apiGroups:
- ceph.rook.io
resources:
- cephblockpools
verbs:
- get
- update
- apiGroups:
- ocs.openshift.io
resources:
Expand Down Expand Up @@ -61,3 +81,10 @@ rules:
verbs:
- get
- list
- apiGroups:
- ceph.rook.io
resources:
- cephrbdmirrors
verbs:
- get
- create
29 changes: 28 additions & 1 deletion rbac/provider-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@ rules:
- ""
resources:
- configmaps
- secrets
- services
verbs:
- get
- apiGroups:
- ""
resources:
- secrets
verbs:
- get
- create
- update
- apiGroups:
- ceph.rook.io
resources:
- cephblockpools/finalizers
verbs:
- update
- apiGroups:
- ceph.rook.io
resources:
Expand All @@ -19,6 +32,13 @@ rules:
verbs:
- get
- list
- apiGroups:
- ceph.rook.io
resources:
- cephblockpools
verbs:
- get
- update
- apiGroups:
- ocs.openshift.io
resources:
Expand Down Expand Up @@ -61,3 +81,10 @@ rules:
verbs:
- get
- list
- apiGroups:
- ceph.rook.io
resources:
- cephrbdmirrors
verbs:
- get
- create
17 changes: 17 additions & 0 deletions services/provider/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,20 @@ func (cc *OCSProviderClient) ReportStatus(ctx context.Context, consumerUUID stri

return cc.Client.ReportStatus(apiCtx, req)
}

func (cc *OCSProviderClient) PeerBlockPool(ctx context.Context, secretName string, pool, token []byte) (*pb.PeerBlockPoolResponse, error) {
if cc.Client == nil || cc.clientConn == nil {
return nil, fmt.Errorf("OCS client is closed")
}

req := &pb.PeerBlockPoolRequest{
SecretName: secretName,
Pool: pool,
Token: token,
}

apiCtx, cancel := context.WithTimeout(ctx, cc.timeout)
defer cancel()

return cc.Client.PeerBlockPool(apiCtx, req)
}
267 changes: 206 additions & 61 deletions services/provider/pb/provider.pb.go

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions services/provider/pb/provider_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions services/provider/proto/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ service OCSProvider {

rpc ReportStatus(ReportStatusRequest)
returns (ReportStatusResponse){}
// PeerBlockPool RPC call to send the bootstrap secret for the pool
rpc PeerBlockPool(PeerBlockPoolRequest)
returns (PeerBlockPoolResponse){}
}

// OnboardConsumerRequest holds the required information to validate the consumer and create StorageConsumer
Expand Down Expand Up @@ -172,3 +175,14 @@ message ReportStatusResponse{
// Contains subscription channel of provider operator for client operator to match
string desiredClientOperatorChannel = 1;
}

message PeerBlockPoolRequest{
// secretName is the name of the bootstrap secret
string secretName = 1;
// pool base64 encoded name of the block pool
bytes pool = 2;
// token is secret information from bootstrap secret
bytes token = 3;
}

message PeerBlockPoolResponse{}
81 changes: 81 additions & 0 deletions services/provider/server/cephblockpool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package server

import (
"context"
"fmt"
"slices"

rookCephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
corev1 "k8s.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type cephBlockPoolManager struct {
client client.Client
namespace string
}

func newCephBlockPoolManager(cl client.Client, namespace string) (*cephBlockPoolManager, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that this task can be completed without any errors in the return type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following the same function defination that was there for the other two managers.

return &cephBlockPoolManager{
client: cl,
namespace: namespace,
}, nil
}

func (c *cephBlockPoolManager) EnableBlockPoolMirroring(ctx context.Context, cephBlockPool *rookCephv1.CephBlockPool) error {

cephBlockPool.Spec.Mirroring.Enabled = true
cephBlockPool.Spec.Mirroring.Mode = "image"

err := c.client.Update(ctx, cephBlockPool)
if err != nil {
return fmt.Errorf("failed to enable mirroring on CephBlockPool resource with name %q: %v", cephBlockPool.Name, err)
}

return nil

}

func (c *cephBlockPoolManager) SetBootstrapSecretRef(ctx context.Context, cephBlockPool *rookCephv1.CephBlockPool, secretName string, secretData map[string][]byte) error {

// create the secret
bootstrapSecret := &corev1.Secret{}
bootstrapSecret.Name = secretName
bootstrapSecret.Namespace = c.namespace

_, err := ctrl.CreateOrUpdate(ctx, c.client, bootstrapSecret, func() error {
bootstrapSecret.Data = secretData
return ctrl.SetControllerReference(cephBlockPool, bootstrapSecret, c.client.Scheme())
})
if err != nil {
return fmt.Errorf("failed to create/update the bootstrap secret %q: %v", secretName, err)
}

// set the secret ref
if cephBlockPool.Spec.Mirroring.Peers == nil {
cephBlockPool.Spec.Mirroring.Peers = &rookCephv1.MirroringPeerSpec{SecretNames: []string{secretName}}
} else {
if !slices.Contains(cephBlockPool.Spec.Mirroring.Peers.SecretNames, secretName) {
cephBlockPool.Spec.Mirroring.Peers.SecretNames = append(cephBlockPool.Spec.Mirroring.Peers.SecretNames, secretName)
}
}

err = c.client.Update(ctx, cephBlockPool)
if err != nil {
return fmt.Errorf("failed to set bootstrap secret ref on CephBlockPool resource with name %q: %v", cephBlockPool.Name, err)
}

return nil
}

func (c *cephBlockPoolManager) GetBlockPoolByName(ctx context.Context, blockPoolName string) (*rookCephv1.CephBlockPool, error) {
blockPool := &rookCephv1.CephBlockPool{}
blockPool.Name = blockPoolName
blockPool.Namespace = c.namespace
err := c.client.Get(ctx, client.ObjectKeyFromObject(blockPool), blockPool)
if err != nil {
return nil, err
}
return blockPool, nil
}
43 changes: 43 additions & 0 deletions services/provider/server/cephrbdmirror.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package server

import (
"context"

rookCephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const rBDMirrorName = "rbd-mirror"

type cephRBDMirrorManager struct {
client client.Client
namespace string
}

func newCephRBDMirrorManager(cl client.Client, namespace string) (*cephRBDMirrorManager, error) {
return &cephRBDMirrorManager{
client: cl,
namespace: namespace,
}, nil
}

func (c *cephRBDMirrorManager) Create(ctx context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason in not using creatorupdate from controller util?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about the case when we run MaintenanceMode (this requires the RBD mirror to be scaled down). If a new PeerBlockPool call is received while MaintenacneMode is in progress it and we use CreateOrUpdate, it will interfere with it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough, does the owner scale up after the maintenance mode?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be the responsibility of the controller executing the maintenance mode


cephRBDMirror := &rookCephv1.CephRBDMirror{}
cephRBDMirror.Name = rBDMirrorName
cephRBDMirror.Namespace = c.namespace
err := c.client.Get(ctx, client.ObjectKeyFromObject(cephRBDMirror), cephRBDMirror)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason in making two calls rather than a single create?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need one rbdMirror for the cluster, hence I am checking if it already exists, and create it only if it doesn't


// create if not found
if err != nil && kerrors.IsNotFound(err) {
cephRBDMirror.Spec = rookCephv1.RBDMirroringSpec{Count: 1}
err = c.client.Create(ctx, cephRBDMirror)
if err != nil {
return err
}
}

// if any other err/nil return it
return err
}
Loading
Loading