Skip to content

Commit

Permalink
Remove useless field LeaderElect
Browse files Browse the repository at this point in the history
  • Loading branch information
marco6 committed Jan 9, 2025
1 parent 0d2b3cc commit abe052b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
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

0 comments on commit abe052b

Please sign in to comment.