Documentation ¶
Index ¶
Constants ¶
View Source
const ( // DefaultTTL is default time to live for the lock. DefaultTTL = 5 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func IsAlreadyExists ¶
IsAlreadyExists asserts alreadyExistsError.
func IsInvalidConfig ¶
IsInvalidConfig asserts invalidConfigError.
func IsOwnerMismatch ¶
IsOwnerMismatch asserts ownerMismatchError.
Types ¶
type AcquireOptions ¶
type Config ¶
type Config struct { DynClient dynamic.Interface // GVR defines a resource that the lock will be // created on with use of the dynamic Kubernetes client. This object // will be passed directly in the dynamic client API calls. // // E.g. for Namespace resource it can be instantiated like: // // schema.GroupVersionResource{ // Group: "", // Version: "v1", // Resource: "namespaces", // } // // E.g. for CR defined by a CRD defined in // https://github.com/giantswarm/apiextensions/ repository it can be // instantiated like: // // schema.GroupVersionResource{ // Group: v1alpha1.NewAWSConfigCRD().Spec.Group, // Version: v1alpha1.NewAWSConfigCRD().Spec.Version, // Resource: v1alpha1.NewAWSConfigCRD().Spec.Names.Plural, // } GVR schema.GroupVersionResource }
type Interface ¶
type Interface interface { // Lock creates a lock with the given name. The name will be used to // create annotation prefixed with "kubelock.giantswarm.io/" on the // Kubernetes resource. Value of this annotation stores the lock data. // // NOTE: The name parameter is not validated but it must (together with // the annotation prefix mentioned) be a valid annotation key. Lock(name string) NamespaceableLock }
Interface is the interface of a distributed Kubernetes lock. The default implementation is KubeLock.
The typical usage for a namespace resource may look like:
kubeLock.Lock("my-lock-name").Namespace("my-namespace").Acquire(ctx, "my-configmap", kubelock.AcquireOptions{})
The typical usage for a cluster scope resource may look like:
kubeLock.Lock("my-lock-name").Acquire(ctx, "my-namespace", kubelock.ReleaseOptions{})
type KubeLock ¶
type KubeLock struct {
// contains filtered or unexported fields
}
func (*KubeLock) Lock ¶
func (k *KubeLock) Lock(name string) NamespaceableLock
type Lock ¶
type Lock interface { // Acquire tries to acquire the lock on a Kubernetes resource with the // given name. // // This method returns an error matched by IsAlreadyExists if the lock // already exists on the resource, it is not expired and it has the same // owner (set in options). // // This method returns an error matched by IsOwnerMismatch if the lock // already exists on the resource and it is not expired but was acquired // by a different owner (set in options). Acquire(ctx context.Context, name string, options AcquireOptions) error // Release tries to release the lock on a Kubernetes resource with the // given name. // // This method returns an error matched by IsNotFound if the lock // does not exist on the resource or it is expired. // // This method returns an error matched by IsOwnerMismatch if the lock // already exists and it is not expired but it was acquired by // a different owner (set in options). Release(ctx context.Context, name string, options ReleaseOptions) error }
type NamespaceableLock ¶
type ReleaseOptions ¶
type ReleaseOptions struct { // Owner is an arbitrary string representing owner of the lock. Owner string }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.