lock

package
v0.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2021 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package lock implements a ConfigMap lock similar to the one found in github.com/operator-framework/operator-sdk/pkg/leader.

The main difference is that it provides a Release mechanism as opposed to the Leader-for-life strategy the operator-sdk uses. This is useful for getting temporary locks on K8s resources. Also, since the user of the lock will not always dissapear, an expiration key is placed in the configMap to signal to another process when it's okay to release a stale lock.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lock

type Lock struct {
	// contains filtered or unexported fields
}

Lock implements a simple locking mechanism backed by a configmap. When the lock is acquired, a configmap is made with an owner reference to the running pod. Another lock attempt will block until it can create the configmap with the same name, or if the lock expires.

func New

func New(c client.Client, name string, timeout time.Duration) *Lock

New returns a new lock. If timeout is a value less than zero, then no expiration is placed on the lock. A safeguard for deadlocks is still in place due to the OwnerReference to the pod that holds the lock on the configmap.

func (*Lock) Acquire

func (l *Lock) Acquire() error

Acquire will attempt to acquire the lock, retrying until the lock is either acquired or the timeout is reached.

func (*Lock) GetCMData

func (l *Lock) GetCMData() map[string]string

GetCMData returns the data to apply to the configmap for this lock.

func (*Lock) GetName

func (l *Lock) GetName() string

GetName returns the name of this lock.

func (*Lock) GetTimeout

func (l *Lock) GetTimeout() time.Duration

GetTimeout returns the timeout for this lock.

func (*Lock) Release

func (l *Lock) Release() error

Release will delete the configmap, releasing the lock. If the found lock does not belong to the running pod, an error is returned.

func (*Lock) WithLabels

func (l *Lock) WithLabels(labels map[string]string) *Lock

WithLabels configures labels to add to the resources associated with this lock.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL