Documentation
¶
Overview ¶
Package client provides a Go client for the takt server's HTTP API.
The transport is generated from the OpenAPI document, so the wire format has a single description. This package wraps it to present canonical domain types and ordinary Go errors, which keeps generated response envelopes and pointer-heavy optional fields out of consumers such as the CLI.
Index ¶
- Variables
- func IsBadRequest(err error) bool
- func IsConflict(err error) bool
- func IsForbidden(err error) bool
- func IsNotFound(err error) bool
- func IsUnauthorized(err error) bool
- func IsUnavailable(err error) bool
- func IsUnprocessable(err error) bool
- func NewContext(ctx context.Context, c *Client) context.Context
- type ApplyOption
- type BackupOption
- type Client
- func (c *Client) Apply(ctx context.Context, spec manifest.Spec, options ...ApplyOption) (Workload, bool, error)
- func (c *Client) ApplyPolicy(ctx context.Context, policy manifest.Policy, options ...ApplyOption) (Policy, error)
- func (c *Client) ApplyService(ctx context.Context, service manifest.Service, options ...ApplyOption) (Service, error)
- func (c *Client) ApplyVolume(ctx context.Context, volume manifest.Volume, options ...ApplyOption) (Volume, error)
- func (c *Client) Backup(ctx context.Context, out io.Writer, options ...BackupOption) error
- func (c *Client) CreateToken(ctx context.Context, principal string) (Token, string, error)
- func (c *Client) Delete(ctx context.Context, name string, options ...LifecycleOption) (Workload, error)
- func (c *Client) DeleteSecret(ctx context.Context, name string, options ...DeleteSecretOption) error
- func (c *Client) DeleteService(ctx context.Context, name string) error
- func (c *Client) DeleteToken(ctx context.Context, id string) error
- func (c *Client) DeleteVariable(ctx context.Context, name string, options ...DeleteVariableOption) error
- func (c *Client) DeleteVolume(ctx context.Context, name string, options ...DeleteVolumeOption) error
- func (c *Client) DryRun(ctx context.Context, spec manifest.Spec) (DryRun, error)
- func (c *Client) Events(ctx context.Context, name string, options ...EventOption) ([]Event, error)
- func (c *Client) Get(ctx context.Context, name string) (Workload, error)
- func (c *Client) GetNode(ctx context.Context) (Node, error)
- func (c *Client) GetOIDC(ctx context.Context) (OIDC, error)
- func (c *Client) GetPolicy(ctx context.Context) (Policy, error)
- func (c *Client) GetSecret(ctx context.Context, name string) (Secret, error)
- func (c *Client) GetService(ctx context.Context, name string) (Service, error)
- func (c *Client) GetVariable(ctx context.Context, name string) (Variable, error)
- func (c *Client) GetVolume(ctx context.Context, name string) (Volume, error)
- func (c *Client) Health(ctx context.Context) error
- func (c *Client) InitACL(ctx context.Context) (string, error)
- func (c *Client) List(ctx context.Context, queries ...string) ([]Workload, error)
- func (c *Client) ListSecrets(ctx context.Context, queries ...string) ([]Secret, error)
- func (c *Client) ListServices(ctx context.Context, queries ...string) ([]Service, error)
- func (c *Client) ListTokens(ctx context.Context) ([]Token, error)
- func (c *Client) ListVariables(ctx context.Context, queries ...string) ([]Variable, error)
- func (c *Client) ListVolumes(ctx context.Context, queries ...string) ([]Volume, error)
- func (c *Client) LoginCode(ctx context.Context, code, verifier, redirectURI string) (Login, error)
- func (c *Client) Logout(ctx context.Context) error
- func (c *Client) Logs(ctx context.Context, out io.Writer, name string, options ...LogOption) error
- func (c *Client) Metrics(ctx context.Context, out io.Writer) error
- func (c *Client) Ready(ctx context.Context) (Readiness, error)
- func (c *Client) Rekey(ctx context.Context) (Rekey, error)
- func (c *Client) Restart(ctx context.Context, name string, options ...LifecycleOption) (Workload, error)
- func (c *Client) SetSecret(ctx context.Context, secret manifest.Secret, options ...ApplyOption) (Secret, bool, error)
- func (c *Client) SetVariable(ctx context.Context, variable manifest.Variable, options ...ApplyOption) (Variable, bool, error)
- func (c *Client) Start(ctx context.Context, name string, options ...LifecycleOption) (Workload, error)
- func (c *Client) Stop(ctx context.Context, name string, options ...LifecycleOption) (Workload, error)
- func (c *Client) StreamServices(ctx context.Context, fn func([]Service) error, queries ...string) error
- func (c *Client) WhoAmI(ctx context.Context) (Identity, error)
- type DeleteSecretOption
- type DeleteVariableOption
- type DeleteVolumeOption
- type DryRun
- type Error
- type Event
- type EventData
- type EventOption
- type EventReason
- type Health
- type HealthStatus
- type Identity
- type Instance
- type InstanceState
- type LifecycleOption
- type LogOption
- type Login
- type Node
- type NodeAllocation
- type NodeDisk
- type NodeDisks
- type NodeLoad
- type NodeMemory
- type OIDC
- type Option
- type Policy
- type Readiness
- type Rekey
- type ResolvedPort
- type Secret
- type Service
- type ServiceBackend
- type Token
- type Usage
- type Variable
- type Volume
- type Workload
- type WorkloadState
Constants ¶
This section is empty.
Variables ¶
var ( // ErrWorkloadNotFound is returned when no workload exists with the given name. ErrWorkloadNotFound = errors.New("workload not found") // ErrWorkloadChanged is returned when a conditional apply names a tag that is no // longer the workload's. ErrWorkloadChanged = errors.New("workload changed since it was read") // ErrWorkloadInUse is returned when a workload another one references is deleted // without being forced. ErrWorkloadInUse = errors.New("workload is in use") // ErrVolumeNotFound is returned when no volume exists with the given name. ErrVolumeNotFound = errors.New("volume not found") // ErrVolumeChanged is returned when a conditional apply names a tag that is no // longer the volume's. ErrVolumeChanged = errors.New("volume changed since it was read") // ErrVolumeInUse is returned when a volume a workload mounts is deleted without // being forced. ErrVolumeInUse = errors.New("volume is in use") // ErrInvalidVolumeName is returned when a name is not usable as a single segment // of a request path. ErrInvalidVolumeName = errors.New("invalid volume name") // ErrServiceNotFound is returned when no service exists with the given name. ErrServiceNotFound = errors.New("service not found") // ErrServiceChanged is returned when a conditional apply names a tag that is no // longer the service's. ErrServiceChanged = errors.New("service changed since it was read") // ErrInvalidServiceName is returned when a name is not usable as a single // segment of a request path. ErrInvalidServiceName = errors.New("invalid service name") // ErrSecretChanged is returned when a conditional set names a tag that is no // longer the secret's. ErrSecretChanged = errors.New("secret changed since it was read") // ErrVariableChanged is returned when a conditional set names a tag that is no // longer the variable's. ErrVariableChanged = errors.New("variable changed since it was read") // ErrSecretNotFound is returned when no secret exists with the given name. ErrSecretNotFound = errors.New("secret not found") // ErrSecretInUse is returned when a secret a workload reads is deleted without // being forced. ErrSecretInUse = errors.New("secret is in use") // ErrInvalidSecretName is returned when a name is not usable as a single segment // of a request path. ErrInvalidSecretName = errors.New("invalid secret name") // ErrVariableNotFound is returned when no variable exists with the given name. ErrVariableNotFound = errors.New("variable not found") // ErrVariableInUse is returned when a variable a workload reads is deleted // without being forced. ErrVariableInUse = errors.New("variable is in use") // ErrInvalidVariableName is returned when a name is not usable as a single // segment of a request path. ErrInvalidVariableName = errors.New("invalid variable name") // ErrTokenNotFound is returned when no token exists with the given // identifier. ErrTokenNotFound = errors.New("token not found") // ErrInvalidTokenID is returned when an identifier is not usable as a // single segment of a request path. ErrInvalidTokenID = errors.New("invalid token id") // ErrACLInitialized is returned when init is asked for and a recovery // token already exists. ErrACLInitialized = errors.New("acl already initialized") // ErrPolicyChanged is returned when the policy an apply was conditioned // on is no longer the policy the server holds. ErrPolicyChanged = errors.New("policy changed since it was read") // ErrRecoveryLogout is returned when the recovery token asks to revoke // itself, which only the reset file does. ErrRecoveryLogout = errors.New("the recovery token is revoked by the reset file") // ErrRecoveryDelete is returned when a delete names the recovery token, // which only the reset file revokes. ErrRecoveryDelete = errors.New("the recovery token is revoked by the reset file") // ErrOIDCNotConfigured is returned when a login is asked for and the // server carries no OIDC configuration. ErrOIDCNotConfigured = errors.New("oidc is not configured") )
Functions ¶
func IsBadRequest ¶
IsBadRequest reports whether err is a server-side error with a 400 status.
func IsConflict ¶
IsConflict reports whether err is a server-side error with a 409 status, which the server uses when a workload cannot be applied because it is being deleted.
func IsForbidden ¶ added in v0.5.0
IsForbidden reports whether err is a server-side error with a 403 status, which the server uses when the caller's role does not cover the operation.
func IsNotFound ¶
IsNotFound reports whether err is a server-side error with a 404 status.
func IsUnauthorized ¶ added in v0.5.0
IsUnauthorized reports whether err is a server-side error with a 401 status, which the server uses when a request presents no valid credential.
func IsUnavailable ¶
IsUnavailable reports whether err is a server-side error with a 503 status, which the server uses when it has no host port to give a workload that needs one.
func IsUnprocessable ¶
IsUnprocessable reports whether err is a server-side error with a 422 status, which the server uses for a specification it understands but cannot run.
Types ¶
type ApplyOption ¶ added in v0.9.0
type ApplyOption func(*applyConfig)
The ApplyOption type is a function that modifies how an apply is made.
func WithIfMatch ¶ added in v0.9.0
func WithIfMatch(etag string) ApplyOption
WithIfMatch conditions an apply on the resource still carrying the given tag, as read from the ETag of the get that produced it.
An apply without it writes whatever it is given over whatever is there. With it, an apply working from a read that has since gone stale is refused rather than quietly discarding the write that landed in between, reported as the resource's own changed error.
An empty tag is the same as not passing the option at all, so a caller threading through a flag left unset does not have to special-case it.
func WithRolloutInterval ¶ added in v0.13.0
func WithRolloutInterval(interval time.Duration) ApplyOption
WithRolloutInterval modifies how often a waiting apply polls the server, and implies WithWaitForRollout.
func WithWaitForRollout ¶ added in v0.13.0
func WithWaitForRollout() ApplyOption
WithWaitForRollout modifies a workload apply to block until the workload has settled on what was applied: it is running, or completed for one that runs to an end, and when the apply moved its version, every instance it reports is one started since.
Read only by Apply. A volume, service, secret or variable is stored as it is applied, so there is nothing for the others to wait on.
Waiting is polling, so the call returns once that has happened, the context is cancelled, or the server reports an error. A workload on a schedule settles when its next occurrence runs, so a wait on one blocks until then.
type BackupOption ¶
type BackupOption func(*backupConfig)
The BackupOption type is a function that modifies what a backup covers.
func WithKeys ¶
func WithKeys() BackupOption
WithKeys modifies a backup to hold the keyring alongside the database.
Left out unless this is passed, and the default is the one to prefer. A database without its keys decrypts nothing, and that separability is what makes a copy of it safe to keep somewhere a key would not be. An archive holding both is key material: it opens every secret the server holds, and it keeps opening them long after the backup was taken.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
The Client type talks to an takt server over HTTP.
func FromConfig ¶ added in v0.6.0
FromConfig returns a Client connecting with the resolved settings: the address, the certificate authority when the settings name one, and the token as a bearer credential when they hold one. Options apply after the settings, so a caller can override what the settings supply.
func FromContext ¶
FromContext returns the client the context carries, or nil when it carries none.
func New ¶
New returns a Client that targets the takt server at the given address.
An invalid address or an unusable certificate authority file is rejected here so that callers see the problem at construction time rather than on their first request.
func (*Client) Apply ¶
func (c *Client) Apply(ctx context.Context, spec manifest.Spec, options ...ApplyOption) (Workload, bool, error)
Apply stores spec as the desired state for its name, reporting whether the workload was newly created.
Applying an unchanged specification is a no-op that leaves the workload's version alone.
The apply returns once the server has stored the specification, which is before anything runs it. Pass WithWaitForRollout to block until the workload has settled on it, and the returned workload is then the one that settled.
func (*Client) ApplyPolicy ¶ added in v0.5.0
func (c *Client) ApplyPolicy(ctx context.Context, policy manifest.Policy, options ...ApplyOption) (Policy, error)
ApplyPolicy replaces the whole policy with the given document, on the condition that the policy still carries the tag WithIfMatch names. A stale tag is reported as ErrPolicyChanged rather than silently clobbering a concurrent apply: read the policy again and re-apply.
Without WithIfMatch the tag is read first and the apply conditioned on it, which is the one-step form `takt acl apply` uses. The apply is never unconditional, unlike a resource apply without the option. The policy always exists, so there is always a tag to name, and an apply that named none would be a lost update on its way to happening.
Returns the policy as applied, carrying its new tag.
func (*Client) ApplyService ¶
func (c *Client) ApplyService(ctx context.Context, service manifest.Service, options ...ApplyOption) (Service, error)
ApplyService submits the service as desired state, returning it as it now stands with its backends resolved.
The operation is idempotent: the stored selection becomes what the manifest says, however many times it is applied. The workloads the target selects do not have to exist, so a service applied ahead of its workloads reports no backends until they arrive.
func (*Client) ApplyVolume ¶ added in v0.3.0
func (c *Client) ApplyVolume(ctx context.Context, volume manifest.Volume, options ...ApplyOption) (Volume, error)
ApplyVolume stores the volume the manifest describes, creating it when the name is new and replacing its labels, owner and mode when it is not, returning it as it now stands.
The operation is idempotent: the stored volume becomes what the manifest says, however many times it is applied. The directory keeps its path across an apply, so nothing mounting the volume is redeployed, and the owner and mode are reapplied to it — which is also how a live volume is handed to another user. A manifest clearing either leaves the directory as it stands.
A volume has to exist before a workload can mount it, so that a mistyped name is reported rather than quietly becoming a second empty volume.
func (*Client) Backup ¶
Backup writes a backup of the server's state to out, as a zip archive.
The archive holds a consistent snapshot of the database taken while the server keeps running, and the keyring when WithKeys is passed. It holds neither volume data, which the server has no business copying, nor the files a workload mounts, which are transient. Volumes are backed up separately, and ListVolumes reports where each one is on the host.
The archive is copied as it arrives rather than returned, like Metrics: it is the size of the server's database, and the usual destination is a file.
func (*Client) CreateToken ¶ added in v0.5.0
CreateToken mints a static client token bound to the given principal, returning its record and the credential itself. The credential is reported this once: the server stores only a hash of it.
func (*Client) Delete ¶
func (c *Client) Delete(ctx context.Context, name string, options ...LifecycleOption) (Workload, error)
Delete marks the workload with the given name for deletion and returns it as it stood when marked, returning ErrWorkloadNotFound when no such workload exists.
Deletion is asynchronous: the returned workload is reported as terminating, and disappears once the server has stopped everything running for it. Pass WithWait to block until that has happened.
A workload another one references is refused with ErrWorkloadInUse, and the error names the workloads reading its address. Pass WithForceDeleteWorkload to delete it anyway.
func (*Client) DeleteSecret ¶
func (c *Client) DeleteSecret(ctx context.Context, name string, options ...DeleteSecretOption) error
DeleteSecret removes the secret with the given name.
A secret a workload reads is refused with ErrSecretInUse, and the error names the workloads reading it. Pass WithForceDelete to remove it anyway, which leaves those workloads running until something replaces them and then unable to start.
func (*Client) DeleteService ¶
DeleteService removes the service with the given name, returning ErrServiceNotFound when no such service exists.
The workloads the service selected keep running. What stops is the service reporting their addresses.
func (*Client) DeleteToken ¶ added in v0.5.0
DeleteToken revokes the token with the given identifier, returning ErrTokenNotFound when no such token exists. Revocation is immediate: the next request presenting the credential is refused. The one refusal is the recovery token, reported as ErrRecoveryDelete: its revocation path is the reset file, not this call.
func (*Client) DeleteVariable ¶
func (c *Client) DeleteVariable(ctx context.Context, name string, options ...DeleteVariableOption) error
DeleteVariable removes the variable with the given name.
A variable a workload reads is refused with ErrVariableInUse, and the error names the workloads reading it. Pass WithForceDeleteVariable to remove it anyway, which leaves those workloads running until something replaces them and then unable to start.
func (*Client) DeleteVolume ¶
func (c *Client) DeleteVolume(ctx context.Context, name string, options ...DeleteVolumeOption) error
DeleteVolume removes the volume with the given name and everything stored in it.
A volume a workload mounts is refused with ErrVolumeInUse, and the error names the workloads holding it. Pass WithForce to remove it anyway. Nothing else in takt removes a volume, so this is the only call that destroys stored data.
func (*Client) DryRun ¶
DryRun reports what applying spec would do, without applying it.
The server resolves the specification exactly as an apply resolves it, so everything an apply refuses this refuses too: a volume, secret, variable or workload the specification names and nothing holds, a pinned host port another workload has, a workload being torn down, and a specification that is not runnable. A dry run that returns is therefore a statement about the apply.
Nothing is allocated, so a port mapping needing a host port comes back without one and its path is named in Unknown.
The fields that differ from the stored specification are named in Changed. They say what about the workload would move, where the hash says only that something would.
func (*Client) Events ¶ added in v0.7.0
Events returns what the server recorded about the named workload while converging it, most recently seen first, as the options describe. Returns ErrWorkloadNotFound when no such workload exists.
Passing no options reads the most recent events with the server deciding how many of them to return.
func (*Client) Get ¶
Get returns the workload with the given name, returning ErrWorkloadNotFound when no such workload exists.
func (*Client) GetOIDC ¶ added in v0.5.0
GetOIDC returns the issuer and client identifier a login runs the authorization code flow against, reporting ErrOIDCNotConfigured when the server carries no OIDC configuration.
func (*Client) GetPolicy ¶ added in v0.5.0
GetPolicy returns the canonical current policy document and the tag a conditional apply presents back.
func (*Client) GetSecret ¶
GetSecret returns the secret with the given name, without its value, returning ErrSecretNotFound when no such secret exists.
func (*Client) GetService ¶
GetService returns the service with the given name with its backends resolved, returning ErrServiceNotFound when no such service exists.
func (*Client) GetVariable ¶
GetVariable returns the variable with the given name, returning ErrVariableNotFound when no such variable exists.
func (*Client) GetVolume ¶
GetVolume returns the volume with the given name, returning ErrVolumeNotFound when no such volume exists.
func (*Client) Health ¶
Health reports whether the server is alive and serving requests. A nil error is the whole answer.
func (*Client) InitACL ¶ added in v0.5.0
InitACL mints the recovery token and returns it. It works exactly once: ErrACLInitialized is reported for as long as a recovery token exists, and only the reset file in the server's data directory makes it work again.
func (*Client) List ¶
List returns the workloads matching every one of the given queries, or all of them when none are given.
A query is a "path=value" filter over the workload's specification, where the path is a JSON path such as "$.labels.app". Values are compared as text, so a number is matched by its digits.
func (*Client) ListSecrets ¶
ListSecrets returns the secrets matching every one of the given queries, or all of them when none are given, without their values.
A query is a "path=value" filter over the secret's labels, where the path is a JSON path such as "$.labels.app". A query can reach only the labels, so it cannot probe what a secret holds.
func (*Client) ListServices ¶
ListServices returns the services matching every one of the given queries, or all of them when none are given.
A query is a "path=value" filter over the service's labels, where the path is a JSON path such as "$.labels.app". A query can reach only the service's own labels, not its target's.
func (*Client) ListTokens ¶ added in v0.5.0
ListTokens names every credential the server holds, newest first. With GetPolicy, this answers "who can touch this server" completely.
func (*Client) ListVariables ¶
ListVariables returns the variables matching every one of the given queries, or all of them when none are given, with their values.
A query is a "path=value" filter over the variable's labels, where the path is a JSON path such as "$.labels.app". A query can reach only the labels.
func (*Client) ListVolumes ¶
ListVolumes returns the volumes matching every one of the given queries, or all of them when none are given.
A query is a "path=value" filter over the volume's labels, where the path is a JSON path such as "$.labels.app". A query can reach only the labels.
func (*Client) LoginCode ¶ added in v0.5.0
LoginCode trades an authorization code from a loopback flow for a short-lived client token. The server performs the exchange with the issuer, because the exchange is what needs the client secret and the secret never reaches a client.
func (*Client) Logout ¶ added in v0.5.0
Logout revokes the credential this client authenticated with, whatever its kind. The one refusal is the recovery token, reported as ErrRecoveryLogout: its revocation path is the reset file, not this call.
func (*Client) Logs ¶
Logs writes the recent output of the named workload to out, as the options describe.
Passing no options reads the current instance with the server deciding how much of it to return.
A followed read does not return until the instance ends or the context is cancelled. Cancellation is not reported as a failure: it is how a caller ends a follow.
The output is copied as it arrives rather than returned, so a workload with a lot of output doesn't have to fit in the caller's memory before any of it is usable.
func (*Client) Metrics ¶
Metrics writes the server's metrics to out, in the Prometheus text format.
The output is copied as it arrives rather than returned, like Logs: the response grows with the number of workloads, and the usual destination is a file or a pipe rather than memory.
func (*Client) Ready ¶
Ready reports whether the server can do its job: the database answers, and every configured driver answered the most recent attempt to observe it.
A not-ready answer is an answer rather than an error: the server responded, and the reasons say what is missing. The error is for a request that failed.
func (*Client) Rekey ¶
Rekey re-encrypts every secret the server holds under a newly generated key.
No workload is redeployed by this. A rekey changes how a value is stored, not what it is, so no secret's revision moves.
The keyring needs a fresh backup afterwards. The copy taken before this call no longer opens anything the server holds.
func (*Client) Restart ¶
func (c *Client) Restart(ctx context.Context, name string, options ...LifecycleOption) (Workload, error)
Restart asks the server to replace the workload's running instances and returns the workload as it stood when the request was recorded. Returns ErrWorkloadNotFound when no such workload exists, and IsConflict reports true of the error for a workload that is being deleted or is suspended.
The replacement happens on the server's next pass, from the unchanged specification, so the version does not move. Pass WithWait to block until an instance that did not exist before the request has started.
func (*Client) SetSecret ¶
func (c *Client) SetSecret(ctx context.Context, secret manifest.Secret, options ...ApplyOption) (Secret, bool, error)
SetSecret stores the given secret, reporting whether it was newly created.
Setting a secret to the value it already holds does nothing, so a caller that sets every secret on every run does not restart the workloads reading them. A value that did change replaces those workloads, and reaches them as they start.
Pass WithIfMatch to condition the set on the tag a get reported, which is refused with ErrSecretChanged when the secret has moved on since.
func (*Client) SetVariable ¶
func (c *Client) SetVariable(ctx context.Context, variable manifest.Variable, options ...ApplyOption) (Variable, bool, error)
SetVariable stores the given variable, reporting whether it was newly created.
Setting a variable to the value it already holds does nothing, so a caller that sets every variable on every run does not restart the workloads reading them. A value that did change replaces those workloads, and reaches them as they start.
Pass WithIfMatch to condition the set on the tag a get reported, which is refused with ErrVariableChanged when the variable has moved on since.
func (*Client) Start ¶
func (c *Client) Start(ctx context.Context, name string, options ...LifecycleOption) (Workload, error)
Start clears the suspension of the workload with the given name and returns it as it stood when cleared. Returns ErrWorkloadNotFound when no such workload exists, and IsConflict reports true of the error for a workload that is being deleted.
Starting is asynchronous: the server starts the workload's instances on its next pass. Pass WithWait to block until something is up for the workload that was not up before — for a scheduled workload that is its next occurrence, so waiting on one blocks until the schedule next fires. Starting a workload that is not suspended changes nothing, and waiting on one returns as soon as it is read.
func (*Client) Stop ¶
func (c *Client) Stop(ctx context.Context, name string, options ...LifecycleOption) (Workload, error)
Stop marks the workload with the given name as suspended and returns it as it stood when marked. Returns ErrWorkloadNotFound when no such workload exists, and IsConflict reports true of the error for a workload that is being deleted.
Stopping is asynchronous: the mark holds the workload down and the server stops its instances afterwards. Pass WithWait to block until nothing is running for it. The specification and its version are untouched, so Start resumes the workload rather than replacing it. Suspension survives a server restart and holds until Start clears it.
func (*Client) StreamServices ¶ added in v0.8.0
func (c *Client) StreamServices(ctx context.Context, fn func([]Service) error, queries ...string) error
StreamServices calls fn with the services matching every one of the given queries as soon as the server answers, and again each time the set changes, until ctx is cancelled, fn returns an error, or the server ends the stream.
Each call carries the whole set, so fn replaces what it knows rather than applying a change to it: a service or backend that has gone is absent from the next call. Cancellation is not reported as a failure, since it is how a caller ends a stream. A server ending it is reported as nil too, and a caller that wants to keep following opens a new stream and starts again from the first set.
type DeleteSecretOption ¶
type DeleteSecretOption func(*deleteSecretConfig)
The DeleteSecretOption type configures how a secret is deleted.
func WithForceDelete ¶
func WithForceDelete() DeleteSecretOption
WithForceDelete removes a secret even though a workload reads it.
Separate from WithForce, which deletes a volume, because an option that could be passed to either call would compile against the wrong one.
type DeleteVariableOption ¶
type DeleteVariableOption func(*deleteVariableConfig)
The DeleteVariableOption type configures how a variable is deleted.
func WithForceDeleteVariable ¶
func WithForceDeleteVariable() DeleteVariableOption
WithForceDeleteVariable removes a variable even though a workload reads it.
Named apart from WithForceDelete, which deletes a secret, because an option that could be passed to either call would compile against the wrong one.
type DeleteVolumeOption ¶
type DeleteVolumeOption func(*deleteVolumeConfig)
The DeleteVolumeOption type configures how a volume is deleted.
func WithForce ¶
func WithForce() DeleteVolumeOption
WithForce removes a volume even though a workload mounts it. The workload keeps running and its mount stops resolving, so this is for a volume whose workloads are known not to need it.
type DryRun ¶
type DryRun struct {
// The specification as the server would store it: defaults in place,
// volumes resolved to the paths they live at, and every port settled that
// could be settled without allocating one.
Spec manifest.Spec
// The hash the apply would store. Empty when a host port has yet to be
// allocated, since the allocation reaches the hash and nothing has chosen
// one.
SpecHash string
// Whether nothing holds the name, so applying creates the workload.
Created bool
// Whether applying moves the stored hash, so the running instances are
// replaced. False for a workload that does not exist.
Replaced bool
// The paths into Spec whose values the server settles only as it applies. A
// host port it has yet to allocate is the only one.
Unknown []string
// The paths into Spec that differ from the specification the server stores.
// Empty for a workload that does not exist, which has nothing to differ
// from.
//
// A workload can be replaced with none of these set. The hash covers what a
// workload reads as well as what it says, so an image rebuilt under the same
// tag replaces an instance with the manifest untouched.
Changed []string
}
The DryRun type reports what applying a specification would do, none of it having been done.
type Error ¶
type Error struct {
// The HTTP status code the server responded with.
Status int
// The message the server reported.
Message string
}
The Error type describes an unsuccessful response from the server.
type Event ¶ added in v0.7.0
type Event struct {
// Why the event was recorded.
Reason EventReason
// The event as a sentence, rendered by the server.
Message string
// The values the message was rendered from. Which fields are set depends on
// the reason, and none are for a reason whose message says everything.
Data EventData
// How many times the event was seen between FirstSeen and LastSeen.
Count int
// When the current run of sightings began.
FirstSeen time.Time
// When the event was last seen.
LastSeen time.Time
}
The Event type is something the server observed about a workload while converging it.
Repeated sightings of one thing coalesce into a single event, so this carries a count and the two times that bound it rather than appearing once per sighting. It says a thing was true as of LastSeen, which is a claim about the past rather than about the workload now.
type EventData ¶ added in v0.7.0
type EventData struct {
// The image reference, expected hash, or other reference the event concerns.
Reference string
// The name of another object the event concerns, such as the secret whose
// change moved a workload's hash.
Name string
// The specification hash the workload is converging towards.
Hash string
// The specification hash the workload was at, where the event reports a move.
Previous string
// The version of the specification the event concerns.
Version int
// The ordinal of the instance the event concerns, counting from zero.
Instance int
// The status an instance ended with. Nil where the event did not record one,
// which is not the same as a clean exit reporting zero.
ExitCode *int
// How many times something has happened, such as the consecutive failures a
// health check has reported. This counts within one sighting, where Event.Count
// counts the sightings.
Count int
// How long the server is waiting before it tries again.
Delay time.Duration
// The digest an image reference resolves to, where the event concerns one.
Digest string
// The schedule expression the event concerns.
Schedule string
// The signal sent to the workload, where the event reports one.
Signal string
// The host ports the event concerns.
Ports []int
// What went wrong, where the event reports a failure.
Error string
}
The EventData type carries the values an event's message was rendered from.
It is one struct covering every reason rather than a type per reason, because reasons overlap in what they name. A reason sets the two or three fields its message needs and leaves the rest at their zero values.
type EventOption ¶ added in v0.9.0
type EventOption func(*eventConfig)
The EventOption type is a function that modifies which events are read.
func WithEventsLimit ¶ added in v0.9.0
func WithEventsLimit(events int) EventOption
WithEventsLimit modifies a read to return no more than a number of events.
A count of zero or less leaves the limit to the server, which is also what happens when this is not passed at all. The server caps what it will read either way, so a generous count is answered with as much as it is willing to serve rather than refused.
func WithEventsSince ¶ added in v0.9.0
func WithEventsSince(t time.Time) EventOption
WithEventsSince modifies a read to return only the events last seen after an instant.
The filter is on the last sighting rather than the first, so an event that recurs is returned again carrying its new count. A caller polling for what changed passes back the newest LastSeen it has already read, and a changed count is a change worth reporting.
type EventReason ¶ added in v0.7.0
type EventReason string
The EventReason type names why the server recorded an event.
Match on this rather than on the rendered message, which is worded for a human and may be reworded between releases. The constants below are what this version of the client knows about. A server newer than the client may send a reason none of them names, so a switch on a reason needs a default rather than treating the set as closed.
const ( // EventImagePulling indicates the workload is waiting on an image being fetched. EventImagePulling EventReason = "imagePulling" // EventRestartPaced indicates the server is waiting before it starts the workload // again, having started it recently. EventRestartPaced EventReason = "restartPaced" // EventRestartGaveUp indicates the server has stopped trying to start the workload. EventRestartGaveUp EventReason = "restartGaveUp" // EventReferenceUnresolved indicates something the specification refers to could // not be read, such as a pinned image reference. EventReferenceUnresolved EventReason = "referenceUnresolved" // EventDependencyNotReady indicates the server is holding the workload's first // start until the instance of a workload it references passes its health check. EventDependencyNotReady EventReason = "dependencyNotReady" // EventDependencyWaitGivenUp indicates the server started the workload without // waiting any longer for the instance it references to pass its health check. EventDependencyWaitGivenUp EventReason = "dependencyWaitGivenUp" )
The reasons a workload has not started yet.
const ( // EventSpecificationModified indicates the submitted specification changed. EventSpecificationModified EventReason = "specificationModified" // EventPortsDrifted indicates an instance's published ports no longer match the // ports the workload was given. EventPortsDrifted EventReason = "portsDrifted" // EventHashMoved indicates an instance is being replaced because the workload's // specification hash moved. EventHashMoved EventReason = "hashMoved" // EventSecretChanged indicates a secret the workload reads was written. EventSecretChanged EventReason = "secretChanged" // EventVariableChanged indicates a variable the workload reads was written. EventVariableChanged EventReason = "variableChanged" // EventAddressMoved indicates another workload this one refers to moved. EventAddressMoved EventReason = "addressMoved" // EventAddressRemoved indicates another workload this one refers to was deleted. EventAddressRemoved EventReason = "addressRemoved" // EventHealthCheckFailing indicates the workload's health check has failed enough // consecutive times to count against it. EventHealthCheckFailing EventReason = "healthCheckFailing" // EventHealthCheckRecovered indicates the workload's health check passes again. EventHealthCheckRecovered EventReason = "healthCheckRecovered" // EventInstanceExited indicates an instance ended on its own. EventInstanceExited EventReason = "instanceExited" // EventInstanceUnhealthy indicates an instance was replaced because it failed its // health check while its runtime still reported it running. EventInstanceUnhealthy EventReason = "instanceUnhealthy" )
The reasons a workload restarted.
const ( // EventApplied indicates a specification was submitted for the workload. EventApplied EventReason = "applied" // EventSuspended indicates an operator stopped the workload and held it down. EventSuspended EventReason = "suspended" // EventResumed indicates an operator started a suspended workload again. EventResumed EventReason = "resumed" // EventRestartRequested indicates an operator asked for the workload's instances // to be replaced. EventRestartRequested EventReason = "restartRequested" // EventDeleted indicates the workload was marked for deletion. EventDeleted EventReason = "deleted" // EventInstanceStarted indicates the server started an instance. EventInstanceStarted EventReason = "instanceStarted" // EventInstanceRemoved indicates the server removed an instance it no longer wants. EventInstanceRemoved EventReason = "instanceRemoved" // EventPortsAbandoned indicates the server gave up host ports the workload held. EventPortsAbandoned EventReason = "portsAbandoned" // EventMountsRefreshed indicates the workload was signalled because a value it // mounts changed. EventMountsRefreshed EventReason = "mountsRefreshed" )
The reasons naming something done to a workload.
const ( // EventRunStarted indicates a scheduled run began. EventRunStarted EventReason = "runStarted" // EventRunFinished indicates a scheduled run ended. EventRunFinished EventReason = "runFinished" // EventOccurrenceSkipped indicates an occurrence was passed over because the run // before it had not finished. EventOccurrenceSkipped EventReason = "occurrenceSkipped" // EventOccurrenceReplaced indicates an occurrence stopped a run that had not // finished and took its place. EventOccurrenceReplaced EventReason = "occurrenceReplaced" // EventScheduleInvalid indicates the workload's schedule could not be read. EventScheduleInvalid EventReason = "scheduleInvalid" )
The reasons particular to a workload on a schedule.
const ( // EventImageDrifted indicates a pull-always workload's tag resolves to a digest // other than the one its instances were hashed with, and nothing was replaced. EventImageDrifted EventReason = "imageDrifted" // EventImageFollowed indicates a followed workload's hash was moved to a // rebuilt tag, replacing its instances. EventImageFollowed EventReason = "imageFollowed" // EventDigestUnresolved indicates the registry could not say what a tag // resolves to, so nothing was compared. EventDigestUnresolved EventReason = "digestUnresolved" // EventFollowUnscheduled indicates a workload asked to follow its tag on a // server that checks no digests. EventFollowUnscheduled EventReason = "followUnscheduled" )
The reasons concerning a workload's image between starts.
const ( // EventConvergeFailed indicates a pass over the workload did not finish. EventConvergeFailed EventReason = "convergeFailed" )
type Health ¶
type Health struct {
// Whether the instance is working.
Status HealthStatus
// How many consecutive checks have failed. Nil when the check is the
// runtime's own rather than one takt performs, since takt counts no
// failures against a check it did not run.
Failures *int
// When the check last ran, if it has run at all.
CheckedAt time.Time
// Why the last check failed, when it did.
Error string
}
The Health type is the client-side view of a health check's outcome.
type HealthStatus ¶
type HealthStatus string
The HealthStatus type describes whether a workload is working, as distinct from whether its runtime reports it started.
const ( // HealthStarting indicates the workload has not yet passed a check, either // because it is inside its start period or because nothing has answered yet. HealthStarting HealthStatus = "starting" // HealthHealthy indicates the workload's most recent check passed. HealthHealthy HealthStatus = "healthy" // HealthUnhealthy indicates enough consecutive checks have failed to exhaust the // workload's retries. HealthUnhealthy HealthStatus = "unhealthy" )
type Identity ¶ added in v0.5.0
type Identity struct {
// Whether authentication is enabled on the server.
Enabled bool
// The name the caller authenticated as. "anonymous" when
// authentication is disabled, and empty for the recovery token.
Principal string
// The role the policy grants the caller, empty when it grants
// nothing.
Role string
// The groups asserted for the caller when its token was minted.
Groups []string
// Whether the caller authenticated with the recovery token.
Recovery bool
}
The Identity type is the client-side view of who the caller is.
type Instance ¶
type Instance struct {
// The server's opaque handle for this instance.
ID string
// The index of the instance among the workload's instances, counted from
// zero up to the specification's count.
Index int
// The instance's current state.
State InstanceState
// The hash of the specification the instance was started from.
SpecHash string
// The exit code. Nil while the instance is still running.
ExitCode *int
// When the instance last started, if it has started at all.
StartedAt time.Time
// What the most recent health check established. Nil when the instance is
// not checked at all.
Health *Health
// What the instance is consuming, against the limits it answers to. Nil
// when the server had no reading for it, which an instance that is not
// running has none of.
Usage *Usage
}
The Instance type is the client-side view of one unit of work the server is running for a workload.
type InstanceState ¶
type InstanceState string
The InstanceState type describes the state of a single unit of work the server is running for a workload.
It is distinct from WorkloadState because the two do not share a vocabulary: an instance exits, where a workload whose instances have all exited is stopped.
const ( // InstanceStatePending indicates the instance has been created but is not yet // running. InstanceStatePending InstanceState = "pending" // InstanceStateRunning indicates the instance is up. InstanceStateRunning InstanceState = "running" // InstanceStateTerminating indicates the instance is on its way out. InstanceStateTerminating InstanceState = "terminating" // InstanceStateExited indicates the instance ended without failing. InstanceStateExited InstanceState = "exited" // InstanceStateCompleted indicates the instance ended cleanly and nothing will // restart it, whether because its workload's restart policy asks for nothing // further or because the workload runs on a schedule. InstanceStateCompleted InstanceState = "completed" // InstanceStateFailed indicates the instance ended in failure. InstanceStateFailed InstanceState = "failed" )
type LifecycleOption ¶
type LifecycleOption func(*lifecycleConfig)
The LifecycleOption type is a function that modifies how a workload lifecycle operation is performed.
func WithForceDeleteWorkload ¶
func WithForceDeleteWorkload() LifecycleOption
WithForceDeleteWorkload deletes a workload even though another workload references its address. Those workloads are redeployed and then report the reference they can no longer resolve, retrying until something holds the name again.
Read only by Delete. The other lifecycle calls leave the workload in place, so there is nothing for them to force.
func WithWait ¶
func WithWait() LifecycleOption
WithWait modifies a lifecycle operation to block until the server has finished acting on it: a delete until the workload has disappeared, a stop until nothing is running for it, a start until something is, and a restart until a replacement instance has appeared.
Waiting is polling, so the call returns once that has happened, the context is cancelled, or the server reports an error.
func WithWaitInterval ¶
func WithWaitInterval(interval time.Duration) LifecycleOption
WithWaitInterval modifies how often a waiting operation polls the server, and implies WithWait.
type LogOption ¶
type LogOption func(*logConfig)
The LogOption type is a function that modifies which output is read.
func WithFollow ¶
func WithFollow() LogOption
WithFollow modifies a read to keep writing output as the workload produces it.
The read ends when the instance ends, which is what somebody watching a workload start is waiting for either way. A replacement is a new instance, so a workload that restarts while you watch needs another read.
Cancelling the context is how a caller ends a follow early, and it ends the read rather than failing it. This cannot be combined with WithPrevious, which reads an instance that has already ended.
func WithInstance ¶
WithInstance modifies a read to return one instance's output, selected by its index.
Without it every instance's output is returned, except on a follow of a workload running more than one instance, which the server refuses: a follow reads one stream until it ends, and interleaving several would return output nothing could attribute.
func WithLogsSince ¶ added in v0.9.0
WithLogsSince modifies a read to return only the output written at or after an instant.
This reaches container workloads only. An exec workload's output is a plain file with no timestamps in it, so the server ignores this rather than filtering on times it would have to invent.
func WithPrevious ¶
func WithPrevious() LogOption
WithPrevious modifies a read to return the output of the instance that was replaced rather than the one running now.
The server keeps the instance it most recently stopped so that the output of an attempt that ended survives it. For a workload restarting repeatedly this is the attempt that failed, where the one running now has not failed yet. A workload that has only ever run once has no earlier attempt, and nothing is written.
func WithTail ¶
WithTail modifies a read to return only the last lines of the output.
A count of zero or less leaves the limit to the server, which is also what happens when this is not passed at all. The server caps what it will read either way, so a generous count is answered with as much as it is willing to serve rather than refused.
type Login ¶ added in v0.5.0
type Login struct {
// The minted token. Reported this once and never again.
Credential string
// The principal the token is bound to.
Principal string
// The time the token stops authenticating.
ExpiresAt time.Time
}
The Login type is the client-side view of a successful login: the short-lived credential a verified identity was exchanged for.
type Node ¶ added in v0.8.0
type Node struct {
// The host's name.
Hostname string
// The operating system the binary was built for.
OS string
// The processor architecture the binary was built for.
Arch string
// The kernel release.
Kernel string
// How many processors the host has.
CPUs int
// The version of the takt binary serving the request, which is what a
// client checks before relying on something newer than the server.
Version string
// When the server process started.
StartedAt time.Time
// When the host booted.
BootedAt time.Time
// The host's memory.
Memory NodeMemory
// The host's load averages.
Load NodeLoad
// The filesystems takt writes to.
Disks NodeDisks
// What takt's running instances are permitted between them, read
// against the capacity above to answer whether another workload fits.
Allocated NodeAllocation
}
The Node type is the client-side view of the machine the server runs on: what it is, and what it has.
The capacity figures are the host's. Memory in use and the load averages describe everything on the box, rather than what takt's workloads consume, which each instance reports for itself.
type NodeAllocation ¶ added in v0.8.0
type NodeAllocation struct {
// The memory the running instances may use between them, in bytes.
Memory int
// The processors the running instances may use between them.
CPU float64
// How many running instances name no memory limit.
UnlimitedMemory int
// How many running instances name no processor limit.
UnlimitedCPU int
}
The NodeAllocation type sums the limits every running instance is held to. An instance naming no limit is bounded only by the host and adds nothing to the sum, so it is counted instead.
type NodeDisk ¶ added in v0.8.0
type NodeDisk struct {
// The directory the figures describe, as configured. Reported even when
// the directory has not been created yet.
Path string
// The size of the filesystem.
Total int
// How much of it an unprivileged writer can still use.
Free int
}
The NodeDisk type describes the filesystem under a directory, in bytes.
type NodeDisks ¶ added in v0.8.0
type NodeDisks struct {
// The filesystem under the data directory.
Data NodeDisk
// The filesystem under the volumes directory.
Volumes NodeDisk
}
The NodeDisks type describes the filesystems under the directories takt writes to. Both describe one filesystem unless the operator mounted something at the volumes directory.
type NodeLoad ¶ added in v0.8.0
type NodeLoad struct {
// The load averaged over the last minute.
One float64
// The load averaged over the last five minutes.
Five float64
// The load averaged over the last fifteen minutes.
Fifteen float64
}
The NodeLoad type carries the host's load averages.
type NodeMemory ¶ added in v0.8.0
type NodeMemory struct {
// How much memory the host has.
Total int
// How much of it is in use. This is the total less what the kernel
// reports as available, so the page cache it reclaims before refusing
// an allocation is not counted as spent.
Used int
}
The NodeMemory type describes the host's memory, in bytes.
type OIDC ¶ added in v0.5.0
type OIDC struct {
// The issuer the flow runs against.
Issuer string
// The client identifier registered with the issuer.
ClientID string
}
The OIDC type is the client-side view of the server's OIDC configuration, which is what a login needs to run the authorization code flow.
type Option ¶
type Option func(*config)
The Option type is a function that modifies how New builds a Client.
func WithCACertificate ¶
WithCACertificate makes the client check the server's certificate against the PEM certificate authority file at the given path instead of the system roots. This is how a client trusts a server with a self-signed certificate without giving up verification altogether.
func WithToken ¶ added in v0.5.0
WithToken makes the client present the given token as a bearer credential on every request, which is what a server with authentication enabled requires.
func WithoutCredential ¶ added in v0.6.0
func WithoutCredential() Option
WithoutCredential makes the client present no credential, whatever the settings it was built from hold. The login command is the reason it exists: logging in mints a replacement for the stored token, and a server refuses any credential that does not authenticate — so presenting an expired token would fail the very login meant to replace it.
type Policy ¶ added in v0.9.0
type Policy struct {
// The canonical current document. Before any apply it is the empty
// document: version v1, no grants, which grants nothing to anyone.
Spec manifest.Policy
// The entity tag identifying this version of the document, exactly as
// the ETag header carried it, which ApplyPolicy presents back.
ETag string
}
The Policy type is the client-side view of the policy: the document the server holds, together with the tag a conditional apply hands back.
The document is nested rather than flattened so that what this carries beside it can never be mistaken for part of it. A file an operator keeps holds only the Spec.
type Readiness ¶
type Readiness struct {
// Whether the database and every configured driver answered.
Ready bool
// Why the server is not ready. Empty when it is.
Reasons []string
}
The Readiness type is the client-side view of whether the server can do its job.
type Rekey ¶
type Rekey struct {
// How many secrets were re-encrypted.
Secrets int
// The key the server's secrets are now sealed under.
KeyID string
// The key they were sealed under before. The server's keyring keeps it,
// because it still opens the backups taken before the rekey.
PreviousKeyID string
}
The Rekey type is the client-side view of a completed rekey.
type ResolvedPort ¶
type ResolvedPort struct {
// The index of the workload instance the port reaches. Zero for a
// workload running one instance.
Instance int
// What the specification called the port, which is how the rest of a
// manifest refers to it. Empty for a port the specification did not name.
Name string
// The port the workload listens on inside its runtime.
To int
// The host port that reaches it.
From int
// The transport protocol the port is published on, which is either tcp or
// udp. The two are separate address spaces, so it is part of the address
// rather than a detail of it.
Protocol string
// Whether the host port was allocated by the server rather than pinned by
// the specification.
Dynamic bool
}
The ResolvedPort type is a port mapping as the server applied it.
type Secret ¶
type Secret struct {
// The name that identifies the secret, and which a manifest references.
Name string
// Changes whenever the secret's value changes, and never otherwise.
//
// Useful for confirming a rotation landed. It says nothing about the value.
Revision string
// The names of the workloads whose specifications reference this secret. Empty
// for a secret nothing reads, which is one that can be deleted without
// forcing.
UsedBy []string
// Arbitrary key-value pairs attached to the secret.
Labels map[string]string
// The entity tag identifying this version of the secret, which a conditional
// set hands back in WithIfMatch. Empty on one read from a list, which reports
// no tag per item. Unlike the revision it moves on a relabel too.
ETag string
// The time the secret was created.
CreatedAt time.Time
// The time the secret last changed, by its value or its labels. The revision
// is what says the value moved.
UpdatedAt time.Time
}
The Secret type is the client-side view of a secret: a value a workload can read and an operator cannot.
There is no value on it. Nothing reads a secret back out of takt, so there is nothing for this type to carry.
type Service ¶
type Service struct {
// The name that identifies the service.
Name string
// Arbitrary key-value pairs attached to the service.
Labels map[string]string
// Which workload instances the service selects, and which of their
// ports it addresses.
Target manifest.ServiceTarget
// The selected instances that are fit to serve when the response was
// written. Empty when nothing selected is fit to serve.
Backends []ServiceBackend
// The entity tag identifying this version of the service, which a conditional
// apply hands back in WithIfMatch. Empty on one read from a list, which
// reports no tag per item.
ETag string
// The time the service was created.
CreatedAt time.Time
// The time the service was last modified.
UpdatedAt time.Time
}
The Service type is the client-side view of a service: a named selection of workload instances to balance requests across.
type ServiceBackend ¶
type ServiceBackend struct {
// The name of the workload the instance belongs to.
Workload string
// The index of the instance among the workload's instances.
Instance int
// The host address that reaches the instance's target port, as
// "host:port".
Address string
}
The ServiceBackend type is one address a service balances requests across.
type Token ¶ added in v0.5.0
type Token struct {
// The identifier the server assigns, which a delete names.
ID string
// Whether this is the recovery token or a client token.
Type string
// What minted the token: "init", "static", "oidc" or "session".
Source string
// The principal the token authenticates as. Empty for the recovery
// token.
Principal string
// The time the token stops authenticating. Zero when it does not
// expire.
ExpiresAt time.Time
// The time the token was created.
CreatedAt time.Time
// The time the token last authenticated a request. Zero when it never
// has.
LastUsedAt time.Time
// The workload the server minted the token for. Empty for a token not
// minted for one.
Workload string
// The instance the token was minted for, when one instance holds it in
// its environment. Nil for a token every instance of the workload
// shares, and for a token not minted for a workload.
Instance *int
// The workload version the token was minted for, when every instance
// of that version shares it from a file. Nil for an instance's own
// token, and for a token not minted for a workload.
Version *int
}
The Token type is the client-side view of a credential's record. The credential itself is reported once, by the create that minted it, and never again.
type Usage ¶ added in v0.7.0
type Usage struct {
// The memory the instance is using, in bytes.
Memory int
// The memory the instance may use, in bytes.
MemoryLimit *int
// The processors the instance is using, averaged since the reading before
// it. Nil until a second reading has been taken, since a rate needs a pair.
CPU *float64
// The processors the instance may use.
CPULimit *float64
// The processes and threads the instance is running.
Pids int
// The processes and threads the instance may run.
PidsLimit *int
}
The Usage type is the client-side view of what an instance is consuming.
A limit is nil when the specification named none, which leaves the instance bounded by the host rather than by a figure anything could print.
type Variable ¶
type Variable struct {
// The name that identifies the variable, and which a manifest references.
Name string
// The value the variable holds.
Value string
// The names of the workloads whose specifications reference this variable.
// Empty for a variable nothing reads, which is one that can be deleted without
// forcing.
UsedBy []string
// Arbitrary key-value pairs attached to the variable.
Labels map[string]string
// The entity tag identifying this version of the variable, which a
// conditional set hands back in WithIfMatch. Empty on one read from a list,
// which reports no tag per item.
ETag string
// The time the variable was created.
CreatedAt time.Time
// The time the variable last changed, by its value or its labels.
UpdatedAt time.Time
}
The Variable type is the client-side view of a variable: a value both a workload and an operator can read.
The value is on it, unlike a Secret. That is the whole difference between the two, and it is why anything worth hiding belongs in a secret instead.
type Volume ¶
type Volume struct {
// The name that identifies the volume.
Name string
// Where the volume's data is on the host running the server, which is what
// something taking a backup needs.
Path string
// The names of the workloads whose specifications mount this volume. Empty for a
// volume nothing is using, which is one that can be deleted without forcing.
UsedBy []string
// Arbitrary key-value pairs attached to the volume.
Labels map[string]string
// Who owns the volume's directory, as a numeric "uid" or "uid:gid". Empty
// when the directory is owned by the user running the server.
Owner string
// The permission bits on the volume's directory, as an octal string. Empty
// when the directory keeps the server's default.
Mode string
// The entity tag identifying this version of the volume, which a conditional
// apply hands back in WithIfMatch. Empty on one read from a list, which
// reports no tag per item.
ETag string
// The time the volume was created.
CreatedAt time.Time
}
The Volume type is the client-side view of a volume: storage a workload mounts, with a lifetime of its own.
type Workload ¶
type Workload struct {
// The name that identifies the workload.
Name string
// Incremented every time the workload's specification changes.
Version int
// Which runtime the specification names.
Runtime manifest.Runtime
// The workload's overall state, derived from its instances.
State WorkloadState
// Whether the workload is being torn down and will shortly disappear.
Deleting bool
// Whether the workload has been stopped and is intentionally not running.
Suspended bool
// Whether the server's last check of the workload's tag found it resolving
// to a digest other than the one its instances were hashed with. Only ever
// set for a pull-always workload on a server that checks digests.
ImageDrifted bool
// The specification that was submitted.
Spec manifest.Spec
// The port mappings the server settled on, including any it allocated. These
// are how the workload is reached.
Ports []ResolvedPort
// The instances the server is currently running for the workload.
Instances []Instance
// The entity tag identifying this version of the workload, which a conditional
// apply hands back in WithIfMatch. Empty on one read from a list, which
// reports no tag per item.
ETag string
// The time the workload was first applied.
CreatedAt time.Time
// The time the workload's specification last changed.
UpdatedAt time.Time
// When the workload next runs, for one that names a schedule. Zero for a
// workload that runs continuously.
NextRun time.Time
}
The Workload type is the client-side view of a workload: the desired state that was submitted, together with what the server reports is running for it.
type WorkloadState ¶
type WorkloadState string
The WorkloadState type describes the overall state of a workload, derived by the server from the instances it is running.
const ( // WorkloadStatePending indicates nothing is running for the workload yet, either // because it has just been applied or because it is waiting to be restarted. WorkloadStatePending WorkloadState = "pending" // WorkloadStateRunning indicates the workload's instances are up. WorkloadStateRunning WorkloadState = "running" // WorkloadStateDegraded indicates the workload has at least one instance up and // at least one failed. It serves traffic, and part of it does not work. WorkloadStateDegraded WorkloadState = "degraded" // WorkloadStateTerminating indicates the workload is being torn down and will // shortly disappear. WorkloadStateTerminating WorkloadState = "terminating" // WorkloadStateStopped indicates the workload's instances have all ended without // failing, and the server intends to restart them. WorkloadStateStopped WorkloadState = "stopped" // WorkloadStateCompleted indicates the workload ended cleanly and nothing will // restart it. Unlike stopped, this is the desired end state. A scheduled // workload reads as completed between occurrences, and NextRun says when it // runs again. WorkloadStateCompleted WorkloadState = "completed" // WorkloadStateFailed indicates the workload is not working, whether because an // instance failed or because it is not passing its health check. WorkloadStateFailed WorkloadState = "failed" // WorkloadStateSuspended indicates the workload was stopped by an operator and // stays down until it is started again. Unlike stopped, the server does not // intend to fix it. WorkloadStateSuspended WorkloadState = "suspended" )