diff --git a/internal/controllers/machinedeployment/machinedeployment_controller.go b/internal/controllers/machinedeployment/machinedeployment_controller.go index 41184e4b69aa..8b724b923f20 100644 --- a/internal/controllers/machinedeployment/machinedeployment_controller.go +++ b/internal/controllers/machinedeployment/machinedeployment_controller.go @@ -513,6 +513,12 @@ func reconcileExternalTemplateReference(ctx context.Context, c client.Client, cl return errors.New(err.Error()) } + // Ensure the ref namespace is populated for objects not yet defaulted by webhook + if ref.Namespace == "" { + ref = ref.DeepCopy() + ref.Namespace = cluster.Namespace + } + obj, err := external.Get(ctx, c, ref) if err != nil { return err diff --git a/internal/controllers/machineset/machineset_controller.go b/internal/controllers/machineset/machineset_controller.go index 960be34095e6..d4807fca138b 100644 --- a/internal/controllers/machineset/machineset_controller.go +++ b/internal/controllers/machineset/machineset_controller.go @@ -1516,6 +1516,12 @@ func (r *Reconciler) reconcileExternalTemplateReference(ctx context.Context, clu return false, err } + // Ensure the ref namespace is populated for objects not yet defaulted by webhook + if ref.Namespace == "" { + ref = ref.DeepCopy() + ref.Namespace = cluster.Namespace + } + obj, err := external.Get(ctx, r.Client, ref) if err != nil { if apierrors.IsNotFound(err) {