Skip to content

Commit

Permalink
added logic to check if namespace exist before creating template reso…
Browse files Browse the repository at this point in the history
…urce

Signed-off-by: dislbenn <dbennett@redhat.com>
  • Loading branch information
dislbenn committed Jan 9, 2025
1 parent 0bf4542 commit f2ee785
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions controllers/backplaneconfig_controller.go
Original file line number Diff line number Diff line change
@@ -1356,6 +1356,21 @@ func (r *MultiClusterEngineReconciler) applyTemplate(ctx context.Context,
return result, err
}
} else {
// Check if the namespace exists if the template specifies a namespace.
if template.GetNamespace() != backplaneConfig.Spec.TargetNamespace && template.GetNamespace() != "" {
ns := &corev1.Namespace{}
if err := r.Client.Get(ctx, types.NamespacedName{Name: template.GetNamespace()}, ns); err != nil {
if apierrors.IsNotFound(err) {
r.Log.Info("Namespace does not exist; skipping resource creation",
"Name", template.GetName(), "Kind", template.GetKind(), "Namespace", template.GetNamespace())

// Skip further processing if the namespace does not exist.
return ctrl.Result{}, nil
}
return ctrl.Result{}, err
}
}

// Apply the object data.
force := true
err := r.Client.Patch(ctx, template, client.Apply,

0 comments on commit f2ee785

Please sign in to comment.