Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 cleanup infrastructure configuration object after bootstrap clone error #1400

Merged
merged 2 commits into from Oct 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions controllers/machineset_controller.go
Expand Up @@ -272,17 +272,6 @@ 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 {
Expand All @@ -296,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