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

NATS: Fix illegal resource version from storage: 0 (#274) #275

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
13 changes: 12 additions & 1 deletion pkg/drivers/nats/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nats
import (
"context"
"encoding/json"
"errors"
"time"

"github.com/k3s-io/kine/pkg/server"
Expand Down Expand Up @@ -116,13 +117,23 @@ func (b *Backend) get(ctx context.Context, key string, revision int64, allowDele
// Start starts the backend.
// See https://github.com/kubernetes/kubernetes/blob/442a69c3bdf6fe8e525b05887e57d89db1e2f3a5/staging/src/k8s.io/apiserver/pkg/storage/storagebackend/factory/etcd3.go#L97
func (b *Backend) Start(ctx context.Context) error {
if _, err := b.Create(ctx, "/registry/health", []byte(`{"health":"true"}`), 0); err != nil {
if err := b.StartWithRetry(ctx, 3); err != nil {
if err != server.ErrKeyExists {
b.l.Errorf("Failed to create health check key: %v", err)
}
}
return nil
}
func (b *Backend) StartWithRetry(ctx context.Context, retriesLeft int) error {
if _, err := b.Create(ctx, "/registry/health", []byte(`{"health":"true"}`), 0); err != nil {
if errors.Is(err, context.DeadlineExceeded) && retriesLeft > 0 {
b.l.Warnf("Failed to create health check key: %v - Retrying...", err)
return b.StartWithRetry(ctx, retriesLeft-1)
}
return err
}
return nil
}

// DbSize get the kineBucket size from JetStream.
func (b *Backend) DbSize(ctx context.Context) (int64, error) {
Expand Down