Skip to content

Commit 7b5b587

Browse files
committed
refactor: address code review comments
Signed-off-by: Tarun Gupta Akirala <[email protected]>
1 parent 7176f79 commit 7b5b587

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

cmd/clusterctl/client/cluster/mover.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (o *objectMover) Move(namespace string, toCluster Client, dryRun bool, muta
9595
proxy = toCluster.Proxy()
9696
}
9797

98-
return o.move(objectGraph, proxy, mutators)
98+
return o.move(objectGraph, proxy, mutators...)
9999
}
100100

101101
func (o *objectMover) ToDirectory(namespace string, directory string) error {
@@ -312,7 +312,7 @@ func getMachineObj(proxy Proxy, machine *node, machineObj *clusterv1.Machine) er
312312
}
313313

314314
// Move moves all the Cluster API objects existing in a namespace (or from all the namespaces if empty) to a target management cluster.
315-
func (o *objectMover) move(graph *objectGraph, toProxy Proxy, mutators []ResourceMutatorFunc) error {
315+
func (o *objectMover) move(graph *objectGraph, toProxy Proxy, mutators ...ResourceMutatorFunc) error {
316316
log := logf.Log
317317

318318
clusters := graph.getClusters()
@@ -323,12 +323,12 @@ func (o *objectMover) move(graph *objectGraph, toProxy Proxy, mutators []Resourc
323323

324324
// Sets the pause field on the Cluster object in the source management cluster, so the controllers stop reconciling it.
325325
log.V(1).Info("Pausing the source cluster")
326-
if err := setClusterPause(o.fromProxy, clusters, nil, true, o.dryRun); err != nil {
326+
if err := setClusterPause(o.fromProxy, clusters, true, o.dryRun); err != nil {
327327
return err
328328
}
329329

330330
log.V(1).Info("Pausing the source ClusterClasses")
331-
if err := setClusterClassPause(o.fromProxy, clusterClasses, nil, true, o.dryRun); err != nil {
331+
if err := setClusterClassPause(o.fromProxy, clusterClasses, true, o.dryRun); err != nil {
332332
return errors.Wrap(err, "error pausing ClusterClasses")
333333
}
334334

@@ -348,7 +348,7 @@ func (o *objectMover) move(graph *objectGraph, toProxy Proxy, mutators []Resourc
348348
// Create all objects group by group, ensuring all the ownerReferences are re-created.
349349
log.Info("Creating objects in the target cluster")
350350
for groupIndex := 0; groupIndex < len(moveSequence.groups); groupIndex++ {
351-
if err := o.createGroup(moveSequence.getGroup(groupIndex), toProxy, mutators); err != nil {
351+
if err := o.createGroup(moveSequence.getGroup(groupIndex), toProxy, mutators...); err != nil {
352352
return err
353353
}
354354
}
@@ -363,13 +363,13 @@ func (o *objectMover) move(graph *objectGraph, toProxy Proxy, mutators []Resourc
363363

364364
// Resume the ClusterClasses in the target management cluster, so the controllers start reconciling it.
365365
log.V(1).Info("Resuming the target ClusterClasses")
366-
if err := setClusterClassPause(toProxy, clusterClasses, mutators, false, o.dryRun); err != nil {
366+
if err := setClusterClassPause(toProxy, clusterClasses, false, o.dryRun, mutators...); err != nil {
367367
return errors.Wrap(err, "error resuming ClusterClasses")
368368
}
369369

370370
// Reset the pause field on the Cluster object in the target management cluster, so the controllers start reconciling it.
371371
log.V(1).Info("Resuming the target cluster")
372-
return setClusterPause(toProxy, clusters, mutators, false, o.dryRun)
372+
return setClusterPause(toProxy, clusters, false, o.dryRun, mutators...)
373373
}
374374

375375
func (o *objectMover) toDirectory(graph *objectGraph, directory string) error {
@@ -383,12 +383,12 @@ func (o *objectMover) toDirectory(graph *objectGraph, directory string) error {
383383

384384
// Sets the pause field on the Cluster object in the source management cluster, so the controllers stop reconciling it.
385385
log.V(1).Info("Pausing the source cluster")
386-
if err := setClusterPause(o.fromProxy, clusters, nil, true, o.dryRun); err != nil {
386+
if err := setClusterPause(o.fromProxy, clusters, true, o.dryRun); err != nil {
387387
return err
388388
}
389389

390390
log.V(1).Info("Pausing the source ClusterClasses")
391-
if err := setClusterClassPause(o.fromProxy, clusterClasses, nil, true, o.dryRun); err != nil {
391+
if err := setClusterClassPause(o.fromProxy, clusterClasses, true, o.dryRun); err != nil {
392392
return errors.Wrap(err, "error pausing ClusterClasses")
393393
}
394394

@@ -409,13 +409,13 @@ func (o *objectMover) toDirectory(graph *objectGraph, directory string) error {
409409

410410
// Resume the ClusterClasses in the target management cluster, so the controllers start reconciling it.
411411
log.V(1).Info("Resuming the target ClusterClasses")
412-
if err := setClusterClassPause(o.fromProxy, clusterClasses, nil, false, o.dryRun); err != nil {
412+
if err := setClusterClassPause(o.fromProxy, clusterClasses, false, o.dryRun); err != nil {
413413
return errors.Wrap(err, "error resuming ClusterClasses")
414414
}
415415

416416
// Reset the pause field on the Cluster object in the target management cluster, so the controllers start reconciling it.
417417
log.V(1).Info("Resuming the source cluster")
418-
return setClusterPause(o.fromProxy, clusters, nil, false, o.dryRun)
418+
return setClusterPause(o.fromProxy, clusters, false, o.dryRun)
419419
}
420420

421421
func (o *objectMover) fromDirectory(graph *objectGraph, toProxy Proxy) error {
@@ -450,14 +450,14 @@ func (o *objectMover) fromDirectory(graph *objectGraph, toProxy Proxy) error {
450450
// Resume reconciling the ClusterClasses after being restored from a backup.
451451
// By default, during backup, ClusterClasses are paused so they must be unpaused to be used again
452452
log.V(1).Info("Resuming the target ClusterClasses")
453-
if err := setClusterClassPause(toProxy, clusterClasses, nil, false, o.dryRun); err != nil {
453+
if err := setClusterClassPause(toProxy, clusterClasses, false, o.dryRun); err != nil {
454454
return errors.Wrap(err, "error resuming ClusterClasses")
455455
}
456456

457457
// Resume reconciling the Clusters after being restored from a directory.
458458
// By default, when moved to a directory, Clusters are paused, so they must be unpaused to be used again.
459459
log.V(1).Info("Resuming the target cluster")
460-
return setClusterPause(toProxy, clusters, nil, false, o.dryRun)
460+
return setClusterPause(toProxy, clusters, false, o.dryRun)
461461
}
462462

463463
// moveSequence defines a list of group of moveGroups.
@@ -536,7 +536,7 @@ func getMoveSequence(graph *objectGraph) *moveSequence {
536536
}
537537

538538
// setClusterPause sets the paused field on nodes referring to Cluster objects.
539-
func setClusterPause(proxy Proxy, clusters []*node, mutators []ResourceMutatorFunc, value bool, dryRun bool) error {
539+
func setClusterPause(proxy Proxy, clusters []*node, value bool, dryRun bool, mutators ...ResourceMutatorFunc) error {
540540
if dryRun {
541541
return nil
542542
}
@@ -557,7 +557,7 @@ func setClusterPause(proxy Proxy, clusters []*node, mutators []ResourceMutatorFu
557557

558558
// Nb. The operation is wrapped in a retry loop to make setClusterPause more resilient to unexpected conditions.
559559
if err := retryWithExponentialBackoff(setClusterPauseBackoff, func() error {
560-
return patchCluster(proxy, cluster, patch, mutators)
560+
return patchCluster(proxy, cluster, patch, mutators...)
561561
}); err != nil {
562562
return errors.Wrapf(err, "error setting Cluster.Spec.Paused=%t", value)
563563
}
@@ -566,7 +566,7 @@ func setClusterPause(proxy Proxy, clusters []*node, mutators []ResourceMutatorFu
566566
}
567567

568568
// setClusterClassPause sets the paused annotation on nodes referring to ClusterClass objects.
569-
func setClusterClassPause(proxy Proxy, clusterclasses []*node, mutators []ResourceMutatorFunc, pause bool, dryRun bool) error {
569+
func setClusterClassPause(proxy Proxy, clusterclasses []*node, pause bool, dryRun bool, mutators ...ResourceMutatorFunc) error {
570570
if dryRun {
571571
return nil
572572
}
@@ -584,7 +584,7 @@ func setClusterClassPause(proxy Proxy, clusterclasses []*node, mutators []Resour
584584

585585
// Nb. The operation is wrapped in a retry loop to make setClusterClassPause more resilient to unexpected conditions.
586586
if err := retryWithExponentialBackoff(setClusterClassPauseBackoff, func() error {
587-
return pauseClusterClass(proxy, clusterclass, pause, mutators)
587+
return pauseClusterClass(proxy, clusterclass, pause, mutators...)
588588
}); err != nil {
589589
return errors.Wrapf(err, "error updating ClusterClass %s/%s", clusterclass.identity.Namespace, clusterclass.identity.Name)
590590
}
@@ -593,7 +593,7 @@ func setClusterClassPause(proxy Proxy, clusterclasses []*node, mutators []Resour
593593
}
594594

595595
// patchCluster applies a patch to a node referring to a Cluster object.
596-
func patchCluster(proxy Proxy, n *node, patch client.Patch, mutators []ResourceMutatorFunc) error {
596+
func patchCluster(proxy Proxy, n *node, patch client.Patch, mutators ...ResourceMutatorFunc) error {
597597
cFrom, err := proxy.NewClient()
598598
if err != nil {
599599
return err
@@ -622,7 +622,7 @@ func patchCluster(proxy Proxy, n *node, patch client.Patch, mutators []ResourceM
622622
return nil
623623
}
624624

625-
func pauseClusterClass(proxy Proxy, n *node, pause bool, mutators []ResourceMutatorFunc) error {
625+
func pauseClusterClass(proxy Proxy, n *node, pause bool, mutators ...ResourceMutatorFunc) error {
626626
cFrom, err := proxy.NewClient()
627627
if err != nil {
628628
return errors.Wrap(err, "error creating client")
@@ -768,7 +768,7 @@ func (o *objectMover) ensureNamespace(toProxy Proxy, namespace string) error {
768768
}
769769

770770
// createGroup creates all the Kubernetes objects into the target management cluster corresponding to the object graph nodes in a moveGroup.
771-
func (o *objectMover) createGroup(group moveGroup, toProxy Proxy, mutators []ResourceMutatorFunc) error {
771+
func (o *objectMover) createGroup(group moveGroup, toProxy Proxy, mutators ...ResourceMutatorFunc) error {
772772
createTargetObjectBackoff := newWriteBackoff()
773773
errList := []error{}
774774

cmd/clusterctl/client/cluster/mover_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ func Test_objectMover_move(t *testing.T) {
12261226
if includeMutator {
12271227
mutators = append(mutators, namespaceMutator)
12281228
}
1229-
err := mover.move(graph, toProxy, mutators)
1229+
err := mover.move(graph, toProxy, mutators...)
12301230

12311231
if tt.wantErr {
12321232
g.Expect(err).To(HaveOccurred())

cmd/clusterctl/client/move_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ type fakeObjectMover struct {
298298
fromDirectoryErr error
299299
}
300300

301-
func (f *fakeObjectMover) Move(namespace string, toCluster cluster.Client, dryRun bool, mutators ...cluster.ResourceMutatorFunc) error {
301+
func (f *fakeObjectMover) Move(_ string, _ cluster.Client, _ bool, _ ...cluster.ResourceMutatorFunc) error {
302302
return f.moveErr
303303
}
304304

0 commit comments

Comments
 (0)