Skip to content

Commit

Permalink
Add new control plane wait condition
Browse files Browse the repository at this point in the history
  • Loading branch information
kahun committed Mar 30, 2023
1 parent 626d833 commit 653cbaa
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions pkg/cluster/internal/create/actions/createworker/createworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
_ "embed"
"os"
"strings"
"time"

"sigs.k8s.io/kind/pkg/cluster/internal/create/actions"
"sigs.k8s.io/kind/pkg/cluster/internal/create/actions/cluster"
Expand Down Expand Up @@ -254,25 +253,23 @@ func (a *action) Execute(ctx *actions.ActionContext) error {
return errors.Wrap(err, "failed to create the worker Cluster")
}

// Wait for the control plane initialization
raw = bytes.Buffer{}
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 create the worker Cluster")
}

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)
for i := 0; i < 3; i++ {
raw = bytes.Buffer{}
if err := cmd.SetStdout(&raw).SetStderr(&raw).Run(); err != nil {
return errors.Wrap(err, "failed to get workload cluster kubeconfig")
}
if !strings.Contains(raw.String(), "Error:") && raw.String() != "" {
continue
}
if i == 2 {
return errors.New(raw.String() + " failed to get workload cluster kubeconfig")
}
time.Sleep(3 * time.Second)
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()

Expand Down

0 comments on commit 653cbaa

Please sign in to comment.