Skip to content

Commit e27a97d

Browse files
Merge pull request #313 from umangachapagain/provider-mdr-fixes
Fixes for MDR with provider mode
2 parents 8e08f35 + 078a7fc commit e27a97d

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

addons/agent_mirrorpeer_controller.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,17 +356,36 @@ func (r *MirrorPeerReconciler) hasSpokeCluster(obj client.Object) bool {
356356
return false
357357
}
358358

359+
func (r *MirrorPeerReconciler) hasProviderSpokeCluster(obj client.Object) bool {
360+
mp, ok := obj.(*multiclusterv1alpha1.MirrorPeer)
361+
if !ok {
362+
return false
363+
}
364+
if mp.Status.Phase == multiclusterv1alpha1.IncompatibleVersion {
365+
return false
366+
}
367+
peerRefs, err := utils.GetPeerRefForProviderCluster(context.TODO(), r.SpokeClient, r.HubClient, mp)
368+
if err != nil {
369+
r.Logger.Error("Unable to reconcile MirrorPeer", "MirrorPeer", mp.GetName(), "Error", err)
370+
return false
371+
}
372+
if len(peerRefs) > 0 {
373+
return true
374+
}
375+
return false
376+
}
377+
359378
// SetupWithManager sets up the controller with the Manager.
360379
func (r *MirrorPeerReconciler) SetupWithManager(mgr ctrl.Manager) error {
361380
mirrorPeerSpokeClusterPredicate := predicate.Funcs{
362381
CreateFunc: func(e event.CreateEvent) bool {
363-
return r.hasSpokeCluster(e.Object)
382+
return r.hasSpokeCluster(e.Object) || r.hasProviderSpokeCluster(e.Object)
364383
},
365384
DeleteFunc: func(e event.DeleteEvent) bool {
366-
return r.hasSpokeCluster(e.Object)
385+
return r.hasSpokeCluster(e.Object) || r.hasProviderSpokeCluster(e.Object)
367386
},
368387
UpdateFunc: func(e event.UpdateEvent) bool {
369-
return r.hasSpokeCluster(e.ObjectNew)
388+
return r.hasSpokeCluster(e.ObjectNew) || r.hasProviderSpokeCluster(e.ObjectNew)
370389
},
371390
GenericFunc: func(_ event.GenericEvent) bool {
372391
return false

addons/s3_secret_handler.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (r *S3SecretReconciler) syncBlueSecretForS3(ctx context.Context, name strin
6666
return fmt.Errorf("failed to find client peerRef for current provider cluster %s. %w", r.SpokeClusterName, err)
6767
}
6868
if len(storagePeerRefList) > 1 {
69-
return fmt.Errorf("MirrorPeer has multiple clients pointing to same provider which is unsupported")
69+
s3ProfileName = fmt.Sprintf("%s-%s", utils.S3ProfilePrefix, r.SpokeClusterName)
7070
}
7171
if len(storagePeerRefList) < 1 {
7272
r.Logger.Info("OBC references MirrorPeer which is not related to this provider.", "OBC Name", name, "OBC Namespace", namespace, "MirrorPeer", mirrorPeerName)
@@ -77,7 +77,9 @@ func (r *S3SecretReconciler) syncBlueSecretForS3(ctx context.Context, name strin
7777
}
7878

7979
storageClusterRef = &storagePeerRef.StorageClusterRef
80-
s3ProfileName = fmt.Sprintf("%s-%s-%s", utils.S3ProfilePrefix, storagePeerRef.ClusterName, storagePeerRef.StorageClusterRef.Name)
80+
if s3ProfileName == "" {
81+
s3ProfileName = fmt.Sprintf("%s-%s-%s", utils.S3ProfilePrefix, storagePeerRef.ClusterName, storagePeerRef.StorageClusterRef.Name)
82+
}
8183

8284
// fetch s3 endpoint
8385
route := &routev1.Route{}

controllers/mirrorpeer_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func (r *MirrorPeerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
325325
}
326326
}
327327

328-
if hasStorageClientRef {
328+
if hasStorageClientRef && mirrorPeer.Spec.Type == multiclusterv1alpha1.Async {
329329
result, err := createStorageClusterPeer(ctx, r.Client, logger, r.CurrentNamespace, mirrorPeer)
330330
if err != nil {
331331
logger.Error("Failed to create StorageClusterPeer", "error", err)

0 commit comments

Comments
 (0)