Documentation ¶
Index ¶
- func GetLabelKeys() []string
- type Leaser
- func (l *Leaser) GetOwnerAndExpirationTime(ctx context.Context, u *unstructured.Unstructured) (string, time.Time, error)
- func (l *Leaser) Obtain(ctx context.Context, u *unstructured.Unstructured, ownerId string, ...) error
- func (l *Leaser) Release(ctx context.Context, u *unstructured.Unstructured, ownerId string) error
- func (l *Leaser) SoftObtain(resource *k8s.Resource, liveLabels map[string]string, ownerId string, ...) error
- func (l *Leaser) UnstructuredSupportsLeasing(u *unstructured.Unstructured) (ok bool, err error)
- type ResourceLeaser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLabelKeys ¶
func GetLabelKeys() []string
Get the keys that are set on a resource to obtain a lease
Types ¶
type Leaser ¶
type Leaser struct {
// contains filtered or unexported fields
}
Leaser locks for a period of time by GCP resources by applying 'owner' and 'expiration' labels to the resource. After they are applied, Leaser will only allow a caller to Obtain the resource if one of the following is true: 1. The owner id is the same as what is saved in the labels 2. The expiration time is before the current time
No protections are made for race conditions: the last writer will win.
func NewLeaser ¶
func NewLeaser(tfProvider *tfschema.Provider, smLoader *servicemappingloader.ServiceMappingLoader, kubeClient client.Client) *Leaser
func (*Leaser) GetOwnerAndExpirationTime ¶
func (l *Leaser) GetOwnerAndExpirationTime(ctx context.Context, u *unstructured.Unstructured) (string, time.Time, error)
func (*Leaser) Obtain ¶
func (l *Leaser) Obtain(ctx context.Context, u *unstructured.Unstructured, ownerId string, duration time.Duration, renewalMin time.Duration) error
Obtains a lease, for 'ownerId', on the given unstructured for 'duration' time. If the owner already has a lease on the unstructured the lease is renewed to 'duration' time if the 'renewalMin' is greater than the remaining time on the lease.
To 'always' renew the lease, pass in a 'renewalMin' that is equal to the duration.
func (*Leaser) Release ¶
func (l *Leaser) Release(ctx context.Context, u *unstructured.Unstructured, ownerId string) error
func (*Leaser) SoftObtain ¶
func (l *Leaser) SoftObtain(resource *k8s.Resource, liveLabels map[string]string, ownerId string, duration time.Duration, renewalMin time.Duration) error
Soft obtain obtains a lease for 'ownerId' on the given resource for 'duration' time. See the comment on Obtain(...) for more.
It does not write the results to GCP so the caller must apply the changes to GCP if persistence is desired
func (*Leaser) UnstructuredSupportsLeasing ¶
func (l *Leaser) UnstructuredSupportsLeasing(u *unstructured.Unstructured) (ok bool, err error)
type ResourceLeaser ¶
type ResourceLeaser struct {
// contains filtered or unexported fields
}
func NewResourceLeaser ¶
func NewResourceLeaser(tfProvider *schema.Provider, smLoader *servicemappingloader.ServiceMappingLoader, kubeClient client.Client) *ResourceLeaser
func (*ResourceLeaser) IsLeasable ¶
func (l *ResourceLeaser) IsLeasable(resource *krmtotf.Resource) (ok bool, err error)
func (*ResourceLeaser) Release ¶
func (l *ResourceLeaser) Release(ctx context.Context, u *unstructured.Unstructured) error
func (*ResourceLeaser) SoftObtain ¶
func (l *ResourceLeaser) SoftObtain(ctx context.Context, resource *k8s.Resource, liveLabels map[string]string) error
Soft obtain obtains a lease for the resource given the live labels. The method should be called on resources that are leasable.
It does not write the results to GCP so the caller must apply the changes to GCP if persistence is desired