Heat the oven to 200C/180C fan. Heat the oil in a frying pan and cook the onions for 8-10 minutes until soft and golden.
Crumble in the stock cube, add 150ml of water and the diced potato and simmer for 3 minutes.
Gently fold in the corned beef and the ketchup if using. The corned beef will break down into a thick, mince-like filling. Season with pepper, taste, and only add salt if it needs it because corned beef is already salty. Set the filling aside to cool while you roll the pastry.
Roll out slightly more than half the pastry on a floured surface and use it to line a 20cm pie dish. Spoon in the cooled filling.
Roll out the rest for the lid, lay it over the top and crimp the edges together with your fingers or a fork. Brush the top with milk and cut two slashes in the middle to let the steam out.
Bake for 35-40 minutes until deep golden brown. Let the pie rest for 10 minutes before slicing so the filling sets up.