diff --git a/pkg/cluster/internal/create/actions/createworker/createworker.go b/pkg/cluster/internal/create/actions/createworker/createworker.go index 5c9df7b9fa..b39d5f3367 100644 --- a/pkg/cluster/internal/create/actions/createworker/createworker.go +++ b/pkg/cluster/internal/create/actions/createworker/createworker.go @@ -253,19 +253,26 @@ func (a *action) Execute(ctx *actions.ActionContext) error { return errors.Wrap(err, "failed to create the worker Cluster") } - // Get the workload cluster kubeconfig + // Wait for the control plane initialization raw = bytes.Buffer{} - cmd = node.Command("sh", "-c", "clusterctl -n "+capiClustersNamespace+" get kubeconfig "+descriptorFile.ClusterID+" | tee "+kubeconfigPath) + cmd = node.Command("kubectl", "-n", capiClustersNamespace, "wait", "--for=condition=ControlPlaneInitialized", "--timeout", "5m", "cluster", descriptorFile.ClusterID) if err := cmd.SetStdout(&raw).Run(); err != nil { - return errors.Wrap(err, "failed to get workload cluster kubeconfig") + return errors.Wrap(err, "failed to create the worker Cluster") } - kubeconfig := raw.String() ctx.Status.End(true) // End Creating the workload cluster ctx.Status.Start("Saving the workload cluster kubeconfig 📝") defer ctx.Status.End(false) + // Get the workload cluster kubeconfig + raw = bytes.Buffer{} + cmd = node.Command("sh", "-c", "clusterctl -n "+capiClustersNamespace+" get kubeconfig "+descriptorFile.ClusterID+" | tee "+kubeconfigPath) + if err := cmd.SetStdout(&raw).SetStderr(&raw).Run(); err != nil || strings.Contains(raw.String(), "Error:") || raw.String() == "" { + return errors.Wrap(err, "failed to get workload cluster kubeconfig") + } + kubeconfig := raw.String() + workKubeconfigBasePath := strings.Split(workKubeconfigPath, "/")[0] _, err = os.Stat(workKubeconfigBasePath) if err != nil {