stateclient

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package stateclient provides a small typed client for takod /v1/state over the existing private takodclient transport.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("takod state not found")

ErrNotFound is returned when takod reports that a state document does not exist.

Functions

This section is empty.

Types

type Client

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

Client reads and writes canonical takoapi state documents through takod's private Unix-socket control plane.

func New

func New(executor any) *Client

New returns a state client using the provided private takod request executor.

func (*Client) AcquireLease

func (c *Client) AcquireLease(request LeaseRequest) (*LeaseResponse, error)

AcquireLease acquires the remote operation lease described by request.

func (*Client) AcquireLeaseContext

func (c *Client) AcquireLeaseContext(ctx context.Context, request LeaseRequest) (*LeaseResponse, error)

AcquireLeaseContext acquires the remote operation lease described by request bounded by ctx.

func (*Client) AppendEvent

func (c *Client) AppendEvent(document takoapi.StateEventDocument) error

AppendEvent appends a canonical state event document.

func (*Client) AppendEventContext

func (c *Client) AppendEventContext(ctx context.Context, document takoapi.StateEventDocument) error

AppendEventContext appends a canonical state event document bounded by ctx.

func (*Client) DeleteActualNode

func (c *Client) DeleteActualNode(project, environment, node string) error

DeleteActualNode deletes a per-node actual state document.

func (*Client) DeleteActualNodeContext

func (c *Client) DeleteActualNodeContext(ctx context.Context, project, environment, node string) error

DeleteActualNodeContext deletes a per-node actual state document bounded by ctx.

func (*Client) ReadActual

func (c *Client) ReadActual(project, environment string) (*takoapi.ActualStateDocument, error)

ReadActual reads the canonical aggregate actual state document.

func (*Client) ReadActualContext

func (c *Client) ReadActualContext(ctx context.Context, project, environment string) (*takoapi.ActualStateDocument, error)

ReadActualContext reads the canonical aggregate actual state document bounded by ctx.

func (*Client) ReadActualNode

func (c *Client) ReadActualNode(project, environment, node string) (*takoapi.ActualNodeStateDocument, error)

ReadActualNode reads a canonical per-node actual state document.

func (*Client) ReadActualNodeContext

func (c *Client) ReadActualNodeContext(ctx context.Context, project, environment, node string) (*takoapi.ActualNodeStateDocument, error)

ReadActualNodeContext reads a canonical per-node actual state document bounded by ctx.

func (*Client) ReadDeployment

func (c *Client) ReadDeployment(project, environment, deploymentID string) (*takoapi.DeploymentStateDocument, error)

ReadDeployment reads a single deployment history record by deployment ID.

func (*Client) ReadDeploymentContext

func (c *Client) ReadDeploymentContext(ctx context.Context, project, environment, deploymentID string) (*takoapi.DeploymentStateDocument, error)

ReadDeploymentContext reads a single deployment history record by deployment ID bounded by ctx.

func (*Client) ReadDesired

func (c *Client) ReadDesired(project, environment string) (*takoapi.DesiredStateDocument, error)

ReadDesired reads the canonical desired state document.

func (*Client) ReadDesiredContext

func (c *Client) ReadDesiredContext(ctx context.Context, project, environment string) (*takoapi.DesiredStateDocument, error)

ReadDesiredContext reads the canonical desired state document bounded by ctx.

func (*Client) ReadHistory

func (c *Client) ReadHistory(project, environment string) (*takoapi.DeploymentHistoryDocument, error)

ReadHistory reads the deployment history document.

func (*Client) ReadHistoryContext

func (c *Client) ReadHistoryContext(ctx context.Context, project, environment string) (*takoapi.DeploymentHistoryDocument, error)

ReadHistoryContext reads the deployment history document bounded by ctx.

func (*Client) ReadLease

func (c *Client) ReadLease(project, environment string) (*LeaseResponse, error)

ReadLease reads the currently held remote lease for project/environment.

func (*Client) ReadLeaseContext

func (c *Client) ReadLeaseContext(ctx context.Context, project, environment string) (*LeaseResponse, error)

ReadLeaseContext reads the currently held remote lease for project/environment bounded by ctx.

func (*Client) ReleaseLease

func (c *Client) ReleaseLease(request LeaseRequest) (*LeaseResponse, error)

ReleaseLease releases the remote lease described by request.

func (*Client) ReleaseLeaseContext

func (c *Client) ReleaseLeaseContext(ctx context.Context, request LeaseRequest) (*LeaseResponse, error)

ReleaseLeaseContext releases the remote lease described by request bounded by ctx.

func (*Client) ReplicateDeployment

func (c *Client) ReplicateDeployment(deployment takoapi.DeploymentStateDocument, history *takoapi.DeploymentHistoryDocument) error

ReplicateDeployment writes a deployment record followed by its deployment history using the private takod state transport.

func (*Client) ReplicateDeploymentContext

