Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for kine to be ready during startup #5092

Closed
wants to merge 1 commit into from
Closed
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
45 changes: 34 additions & 11 deletions pkg/component/controller/kine.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@ import (
"path/filepath"
"time"

"github.com/k0sproject/k0s/internal/pkg/dir"
"github.com/k0sproject/k0s/internal/pkg/users"
"github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
"github.com/k0sproject/k0s/pkg/assets"
"github.com/k0sproject/k0s/pkg/component/manager"
"github.com/k0sproject/k0s/pkg/config"
"github.com/k0sproject/k0s/pkg/config/kine"
"github.com/k0sproject/k0s/pkg/constant"
"github.com/k0sproject/k0s/pkg/etcd"
clientv3 "go.etcd.io/etcd/client/v3"
"github.com/k0sproject/k0s/pkg/supervisor"

"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/k0sproject/k0s/internal/pkg/dir"
"github.com/k0sproject/k0s/internal/pkg/users"
"github.com/k0sproject/k0s/pkg/assets"
"github.com/k0sproject/k0s/pkg/constant"
"github.com/k0sproject/k0s/pkg/supervisor"
"github.com/sirupsen/logrus"
clientv3 "go.etcd.io/etcd/client/v3"
)

// Kine implement the component interface to run kine
Expand Down Expand Up @@ -131,7 +132,26 @@ func (k *Kine) Start(ctx context.Context) error {
GID: k.gid,
}

return k.supervisor.Supervise()
if err := k.supervisor.Supervise(); err != nil {
return err
}

var err error
waitErr := wait.PollUntilContextTimeout(ctx, 350*time.Millisecond, 2*time.Minute, true, func(ctx context.Context) (bool, error) {
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
defer cancel()
err = k.ready(ctx)
return err == nil, nil
})

if waitErr != nil {
if err != nil {
return fmt.Errorf("%w (%w)", waitErr, err)
}
return waitErr
}

return nil
}

// Stop stops kine
Expand All @@ -144,15 +164,18 @@ const hcKey = "/k0s-health-check"
const hcValue = "value"

func (k *Kine) Ready() error {
ctx, cancel := context.WithTimeout(context.TODO(), 1*time.Second)
defer cancel()
return k.ready(context.TODO())
}

func (k *Kine) ready(ctx context.Context) error {
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
defer cancel()
ok, err := k.bypassClient.Write(ctx, hcKey, hcValue, 64*time.Second)
if err != nil {
return fmt.Errorf("kine-etcd-health: %w", err)
}
if !ok {
logrus.Warningf("kine-etcd-health: health-check value was not written")
return errors.New("kine-etcd-health: health-check value was not written")
}

v, err := k.bypassClient.Read(ctx, hcKey)
Expand Down
Loading