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

Remove useless field LeaderElect #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
41 changes: 17 additions & 24 deletions pkg/kine/endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,20 @@ type Config struct {
}

type ETCDConfig struct {
Endpoints []string
TLSConfig tls.Config
LeaderElect bool
Endpoints []string
TLSConfig tls.Config
}

func Listen(ctx context.Context, config Config) (ETCDConfig, error) {
driver, dsn := ParseStorageEndpoint(config.Endpoint)
if driver == ETCDBackend {
return ETCDConfig{
Endpoints: strings.Split(config.Endpoint, ","),
TLSConfig: config.Config,
LeaderElect: true,
Endpoints: strings.Split(config.Endpoint, ","),
TLSConfig: config.Config,
}, nil
}

leaderelect, backend, err := getKineStorageBackend(ctx, driver, dsn, config)
backend, err := getKineStorageBackend(ctx, driver, dsn, config)
if err != nil {
return ETCDConfig{}, errors.Wrap(err, "building kine")
}
Expand Down Expand Up @@ -82,9 +80,8 @@ func Listen(ctx context.Context, config Config) (ETCDConfig, error) {
context.AfterFunc(ctx, grpcServer.Stop)

return ETCDConfig{
LeaderElect: leaderelect,
Endpoints: []string{listen},
TLSConfig: tls.Config{},
Endpoints: []string{listen},
TLSConfig: tls.Config{},
}, nil
}

Expand All @@ -110,13 +107,12 @@ func ListenAndReturnBackend(ctx context.Context, config Config) (ETCDConfig, ser
driver, dsn := ParseStorageEndpoint(config.Endpoint)
if driver == ETCDBackend {
return ETCDConfig{
Endpoints: strings.Split(config.Endpoint, ","),
TLSConfig: config.Config,
LeaderElect: true,
Endpoints: strings.Split(config.Endpoint, ","),
TLSConfig: config.Config,
}, nil, nil
}

leaderelect, backend, err := getKineStorageBackend(ctx, driver, dsn, config)
backend, err := getKineStorageBackend(ctx, driver, dsn, config)
if err != nil {
return ETCDConfig{}, nil, errors.Wrap(err, "building kine")
}
Expand Down Expand Up @@ -148,9 +144,8 @@ func ListenAndReturnBackend(ctx context.Context, config Config) (ETCDConfig, ser
context.AfterFunc(ctx, grpcServer.Stop)

return ETCDConfig{
LeaderElect: leaderelect,
Endpoints: []string{listen},
TLSConfig: tls.Config{},
Endpoints: []string{listen},
TLSConfig: tls.Config{},
}, backend, nil
}

Expand All @@ -172,23 +167,21 @@ func grpcServer(config Config) *grpc.Server {
return grpc.NewServer(gopts...)
}

func getKineStorageBackend(ctx context.Context, driver, dsn string, cfg Config) (bool, server.Backend, error) {
func getKineStorageBackend(ctx context.Context, driver, dsn string, cfg Config) (server.Backend, error) {
var (
backend server.Backend
leaderElect = true
err error
backend server.Backend
err error
)
switch driver {
case SQLiteBackend:
leaderElect = false
backend, err = sqlite.New(ctx, dsn, &cfg.ConnectionPoolConfig)
case DQLiteBackend:
backend, err = dqlite.New(ctx, dsn, cfg.Config, &cfg.ConnectionPoolConfig)
default:
return false, nil, fmt.Errorf("storage backend is not defined")
return nil, fmt.Errorf("storage backend is not defined")
}

return leaderElect, backend, err
return backend, err
}

func ParseStorageEndpoint(storageEndpoint string) (string, string) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/migrator/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ func BackupEtcd(ctx context.Context, endpoint, dir string) error {
// RestoreToDqlite restores database contents from backup directory to a k8s-dqlite database.
func RestoreToDqlite(ctx context.Context, endpoint, dir string) error {
client, err := client.New(kine_endpoint.ETCDConfig{
Endpoints: []string{endpoint},
LeaderElect: false,
Endpoints: []string{endpoint},
})
if err != nil {
return fmt.Errorf("failed to create client: %w", err)
Expand Down
Loading