func (c *Client) ReplicateDeploymentContext(ctx context.Context, deployment takoapi.DeploymentStateDocument, history *takoapi.DeploymentHistoryDocument) error

ReplicateDeploymentContext writes a deployment record followed by its deployment history bounded by ctx. The deployment record is written first so peers can read the individual deployment even if the optional history write is skipped. If history is nil, only the deployment record is written.

func (*Client) WithSocket

func (c *Client) WithSocket(socket string) *Client

WithSocket returns a shallow copy configured to use socket. An empty socket uses takodclient.DefaultSocket.

func (*Client) WithTimeout

func (c *Client) WithTimeout(timeout time.Duration) *Client

WithTimeout returns a shallow copy configured to use timeout for JSON requests. Non-positive values use takodclient's default timeout.

func (*Client) WriteActual

func (c *Client) WriteActual(document takoapi.ActualStateDocument) error

WriteActual writes the canonical aggregate actual state document.

func (*Client) WriteActualContext

func (c *Client) WriteActualContext(ctx context.Context, document takoapi.ActualStateDocument) error

WriteActualContext writes the canonical aggregate actual state document bounded by ctx.

func (*Client) WriteActualNode

func (c *Client) WriteActualNode(document takoapi.ActualNodeStateDocument) error

WriteActualNode writes a canonical per-node actual state document.

func (*Client) WriteActualNodeContext

func (c *Client) WriteActualNodeContext(ctx context.Context, document takoapi.ActualNodeStateDocument) error

WriteActualNodeContext writes a canonical per-node actual state document bounded by ctx.

func (*Client) WriteDeployment

func (c *Client) WriteDeployment(document takoapi.DeploymentStateDocument) error

WriteDeployment writes a single deployment history record, using ID as the state revision ID.

func (*Client) WriteDeploymentContext

func (c *Client) WriteDeploymentContext(ctx context.Context, document takoapi.DeploymentStateDocument) error

WriteDeploymentContext writes a single deployment history record bounded by ctx, using ID as the state revision ID.

func (*Client) WriteDesired

func (c *Client) WriteDesired(document takoapi.DesiredStateDocument) error

WriteDesired writes the canonical desired state document.

func (*Client) WriteDesiredContext

func (c *Client) WriteDesiredContext(ctx context.Context, document takoapi.DesiredStateDocument) error

WriteDesiredContext writes the canonical desired state document bounded by ctx.

func (*Client) WriteHistory

func (c *Client) WriteHistory(document takoapi.DeploymentHistoryDocument) error

WriteHistory writes the deployment history document.

func (*Client) WriteHistoryContext

func (c *Client) WriteHistoryContext(ctx context.Context, document takoapi.DeploymentHistoryDocument) error

WriteHistoryContext writes the deployment history document bounded by ctx.

type LeaseInfo

type LeaseInfo struct {
	ID          string                       `json:"id"`
	Project     string                       `json:"project,omitempty"`
	ProjectName string                       `json:"projectName,omitempty"`
	Environment string                       `json:"environment"`
	Operation   string                       `json:"operation,omitempty"`
	Who         string                       `json:"who,omitempty"`
	Holder      string                       `json:"holder,omitempty"`
	User        string                       `json:"user,omitempty"`
	Host        string                       `json:"host,omitempty"`
	PID         int                          `json:"pid,omitempty"`
	AcquiredAt  time.Time                    `json:"acquiredAt,omitempty"`
	CreatedAt   time.Time                    `json:"createdAt,omitempty"`
	ExpiresAt   time.Time                    `json:"expiresAt,omitempty"`
	TTLSeconds  int64                        `json:"ttlSeconds,omitempty"`
	Fence       *nodeidentity.OperationFence `json:"fence,omitempty"`
}

LeaseInfo describes a takod operation lease as returned by /v1/lease. It intentionally mirrors only public JSON fields and does not depend on internal/state types. Both Project and ProjectName are supported because the request body uses project while existing lease metadata uses projectName.

type LeaseRequest

type LeaseRequest struct {
	Project       string   `json:"project"`
	Environment   string   `json:"environment"`
	ID            string   `json:"id,omitempty"`
	Operation     string   `json:"operation,omitempty"`
	Who           string   `json:"who,omitempty"`
	PID           int      `json:"pid,omitempty"`
	TTLSeconds    int64    `json:"ttlSeconds,omitempty"`
	Renew         bool     `json:"renew,omitempty"`
	RequestID     string   `json:"requestId,omitempty"`
	TargetNodeIDs []string `json:"targetNodeIds,omitempty"`
}

LeaseRequest is the JSON body sent to takod /v1/lease for acquire/release.

type LeaseResponse

type LeaseResponse struct {
	Acquired bool       `json:"acquired"`
	Found    bool       `json:"found"`
	Lease    *LeaseInfo `json:"lease,omitempty"`
	Message  string     `json:"message,omitempty"`
}

LeaseResponse is the public response shape returned by takod /v1/lease.

Jump to

Keyboard shortcuts

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