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

LeaderElection NewFromKubeconfig support "Functional Options" pattern #1403

Open
ivankatliarchuk opened this issue Jan 26, 2025 · 0 comments

Comments

@ivankatliarchuk
Copy link

ivankatliarchuk commented Jan 26, 2025

Currently if we would like to have an automated cleanup of leases, the only way is to

The code is here https://github.com/kubernetes/client-go/blob/ce24f3c462e8e98af9d79453327a77ffdc4a8b0e/tools/leaderelection/resourcelock/interface.go#L104C2-L111C3

The proposed functionality is to add something like below, this should not break current clients, or add one more

pseudo code

func NewFromKubeconfig(...., opts ...LeaseLockOptions) {
}
// or
func NewFromKubeconfigOpts(...., opts ...LeaseLockOptions) {
}

type LeaseLockOption func(d *LeaseLock) error

func ObjectMeta(m ObjectMeta) LeaseLockOption {
	return func(l *LeaseLock) error {
		l.LeaseMeta = m
		return nil
	}
} 

func Labels(m Labels) LeaseLockOption {
	return func(l *LeaseLock) error {
		l.Labels = m
		return nil
	}
}

// If ALL objects in the list have been deleted, this object will be garbage collected
func OwnerReferences(m OwnerReferences) LeaseLockOption {
	return func(l *LeaseLock) error {
		l.OwnerReferences = m
		return nil
	}
}
..

I'm happy to submit a pull request if it make sense.
A bit more explanation https://golang.cafe/blog/golang-functional-options-pattern.html

@ivankatliarchuk ivankatliarchuk changed the title LeaderElection NewFromKubeconfig support LeaderElection NewFromKubeconfig support options Jan 26, 2025
@ivankatliarchuk ivankatliarchuk changed the title LeaderElection NewFromKubeconfig support options LeaderElection NewFromKubeconfig support "Functional Options" pattern Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant