-
Notifications
You must be signed in to change notification settings - Fork 185
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
Changes from all commits
df9b868
7a480fb
ace6209
d520db2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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) { | ||
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 | ||
} |
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason in not using creatorupdate from controller util? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fair enough, does the owner scale up after the maintenance mode? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason in making two calls rather than a single create? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.