mirror of
https://github.com/paralus/paralus.git
synced 2026-05-07 08:56:42 +00:00
* restructure rcloud-base as a single base controller * updated master.rest * moved sentry from internal to pkg as it is used by relay * removing unused rpc and it's dependencies * Fix usermgmt tests * Don't redefine variables in rest file Co-authored-by: Abin Simon <abin.simon@rafay.co>
51 lines
990 B
Go
51 lines
990 B
Go
package leaderelection
|
|
|
|
import (
|
|
clientset "k8s.io/client-go/kubernetes"
|
|
rl "k8s.io/client-go/tools/leaderelection/resourcelock"
|
|
)
|
|
|
|
// NewLock returns new resource lock
|
|
func NewLock(lockName, lockNamespace, id string) (rl.Interface, error) {
|
|
|
|
config, err := GetConfig()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
client, err := clientset.NewForConfig(config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return rl.New(rl.LeasesResourceLock,
|
|
lockNamespace,
|
|
lockName,
|
|
client.CoreV1(),
|
|
client.CoordinationV1(),
|
|
rl.ResourceLockConfig{Identity: id},
|
|
)
|
|
}
|
|
|
|
// NewConfigMapLock returns new lock backed by ConfigMap
|
|
func NewConfigMapLock(lockName, lockNamespace, id string) (rl.Interface, error) {
|
|
config, err := GetConfig()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
client, err := clientset.NewForConfig(config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return rl.New(rl.ConfigMapsResourceLock,
|
|
lockNamespace,
|
|
lockName,
|
|
client.CoreV1(),
|
|
nil,
|
|
rl.ResourceLockConfig{Identity: id},
|
|
)
|
|
|
|
}
|