dragonflydb / dragonflydb/dragonfly-operator

Feature Request: Add LeaderElectionReleaseOnCancel configuration option

Open Beginner friendly
#577 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
357
Forks
111
PR merge metrics
No merged PRs in 30d

Description

## Problem

Currently, when a controller pod is terminated, it takes ~40-60 seconds for the new pod to detect the leader loss and take over leadership (due to Kubernetes Lease TTL). This is because `LeaderElectionReleaseOnCancel` is hardcoded to `false` in `cmd/main.go:117`.

For distroless container images (which don't have shell, curl, or other tools), there's no way to implement a preStop hook that gracefully releases the lease on shutdown. This leaves only two options:

1. **Accept slow failover** (~40 seconds)
2. **Fork the repository** and maintain a custom build

## Solution

Add a configuration flag `--leader-elect-release-on-cancel` that allows graceful leader release on shutdown. This is a standard pattern in `controller-runtime` and is already implemented, just needs to be exposed.

## Benefits

- **Faster failover**: Leadership transferred in 1-2 seconds instead of 40-60
- **Works with distroless images**: No need for preStop hooks or shell
- **Backward compatible**: Default remains `false`
- **Zero performance impact**: Only affects shutdown behavior

Contributor guide

Open the contributing guide

Research direction

Start in cmd/main.go:117, where LeaderElectionReleaseOnCancel is currently hardcoded, and inspect nearby leader-election configuration and flag wiring. Run the existing Go tests before and after the change. Done means a --leader-elect-release-on-cancel option is exposed, defaults to false for backward compatibility, and enables release-on-cancel when selected.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
devops
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.