@@ -19,15 +19,13 @@ package cmd
1919import (
2020 "context"
2121 "fmt"
22- "time"
2322
2423 "github.com/spf13/cobra"
2524 corev1 "k8s.io/api/core/v1"
2625 kerrs "k8s.io/apimachinery/pkg/api/errors"
2726 "k8s.io/apimachinery/pkg/api/resource"
2827 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2928 "k8s.io/apimachinery/pkg/types"
30- "k8s.io/apimachinery/pkg/util/wait"
3129 "k8s.io/klog/v2"
3230 "k8s.io/kubectl/pkg/util/i18n"
3331 "k8s.io/kubectl/pkg/util/templates"
@@ -63,7 +61,7 @@ type migrationCreate struct {
6361 // SSH connections.
6462 ServiceType * corev1.ServiceType
6563 // client object to communicate with a cluster
66- clientObject client.Client
64+ client client.Client
6765 // PVC object associated with pvcName used to create destination object
6866 PVC * corev1.PersistentVolumeClaim
6967}
@@ -216,7 +214,7 @@ func (mc *migrationCreate) Run(ctx context.Context) error {
216214 if err != nil {
217215 return err
218216 }
219- mc .clientObject = k8sClient
217+ mc .client = k8sClient
220218
221219 // Get the pvc from cluster
222220 mc .PVC , err = mc .getDestinationPVC (ctx )
@@ -247,7 +245,7 @@ func (mc *migrationCreate) Run(ctx context.Context) error {
247245 }
248246
249247 // Wait for ReplicationDestination to post address, sshkeys
250- err = mc .waitForRDStatus (ctx )
248+ _ , err = mc .mr . data . Destination . waitForRDStatus (ctx , mc . client )
251249 if err != nil {
252250 return err
253251 }
@@ -264,7 +262,7 @@ func (mc *migrationCreate) ensureNamespace(ctx context.Context) (*corev1.Namespa
264262 Name : mc .Namespace ,
265263 },
266264 }
267- if err := mc .clientObject .Create (ctx , ns ); err != nil {
265+ if err := mc .client .Create (ctx , ns ); err != nil {
268266 if kerrs .IsAlreadyExists (err ) {
269267 klog .Infof ("Namespace: \" %s\" is found, proceeding with the same" ,
270268 mc .Namespace )
@@ -309,7 +307,7 @@ func (mc *migrationCreate) createDestinationPVC(ctx context.Context) (*corev1.Pe
309307 },
310308 }
311309
312- if err := mc .clientObject .Create (ctx , destPVC ); err != nil {
310+ if err := mc .client .Create (ctx , destPVC ); err != nil {
313311 return nil , err
314312 }
315313
@@ -325,7 +323,7 @@ func (mc *migrationCreate) getDestinationPVC(ctx context.Context) (*corev1.Persi
325323 Namespace : mc .Namespace ,
326324 Name : mc .DestinationPVC ,
327325 }
328- err := mc .clientObject .Get (ctx , pvcInfo , destPVC )
326+ err := mc .client .Get (ctx , pvcInfo , destPVC )
329327 if err != nil {
330328 if client .IgnoreNotFound (err ) == nil {
331329 klog .Infof ("pvc: \" %s\" not found, creating the same" , mc .DestinationPVC )
@@ -353,47 +351,11 @@ func (mc *migrationCreate) ensureReplicationDestination(ctx context.Context) (
353351 },
354352 },
355353 }
356- if err := mc .clientObject .Create (ctx , rd ); err != nil {
354+ if err := mc .client .Create (ctx , rd ); err != nil {
357355 return nil , err
358356 }
359357 klog .Infof ("Created ReplicationDestination: \" %s\" in Namespace: \" %s\" and Cluster: \" %s\" " ,
360358 rd .Name , rd .Namespace , rd .ClusterName )
361359
362360 return rd , nil
363361}
364-
365- func (mc * migrationCreate ) waitForRDStatus (ctx context.Context ) error {
366- mrd := mc .mr .data .Destination
367- // wait for migrationdestination to become ready
368- nsName := types.NamespacedName {
369- Namespace : mrd .Namespace ,
370- Name : mrd .RDName ,
371- }
372- rd := & volsyncv1alpha1.ReplicationDestination {}
373- err := wait .PollImmediate (5 * time .Second , 2 * time .Minute , func () (bool , error ) {
374- err := mc .clientObject .Get (ctx , nsName , rd )
375- if err != nil {
376- return false , err
377- }
378- if rd .Status == nil || rd .Status .Rsync == nil {
379- return false , nil
380- }
381- if rd .Status .Rsync .Address == nil {
382- klog .V (2 ).Infof ("Waiting for MigrationDestination %s RSync address to populate" , rd .Name )
383- return false , nil
384- }
385-
386- if rd .Status .Rsync .SSHKeys == nil {
387- klog .V (2 ).Infof ("Waiting for MigrationDestination %s RSync sshkeys to populate" , rd .Name )
388- return false , nil
389- }
390-
391- klog .V (2 ).Infof ("Found MigrationDestination RSync Address: %s" , * rd .Status .Rsync .Address )
392- return true , nil
393- })
394- if err != nil {
395- return fmt .Errorf ("failed to fetch rd status: %w," , err )
396- }
397-
398- return nil
399- }
0 commit comments