-
Notifications
You must be signed in to change notification settings - Fork 552
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
rbd: VolumeGroupReplicationContent controller to regenerate the OMAP data #4750
Open
iPraveenParihar
wants to merge
4
commits into
ceph:devel
Choose a base branch
from
iPraveenParihar:vg/replication-omap-regenerate
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ae831e6
journal: pass groupUUID to be used for omap name reserve
iPraveenParihar 5d7b9e1
rbd: add RegenerateVolumeGroupJournal method for Manager interface
iPraveenParihar 39c7102
rbd: controller to regenerate volume group omap data
iPraveenParihar 1f3ef79
helm: add RBACS for replication.storage.openshift.io
iPraveenParihar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
200 changes: 200 additions & 0 deletions
200
internal/controller/volumegroup/volumegroupreplicationcontent.go
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,200 @@ | ||
/* | ||
Copyright 2024 The Ceph-CSI Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package volumegroup | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
replicationv1alpha1 "github.com/csi-addons/kubernetes-csi-addons/api/replication.storage/v1alpha1" | ||
corev1 "k8s.io/api/core/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/controller" | ||
"sigs.k8s.io/controller-runtime/pkg/handler" | ||
"sigs.k8s.io/controller-runtime/pkg/manager" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
"sigs.k8s.io/controller-runtime/pkg/source" | ||
|
||
iPraveenParihar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ctrl "github.com/ceph/ceph-csi/internal/controller" | ||
"github.com/ceph/ceph-csi/internal/rbd" | ||
"github.com/ceph/ceph-csi/internal/util" | ||
"github.com/ceph/ceph-csi/internal/util/log" | ||
) | ||
|
||
type ReconcileVGRContent struct { | ||
client client.Client | ||
config ctrl.Config | ||
Locks *util.VolumeLocks | ||
} | ||
|
||
var ( | ||
_ reconcile.Reconciler = &ReconcileVGRContent{} | ||
_ ctrl.Manager = &ReconcileVGRContent{} | ||
) | ||
|
||
const ( | ||
secretNameParameterName = "replication.storage.openshift.io/group-replication-secret-name" | ||
secretNamespaceParameterName = "replication.storage.openshift.io/group-replication-secret-namespace" | ||
) | ||
|
||
// Init will add the ReconcileVGRContent to the list. | ||
func Init() { | ||
// add ReconcileVGRContent to the list | ||
ctrl.ControllerList = append(ctrl.ControllerList, &ReconcileVGRContent{}) | ||
} | ||
|
||
// Add adds the newVGRContentReconciler. | ||
func (r *ReconcileVGRContent) Add(mgr manager.Manager, config ctrl.Config) error { | ||
return add(mgr, newVGRContentReconciler(mgr, config)) | ||
} | ||
|
||
// newVGRContentReconciler returns a ReconcileVGRContent. | ||
func newVGRContentReconciler(mgr manager.Manager, config ctrl.Config) reconcile.Reconciler { | ||
r := &ReconcileVGRContent{ | ||
client: mgr.GetClient(), | ||
config: config, | ||
Locks: util.NewVolumeLocks(), | ||
} | ||
|
||
return r | ||
} | ||
|
||
func add(mgr manager.Manager, r reconcile.Reconciler) error { | ||
// Create a new controller | ||
c, err := controller.New( | ||
"vgrcontent-controller", | ||
mgr, | ||
controller.Options{MaxConcurrentReconciles: 1, Reconciler: r}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Watch for changes to VolumeGroupReplicationContent | ||
err = c.Watch(source.Kind( | ||
mgr.GetCache(), | ||
&replicationv1alpha1.VolumeGroupReplicationContent{}, | ||
iPraveenParihar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
&handler.TypedEnqueueRequestForObject[*replicationv1alpha1.VolumeGroupReplicationContent]{}), | ||
) | ||
if err != nil { | ||
return fmt.Errorf("failed to watch the changes: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (r *ReconcileVGRContent) getSecrets( | ||
ctx context.Context, | ||
name, | ||
namespace string, | ||
) (map[string]string, error) { | ||
if name == "" || namespace == "" { | ||
return nil, errors.New("secret name or secret namespace is empty") | ||
} | ||
secret := &corev1.Secret{} | ||
err := r.client.Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, secret) | ||
if err != nil { | ||
return nil, fmt.Errorf("error getting secret %s in namespace %s: %w", name, namespace, err) | ||
} | ||
|
||
secrets := map[string]string{} | ||
for key, value := range secret.Data { | ||
secrets[key] = string(value) | ||
} | ||
|
||
return secrets, nil | ||
} | ||
|
||
func (r *ReconcileVGRContent) reconcileVGRContent(ctx context.Context, obj runtime.Object) error { | ||
vgrc, ok := obj.(*replicationv1alpha1.VolumeGroupReplicationContent) | ||
if !ok { | ||
return nil | ||
} | ||
if vgrc.Spec.Provisioner != r.config.DriverName { | ||
return nil | ||
} | ||
|
||
reqName := vgrc.Name | ||
groupHandle := vgrc.Spec.VolumeGroupReplicationHandle | ||
iPraveenParihar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
volumeIds := vgrc.Spec.Source.VolumeHandles | ||
|
||
if groupHandle == "" { | ||
return errors.New("volume group replication handle is empty") | ||
} | ||
|
||
vgrClass := &replicationv1alpha1.VolumeGroupReplicationClass{} | ||
err := r.client.Get(ctx, types.NamespacedName{Name: vgrc.Spec.VolumeGroupReplicationClassName}, vgrClass) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if ok = r.Locks.TryAcquire(groupHandle); !ok { | ||
return fmt.Errorf("failed to acquire lock for group handle %s", groupHandle) | ||
} | ||
defer r.Locks.Release(groupHandle) | ||
|
||
parameters := vgrClass.Spec.Parameters | ||
secretName := vgrClass.Spec.Parameters[secretNameParameterName] | ||
secretNamespace := vgrClass.Spec.Parameters[secretNamespaceParameterName] | ||
|
||
secrets, err := r.getSecrets(ctx, secretName, secretNamespace) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
mgr := rbd.NewManager(r.config.InstanceID, parameters, secrets) | ||
defer mgr.Destroy(ctx) | ||
|
||
groupID, err := mgr.RegenerateVolumeGroupJournal(ctx, groupHandle, reqName, volumeIds) | ||
if err != nil { | ||
return err | ||
} | ||
if groupID != groupHandle { | ||
log.DebugLog(ctx, "groupHandle changed from %s to %s", groupHandle, groupID) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Reconcile reconciles the VolumeGroupReplicationContent object and creates a new omap entries | ||
// for the volume group. | ||
func (r *ReconcileVGRContent) Reconcile(ctx context.Context, | ||
request reconcile.Request, | ||
) (reconcile.Result, error) { | ||
vgrc := &replicationv1alpha1.VolumeGroupReplicationContent{} | ||
err := r.client.Get(ctx, request.NamespacedName, vgrc) | ||
if err != nil { | ||
if apierrors.IsNotFound(err) { | ||
return reconcile.Result{}, nil | ||
} | ||
|
||
return reconcile.Result{}, err | ||
} | ||
// Check if the object is under deletion | ||
if !vgrc.GetDeletionTimestamp().IsZero() { | ||
return reconcile.Result{}, nil | ||
} | ||
|
||
err = r.reconcileVGRContent(ctx, vgrc) | ||
if err != nil { | ||
return reconcile.Result{}, err | ||
} | ||
|
||
return reconcile.Result{}, 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we already have require section for indirect dep, this should be added there, please check