Git Product home page Git Product logo

lockheed's Introduction

Lockheed

Go locking library for kubernetes based locking

Overview

In one of the projects required locking of some actions in scope of a namespace, hence this library sprung to life.

Features

  • Keeps the state of the lock within a per lock kubernetes ConfigMap object
  • Implements interface based abstraction of Locker to enable future implementation of other locking backends then kubernetes
  • Acquiring and releasing of a mutex lock
  • Maintaining a lock with moving time window based on duration and refresh interval
  • Dynamic tagging locks
  • Listing all locks with filtering based on Conditions
  • Forcefull takeover of locks based on Conditions
  • (planned) Shared locks where some lock instances can exist in parallel while others might wait for the lock to be freed or lockable in mutex mode

Configuration directives

Any lock object is instantiated in an inactive state. Untill activated by calling lock.Acquire() it can be further configured with following methods, all of which return back (the same) lock object pointer, to allow chaining their invocation like lock.DirectiveA().DirectiveB().

  • .WithDuration(time.Duration) A duration for whitch to establish or renew the lock every time, 0 = infinite
  • .WithRenewInterval(time.Duration) How often to renew the lock, no renewal if not specified
  • .WithContext(context.Context) Use this custom context within the lock
  • .WithTags([]string) Add these tags to the lock state if not already there
  • .WithResetTags() Remove any tags that were not specified withing .WithTags() directive
  • .WithForce(Condition) Allow forcefull takeover of a lock if it matches specified condition

Examples

lock := lockheed.NewLock("lockname", lockheed.NewKubeLocker()).
    WithDuration(30 * time.Second).
    WithRenewInterval(9 * time.Second)
lock.Acquire()
defer lock.Release()
lock := lockheed.NewLock("lockname", lockheed.NewKubeLocker()).
    WithDuration(30 * time.Second).
    WithRenewInterval(9 * time.Second).
    WithTags([]string{"tag1", "tag2"})
lock.Acquire()
defer lock.Release()
lock := lockheed.NewLock("lockname", lockheed.NewKubeLocker()).
    WithDuration(30 * time.Second).
    WithRenewInterval(9 * time.Second).
    WithResetTags().
    WithForce(lockheed.Condition{
        Operation: lockheed.OperationContains,
        Field:     lockheed.FieldTags,
        Value:     "tag2",
    })
lock.Acquire()
defer lock.Release()

Kubelocker

Kubelocker stores lock state in ConfigMap objects of it's designated namespace. ConfigMaps are named as lockheed-<lockname>. The program implementing this library needs respective RBAC rules allowing ConfigMap manipulation.

lockheed's People

Contributors

goblain avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.