Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions internal/cluster/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ func (c *Cluster) Init(ctx context.Context, opts InitOptions) error {
return fmt.Errorf("failed to patch CoreDNS: %w", err)
}

c.logger.Info("")
c.logger.Info("Waiting for CoreDNS to be ready...")
if err := kubeClient.WaitForDeploymentReady(ctx, "kube-system", "coredns", 3*time.Minute); err != nil {
return fmt.Errorf("CoreDNS not ready: %w", err)
}
c.logger.Info("✓ CoreDNS is ready")

c.logger.Info("")
c.logger.Infof("✅ Cluster initialized on %s with Calico CNI", nodeName)

Expand Down
25 changes: 25 additions & 0 deletions internal/kube/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,31 @@ func (c *Client) EnableCoreDNSFallthrough(ctx context.Context) error {
return nil
}

// WaitForDeploymentReady polls until the named deployment has at least one
// ready replica, or the timeout expires.
func (c *Client) WaitForDeploymentReady(ctx context.Context, namespace, name string, timeout time.Duration) error {
deadline := time.After(timeout)
ticker := time.NewTicker(2 * time.Second)
defer ticker.Stop()

for {
select {
case <-ctx.Done():
return ctx.Err()
case <-deadline:
return fmt.Errorf("timed out waiting for deployment %s/%s to be ready", namespace, name)
case <-ticker.C:
deploy, err := c.clientset.AppsV1().Deployments(namespace).Get(ctx, name, metav1.GetOptions{})
if err != nil {
continue
}
if deploy.Status.ReadyReplicas >= 1 {
return nil
}
}
}
}

// LabelNode adds the given labels to a node, overwriting any that already exist.
func (c *Client) LabelNode(ctx context.Context, nodeName string, labels map[string]string) error {
patch := map[string]interface{}{
Expand Down
Loading