Skip to content

Commit 87fd4cf

Browse files
authored
Merge pull request #1616 from aaroniscode/clusterctl_pivot_fix
🐛Fixes an issue during clusterctl pivot when resource references are missing namespaces
2 parents 705c0b9 + dd78847 commit 87fd4cf

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

cmd/clusterctl/phases/pivot.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func moveCluster(from sourceClient, to targetClient, cluster *clusterv1.Cluster)
189189

190190
// Move infrastructure reference, if any.
191191
if cluster.Spec.InfrastructureRef != nil {
192-
if err := moveReference(from, to, cluster.Spec.InfrastructureRef); err != nil {
192+
if err := moveReference(from, to, cluster.Spec.InfrastructureRef, cluster.Namespace); err != nil {
193193
return errors.Wrapf(err, "error copying Cluster %s/%s infrastructure reference to target cluster",
194194
cluster.Namespace, cluster.Name)
195195
}
@@ -303,7 +303,7 @@ func moveMachineDeployment(from sourceClient, to targetClient, md *clusterv1.Mac
303303
}
304304

305305
// Move infrastructure reference.
306-
if err := moveReference(from, to, &md.Spec.Template.Spec.InfrastructureRef); err != nil {
306+
if err := moveReference(from, to, &md.Spec.Template.Spec.InfrastructureRef, md.Namespace); err != nil {
307307
return errors.Wrapf(err, "error copying MachineSet %s/%s infrastructure reference to target cluster",
308308
md.Namespace, md.Name)
309309
}
@@ -356,7 +356,7 @@ func moveMachineSet(from sourceClient, to targetClient, ms *clusterv1.MachineSet
356356
// When a MachineSet is owned by a MachineDeployment, the referenced template has already been moved
357357
// by the time this function is called.
358358
if metav1.GetControllerOf(ms) == nil {
359-
if err := moveReference(from, to, &ms.Spec.Template.Spec.InfrastructureRef); err != nil {
359+
if err := moveReference(from, to, &ms.Spec.Template.Spec.InfrastructureRef, ms.Namespace); err != nil {
360360
return errors.Wrapf(err, "error copying MachineSet %s/%s infrastructure reference to target cluster",
361361
ms.Namespace, ms.Name)
362362
}
@@ -405,14 +405,14 @@ func moveMachine(from sourceClient, to targetClient, m *clusterv1.Machine) error
405405

406406
// Move bootstrap reference, if any.
407407
if m.Spec.Bootstrap.ConfigRef != nil {
408-
if err := moveReference(from, to, m.Spec.Bootstrap.ConfigRef); err != nil {
408+
if err := moveReference(from, to, m.Spec.Bootstrap.ConfigRef, m.Namespace); err != nil {
409409
return errors.Wrapf(err, "error copying Machine %s/%s bootstrap reference to target cluster",
410410
m.Namespace, m.Name)
411411
}
412412
}
413413

414414
// Move infrastructure reference.
415-
if err := moveReference(from, to, &m.Spec.InfrastructureRef); err != nil {
415+
if err := moveReference(from, to, &m.Spec.InfrastructureRef, m.Namespace); err != nil {
416416
return errors.Wrapf(err, "error copying Machine %s/%s infrastructure reference to target cluster",
417417
m.Namespace, m.Name)
418418
}
@@ -434,11 +434,11 @@ func moveMachine(from sourceClient, to targetClient, m *clusterv1.Machine) error
434434
return nil
435435
}
436436

437-
func moveReference(from sourceClient, to targetClient, ref *corev1.ObjectReference) error {
437+
func moveReference(from sourceClient, to targetClient, ref *corev1.ObjectReference, namespace string) error {
438438
u := &unstructured.Unstructured{}
439439
u.SetAPIVersion(ref.APIVersion)
440440
u.SetKind(ref.Kind)
441-
u.SetNamespace(ref.Namespace)
441+
u.SetNamespace(namespace)
442442
u.SetName(ref.Name)
443443
if err := from.GetUnstructuredObject(u); err != nil {
444444
return errors.Wrapf(err, "error fetching unstructured object %q %s/%s",

0 commit comments

Comments
 (0)