Skip to content

Commit

Permalink
[machineset] Change ordering of template cloning to clone bootstrap t…
Browse files Browse the repository at this point in the history
…emplate prior to infrastructure template
  • Loading branch information
detiber committed Oct 23, 2019
1 parent a767ac6 commit 84f06d7
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions controllers/machineset_controller.go
Expand Up @@ -272,23 +272,9 @@ func (r *MachineSetReconciler) syncReplicas(ctx context.Context, ms *clusterv1.M
err error
)

infraConfig, err = external.CloneTemplate(ctx, r.Client, &machine.Spec.InfrastructureRef, machine.Namespace)
if err != nil {
return errors.Wrapf(err, "failed to clone infrastructure configuration for MachineSet %q in namespace %q", ms.Name, ms.Namespace)
}
machine.Spec.InfrastructureRef = corev1.ObjectReference{
APIVersion: infraConfig.GetAPIVersion(),
Kind: infraConfig.GetKind(),
Namespace: infraConfig.GetNamespace(),
Name: infraConfig.GetName(),
}

if machine.Spec.Bootstrap.ConfigRef != nil {
bootstrapConfig, err = external.CloneTemplate(ctx, r.Client, machine.Spec.Bootstrap.ConfigRef, machine.Namespace)
if err != nil {
if err := r.Client.Delete(context.TODO(), infraConfig); !apierrors.IsNotFound(err) {
klog.Errorf("Failed to cleanup infrastructure configuration object after bootstrap clone error: %v", err)
}
return errors.Wrapf(err, "failed to clone bootstrap configuration for MachineSet %q in namespace %q", ms.Name, ms.Namespace)
}
machine.Spec.Bootstrap.ConfigRef = &corev1.ObjectReference{
Expand All @@ -299,6 +285,17 @@ func (r *MachineSetReconciler) syncReplicas(ctx context.Context, ms *clusterv1.M
}
}

infraConfig, err = external.CloneTemplate(ctx, r.Client, &machine.Spec.InfrastructureRef, machine.Namespace)
if err != nil {
return errors.Wrapf(err, "failed to clone infrastructure configuration for MachineSet %q in namespace %q", ms.Name, ms.Namespace)
}
machine.Spec.InfrastructureRef = corev1.ObjectReference{
APIVersion: infraConfig.GetAPIVersion(),
Kind: infraConfig.GetKind(),
Namespace: infraConfig.GetNamespace(),
Name: infraConfig.GetName(),
}

if err := r.Client.Create(context.TODO(), machine); err != nil {
logger.Error(err, "Unable to create Machine", "machine", machine.Name)
r.recorder.Eventf(ms, corev1.EventTypeWarning, "FailedCreate", "Failed to create machine %q: %v", machine.Name, err)
Expand Down

0 comments on commit 84f06d7

Please sign in to comment.