Skip to content

Commit

Permalink
Wait until kubernetes endpoint becomes available (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
bschimke95 authored May 4, 2024
1 parent 397842b commit db5015e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/k8s/pkg/client/kubernetes/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// WaitApiServerReady waits until the kube-apiserver becomes available.
func (c *Client) WaitApiServerReady(ctx context.Context) error {
// WaitKubernetesEndpointAvailable waits until the kubernetes endpoint becomes available.
func (c *Client) WaitKubernetesEndpointAvailable(ctx context.Context) error {
return control.WaitUntilReady(ctx, func() (bool, error) {
// TODO: use the /readyz endpoint instead
// We want to retry if an error occurs (=API server not ready)
// returning the error would abort, thus checking for nil
_, err := c.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
return err == nil, nil
endpoint, err := c.CoreV1().Endpoints("default").Get(ctx, "kubernetes", metav1.GetOptions{})
return err == nil && endpoint != nil, nil
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/k8s/pkg/k8sd/api/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func (e *Endpoints) postWorkerInfo(s *state.State, r *http.Request) response.Res
if err != nil {
return response.InternalError(fmt.Errorf("failed to create kubernetes client: %w", err))
}
if err := client.WaitApiServerReady(s.Context); err != nil {
return response.InternalError(fmt.Errorf("kube-apiserver did not become ready in time: %w", err))
if err := client.WaitKubernetesEndpointAvailable(s.Context); err != nil {
return response.InternalError(fmt.Errorf("kubernetes endpoints not ready yet: %w", err))
}
servers, err := client.GetKubeAPIServerEndpoints(s.Context)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions src/k8s/pkg/k8sd/app/cluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func waitApiServerReady(ctx context.Context, snap snap.Snap) error {
return fmt.Errorf("failed to create Kubernetes client: %w", err)
}

if err := client.WaitApiServerReady(ctx); err != nil {
return fmt.Errorf("kube-apiserver did not become ready in time: %w", err)
if err := client.WaitKubernetesEndpointAvailable(ctx); err != nil {
return fmt.Errorf("kubernetes endpoints not ready yet: %w", err)
}

return nil
Expand Down

0 comments on commit db5015e

Please sign in to comment.