-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add server implementation for peerblockpool rpc call
Signed-off-by: Rewant Soni <[email protected]>
- Loading branch information
1 parent
f02ece5
commit d06eb77
Showing
5 changed files
with
230 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"slices" | ||
|
||
rookCephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
kerrors "k8s.io/apimachinery/pkg/api/errors" | ||
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 { | ||
if kerrors.IsNotFound(err) { | ||
return nil, fmt.Errorf("CephBlockPool resource %q not found: %v", blockPoolName, err) | ||
} | ||
return nil, fmt.Errorf("failed to get CephBlockPool resource with name %q: %v", blockPoolName, err) | ||
} | ||
return blockPool, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
cephRBDMirror := &rookCephv1.CephRBDMirror{} | ||
cephRBDMirror.Name = rBDMirrorName | ||
cephRBDMirror.Namespace = c.namespace | ||
err := c.client.Get(ctx, client.ObjectKeyFromObject(cephRBDMirror), cephRBDMirror) | ||
|
||
// 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters