Skip to content

Commit

Permalink
Fix ownerRef setting bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Jont828 committed Nov 15, 2023
1 parent dbca52a commit cee1ae1
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (r *DockerMachinePoolReconciler) reconcileDockerMachines(ctx context.Contex
// Providers should iterate through their infrastructure instances and ensure that each instance has a corresponding InfraMachine.
for _, machine := range externalMachines {
if existingMachine, ok := dockerMachineMap[machine.Name()]; ok {
log.V(4).Info("Patching existing DockerMachine", "name", existingMachine.Name)
log.V(2).Info("Patching existing DockerMachine", "name", existingMachine.Name)
desiredMachine := computeDesiredDockerMachine(machine.Name(), cluster, machinePool, dockerMachinePool, &existingMachine)
if err := ssa.Patch(ctx, r.Client, dockerMachinePoolControllerName, desiredMachine, ssa.WithCachingProxy{Cache: r.ssaCache, Original: &existingMachine}); err != nil {
return errors.Wrapf(err, "failed to update DockerMachine %q", klog.KObj(desiredMachine))
Expand Down Expand Up @@ -258,16 +258,17 @@ func computeDesiredDockerMachine(name string, cluster *clusterv1.Cluster, machin
}

if existingDockerMachine != nil {
dockerMachine = existingDockerMachine
dockerMachine.SetUID(existingDockerMachine.UID)
dockerMachine.SetOwnerReferences(existingDockerMachine.OwnerReferences)
}

// Note: Since the MachinePool controller has not created its owner Machine yet, we want to set the DockerMachinePool as the owner so it's not orphaned.
util.EnsureOwnerRef(dockerMachine.OwnerReferences, metav1.OwnerReference{
dockerMachine.SetOwnerReferences(util.EnsureOwnerRef(dockerMachine.OwnerReferences, metav1.OwnerReference{
APIVersion: dockerMachinePool.APIVersion,
Kind: dockerMachinePool.Kind,
Name: dockerMachinePool.Name,
UID: dockerMachinePool.UID,
})
}))
dockerMachine.Labels[clusterv1.ClusterNameLabel] = cluster.Name
dockerMachine.Labels[clusterv1.MachinePoolNameLabel] = format.MustFormatValue(machinePool.Name)

Expand Down

0 comments on commit cee1ae1

Please sign in to comment.