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

Emulated etcd version #211

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 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
3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
metricsAddress string
otel bool
otelAddress string
emulatedEtcdVersion string

connectionPoolConfig generic.ConnectionPoolConfig

Expand Down Expand Up @@ -101,6 +102,7 @@ var (
rootCmdOpts.diskMode,
rootCmdOpts.clientSessionCacheSize,
rootCmdOpts.minTLSVersion,
rootCmdOpts.emulatedEtcdVersion,
rootCmdOpts.watchAvailableStorageInterval,
rootCmdOpts.watchAvailableStorageMinBytes,
rootCmdOpts.lowAvailableStorageAction,
Expand Down Expand Up @@ -173,6 +175,7 @@ func init() {
rootCmd.Flags().BoolVar(&rootCmdOpts.otel, "otel", false, "enable traces endpoint")
rootCmd.Flags().StringVar(&rootCmdOpts.otelAddress, "otel-listen", "127.0.0.1:4317", "listen address for OpenTelemetry endpoint")
rootCmd.Flags().StringVar(&rootCmdOpts.metricsAddress, "metrics-listen", "127.0.0.1:9042", "listen address for metrics endpoint")
rootCmd.Flags().StringVar(&rootCmdOpts.emulatedEtcdVersion, "emulated-etcd-version", "3.5.12", "The emulated etcd version to return on a call to the status endpoint. Defaults to 3.5.12, in order to indicate no support for watch progress notifications yet.")
louiseschmidtgen marked this conversation as resolved.
Show resolved Hide resolved
rootCmd.Flags().IntVar(&rootCmdOpts.connectionPoolConfig.MaxIdle, "datastore-max-idle-connections", 5, "Maximum number of idle connections retained by datastore. If value = 0, the system default will be used. If value < 0, idle connections will not be reused.")
rootCmd.Flags().IntVar(&rootCmdOpts.connectionPoolConfig.MaxOpen, "datastore-max-open-connections", 5, "Maximum number of open connections used by datastore. If value <= 0, then there is no limit")
rootCmd.Flags().DurationVar(&rootCmdOpts.connectionPoolConfig.MaxLifetime, "datastore-connection-max-lifetime", 60*time.Second, "Maximum amount of time a connection may be reused. If value <= 0, then there is no limit.")
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The following configuration options are available listed in a table format:
| `--otel` | Enable traces endpoint | `false` |
| `--otel-listen` | The address to listen for OpenTelemetry endpoint | `127.0.0.1:4317` |
| `--metrics-listen` | The address to listen for metrics endpoint | `127.0.0.1:9042` |
| `--emulated-etcd-version` | The emulated etcd version to return on a call to the status endpoint. Defaults to 3.5.7, in order to indicate no support for watch progress notifications yet. | `3.5.7` |
louiseschmidtgen marked this conversation as resolved.
Show resolved Hide resolved
| `--datastore-max-idle-connections` | Maximum number of idle connections retained by datastore | `5` |
| `--datastore-max-open-connections` | Maximum number of open connections used by datastore | `5` |
| `--datastore-connection-max-lifetime` | Maximum amount of time a connection may be reused | `60s` |
Expand Down
6 changes: 3 additions & 3 deletions pkg/kine/endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type Config struct {
GRPCServer *grpc.Server
Listener string
Endpoint string
EmulatedEtcdVersion string
ConnectionPoolConfig generic.ConnectionPoolConfig

tls.Config
}

Expand Down Expand Up @@ -65,7 +65,7 @@ func Listen(ctx context.Context, config Config) (ETCDConfig, error) {
listen = KineSocket
}

b := server.New(backend)
b := server.New(backend, config.EmulatedEtcdVersion)
grpcServer := grpcServer(config)
b.Register(grpcServer)

Expand Down Expand Up @@ -130,7 +130,7 @@ func ListenAndReturnBackend(ctx context.Context, config Config) (ETCDConfig, ser
listen = KineSocket
}

b := server.New(backend)
b := server.New(backend, config.EmulatedEtcdVersion)
grpcServer := grpcServer(config)
b.Register(grpcServer)

Expand Down
8 changes: 3 additions & 5 deletions pkg/kine/server/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ func (l *LimitedServer) get(ctx context.Context, r *etcdserverpb.RangeRequest) (
attribute.Int64("revision", r.Revision),
)

if len(r.RangeEnd) != 0 {
return nil, fmt.Errorf("unexpected rangeEnd: want empty, got %s", r.RangeEnd)
}
if r.Limit != 0 {
return nil, fmt.Errorf("unexpected limit: want 0, got %d", r.Limit)
if r.Limit != 0 && len(r.RangeEnd) != 0 {
berkayoz marked this conversation as resolved.
Show resolved Hide resolved
err := fmt.Errorf("invalid combination of rangeEnd and limit, limit should be 0 got %d", r.Limit)
Copy link
Contributor

@HomayoonAlimohammadi HomayoonAlimohammadi Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can change this to a named return (probably in another PR). Because IMO it's easy to miss this and just return fmt.Errorf(...) which won't be caught in the defer.

return nil, err
}

rev, kv, err := l.backend.List(ctx, string(r.Key), "", 1, r.Revision)
Expand Down
5 changes: 3 additions & 2 deletions pkg/kine/server/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ func (s *KVServerBridge) Status(ctx context.Context, r *etcdserverpb.StatusReque
return nil, err
}
return &etcdserverpb.StatusResponse{
Header: &etcdserverpb.ResponseHeader{},
DbSize: size,
Header: &etcdserverpb.ResponseHeader{},
DbSize: size,
Version: s.emulatedEtcdVersion,
}, nil
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/kine/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ var (
)

type KVServerBridge struct {
limited *LimitedServer
limited *LimitedServer
emulatedEtcdVersion string
}

func New(backend Backend) *KVServerBridge {
func New(backend Backend, emulatedEtcdVersion string) *KVServerBridge {
return &KVServerBridge{
emulatedEtcdVersion: emulatedEtcdVersion,
limited: &LimitedServer{
backend: backend,
},
Expand Down
5 changes: 4 additions & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func New(
diskMode bool,
clientSessionCacheSize uint,
minTLSVersion string,
emulatedEtcdVersion string,
watchAvailableStorageInterval time.Duration,
watchAvailableStorageMinBytes uint64,
lowAvailableStorageAction string,
Expand Down Expand Up @@ -222,6 +223,8 @@ func New(
}
// set datastore connection pool options
kineConfig.ConnectionPoolConfig = connectionPoolConfig
// set emulated etcd version
kineConfig.EmulatedEtcdVersion = emulatedEtcdVersion
// handle tuning parameters
if exists, err := fileExists(dir, "tuning.yaml"); err != nil {
return nil, fmt.Errorf("failed to check for tuning.yaml: %w", err)
Expand Down Expand Up @@ -340,7 +343,7 @@ func (s *Server) Start(ctx context.Context) error {
if err != nil {
return fmt.Errorf("failed to start kine: %w", err)
}
logrus.WithFields(logrus.Fields{"address": s.kineConfig.Listener, "database": s.kineConfig.Endpoint}).Print("Started kine")
logrus.WithFields(logrus.Fields{"address": s.kineConfig.Listener, "database": s.kineConfig.Endpoint, "emulatedEtcdVersion": s.kineConfig.EmulatedEtcdVersion}).Print("Started kine")

s.backend = backend

Expand Down
Loading