Documentation
¶
Overview ¶
Package k8s provides a lightweight Kubernetes API client for coordination Leases. It uses raw HTTP calls against the mounted service account credentials, avoiding a dependency on client-go.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrConflict = errors.New("conflict: resource version mismatch")
ErrConflict is returned when a Lease update fails due to a resourceVersion mismatch (another writer updated the object first).
Functions ¶
func InCluster ¶
func InCluster() bool
InCluster reports whether the process is running inside a Kubernetes pod by checking for the KUBERNETES_SERVICE_HOST environment variable.
func LeaseNameForDomain ¶
LeaseNameForDomain returns a deterministic, DNS-label-safe Lease name for the given domain. The domain is hashed to avoid dots and length issues.
Types ¶
type Lease ¶
type Lease struct {
APIVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Metadata LeaseMetadata `json:"metadata"`
Spec LeaseSpec `json:"spec"`
}
Lease represents a coordination.k8s.io/v1 Lease object with only the fields needed for distributed locking.
type LeaseClient ¶
type LeaseClient struct {
// contains filtered or unexported fields
}
LeaseClient talks to the Kubernetes coordination API using raw HTTP.
func NewLeaseClient ¶
func NewLeaseClient() (*LeaseClient, error)
NewLeaseClient creates a client that authenticates via the pod's mounted service account. It reads the namespace and CA certificate at construction time (they don't rotate) but reads the bearer token fresh on each request (tokens rotate).
func (*LeaseClient) Create ¶
Create creates a new Lease. Returns the created Lease with server-assigned fields like resourceVersion populated.
func (*LeaseClient) Get ¶
Get retrieves a Lease by name. Returns (nil, nil) if the Lease does not exist.
func (*LeaseClient) Namespace ¶
func (c *LeaseClient) Namespace() string
Namespace returns the namespace this client operates in.
type LeaseMetadata ¶
type LeaseMetadata struct {
Name string `json:"name"`
Namespace string `json:"namespace,omitempty"`
ResourceVersion string `json:"resourceVersion,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
}
LeaseMetadata holds the standard k8s object metadata fields used by Leases.
type LeaseSpec ¶
type LeaseSpec struct {
HolderIdentity *string `json:"holderIdentity"`
LeaseDurationSeconds *int32 `json:"leaseDurationSeconds,omitempty"`
AcquireTime *MicroTime `json:"acquireTime"`
RenewTime *MicroTime `json:"renewTime"`
}
LeaseSpec holds the Lease specification fields.
type MicroTime ¶
MicroTime wraps time.Time with Kubernetes MicroTime JSON formatting.
func (*MicroTime) MarshalJSON ¶
MarshalJSON implements json.Marshaler with k8s MicroTime format.
func (*MicroTime) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler with k8s MicroTime format.