Documentation
¶
Overview ¶
Package api implements the REST handlers for environment-scoped resources (ADR-0006): /api/v1/environments and /api/v1/environments/{env}/...
Index ¶
- Constants
- func EnvFrom(ctx context.Context) *environment.Environment
- func Namespace(r *http.Request) (string, error)
- func ReadOnlyReason(st runtime.NerdctlStatus) string
- type BulkActionRequest
- type BulkActionResult
- type CheckImageUpdatesRequest
- type CreateContainerRequest
- type Environment
- type EnvironmentStatus
- type EventHistory
- type ExecExit
- type Features
- type Handler
- type HistoryEvent
- type ImageUpdateSettings
- type ImageUpdates
- type JobFrame
- type NamespaceSpec
- type PrometheusCheck
- type PrometheusSettings
- type PrometheusSettingsInput
- type RecreateContainerRequest
- type RemoveImagesResult
- type Settings
- type StackLogLine
- type StackOperationRequest
- type StackValidation
- type SummaryResponse
- type TopContainer
- type TopStats
Constants ¶
const ( StatusConnected = "connected" )
Environment statuses.
Variables ¶
This section is empty.
Functions ¶
func EnvFrom ¶
func EnvFrom(ctx context.Context) *environment.Environment
EnvFrom returns the environment resolved from the {env} path parameter.
func Namespace ¶
Namespace returns the containerd namespace for the request: the "namespace" query parameter, or the environment's default. Invalid names are rejected (ADR-0006).
func ReadOnlyReason ¶
func ReadOnlyReason(st runtime.NerdctlStatus) string
ReadOnlyReason explains why an environment is read-only.
Types ¶
type BulkActionRequest ¶
type BulkActionRequest struct {
Action runtime.Action `json:"action"`
IDs []string `json:"ids"`
Force bool `json:"force,omitempty"`
Volumes bool `json:"volumes,omitempty"`
}
BulkActionRequest is the body of POST /containers/actions. Keep in sync with api/openapi.yaml.
type BulkActionResult ¶
type BulkActionResult struct {
ID string `json:"id"`
OK bool `json:"ok"`
Error *httpjson.ErrorDetail `json:"error,omitempty"`
}
BulkActionResult is the outcome for one container.
type CheckImageUpdatesRequest ¶ added in v0.1.1
type CheckImageUpdatesRequest struct {
Ref string `json:"ref,omitempty"`
}
CheckImageUpdatesRequest checks one reference, or all used ones when empty.
type CreateContainerRequest ¶
type CreateContainerRequest struct {
runtime.CreateSpec
// Start runs the container after creating it (like `nerdctl run -d`).
Start bool `json:"start"`
}
CreateContainerRequest is the body of POST /containers. Keep in sync with api/openapi.yaml.
type Environment ¶
type Environment struct {
ID string `json:"id"`
Name string `json:"name"`
Kind string `json:"kind"`
DefaultNamespace string `json:"defaultNamespace"`
}
Environment is the API representation. Keep in sync with api/openapi.yaml.
type EnvironmentStatus ¶
type EnvironmentStatus struct {
Environment
Status string `json:"status"` // connected | unavailable
Error string `json:"error,omitempty"`
Runtime *runtime.Versions `json:"runtime,omitempty"`
// Features reports server settings the UI adapts to.
Features Features `json:"features"`
}
EnvironmentStatus adds live connectivity information.
type EventHistory ¶
type EventHistory interface {
ListEvents(ctx context.Context, arg db.ListEventsParams) ([]db.Event, error)
}
EventHistory reads recorded events (#65, ADR-0021); *db.Queries implements it.
type ExecExit ¶
type ExecExit struct {
ExitCode int `json:"exitCode"`
}
ExecExit is the last data message of a terminal session.
type Features ¶
type Features struct {
// Exec is false when the web terminal is disabled (--disable-exec).
Exec bool `json:"exec"`
// MetricsHistory is true when a Prometheus connection is configured (#176).
MetricsHistory bool `json:"metricsHistory"`
}
Features of the server for an environment.
type Handler ¶
type Handler struct {
Envs *environment.Registry
Jobs *jobs.Manager
// EventHistory serves the event feed (#65); nil when recording is disabled.
EventHistory EventHistory
// ExecDisabled turns off the web terminal (--disable-exec, #15).
ExecDisabled bool
// Settings stores per-environment settings such as the Prometheus connection (#176);
// nil disables them.
Settings Settings
// Stacks finds compose stacks (#24, ADR-0008); nil disables them.
Stacks *stacks.Service
// ImageUpdates checks images for newer registry digests (#53); nil disables it.
ImageUpdates ImageUpdates
// PrometheusHTTP is the HTTP client for Prometheus; nil uses a default with a timeout.
PrometheusHTTP *http.Client
Logger *slog.Logger
}
Handler serves environment endpoints.
type HistoryEvent ¶
type HistoryEvent struct {
ID int64 `json:"id"`
Timestamp time.Time `json:"ts"`
Namespace string `json:"namespace,omitempty"`
Topic string `json:"topic"`
Kind string `json:"kind"`
Action string `json:"action"`
ObjectID string `json:"objectId,omitempty"`
ObjectName string `json:"objectName,omitempty"`
Attributes map[string]string `json:"attributes,omitempty"`
}
HistoryEvent is a recorded event. Keep in sync with api/openapi.yaml.
type ImageUpdateSettings ¶ added in v0.1.1
type ImageUpdateSettings struct {
// IntervalSeconds is 0 (off), 3600, 21600, 43200 or 86400.
IntervalSeconds int64 `json:"intervalSeconds"`
}
ImageUpdateSettings is the schedule of an environment's checks.
type ImageUpdates ¶ added in v0.1.1
type ImageUpdates interface {
Overview(ctx context.Context, env *environment.Environment, ns string) (updates.Overview, error)
Check(ctx context.Context, env *environment.Environment, ref string) (updates.Report, error)
Interval(ctx context.Context, env string) (time.Duration, error)
SetInterval(ctx context.Context, env string, d time.Duration) error
}
ImageUpdates checks images for newer registry digests (#53, ADR-0030); *updates.Checker implements it.
type JobFrame ¶
type JobFrame struct {
Job *jobs.Job `json:"job,omitempty"`
Output string `json:"output,omitempty"`
Reset bool `json:"reset,omitempty"`
}
JobFrame is a data message of a job stream: the job state and/or terminal output. The first frame carries the job and the stored output with reset set.
type NamespaceSpec ¶
type NamespaceSpec struct {
Name string `json:"name"`
}
NamespaceSpec creates a namespace (#195).
type PrometheusCheck ¶
type PrometheusCheck struct {
Version string `json:"version,omitempty"`
// Containers is the number of containers with containerd CPU metrics in Prometheus.
Containers int `json:"containers"`
}
PrometheusCheck is the result of testing a connection.
type PrometheusSettings ¶
type PrometheusSettings struct {
Configured bool `json:"configured"`
URL string `json:"url,omitempty"`
Auth string `json:"auth,omitempty"`
Username string `json:"username,omitempty"`
HasSecret bool `json:"hasSecret"`
}
PrometheusSettings is the API view of an environment's Prometheus connection (#176): the secret is write-only. Keep in sync with api/openapi.yaml.
type PrometheusSettingsInput ¶
type PrometheusSettingsInput struct {
URL string `json:"url"`
Auth string `json:"auth"`
Username string `json:"username"`
Secret string `json:"secret"`
}
PrometheusSettingsInput sets the connection. An empty secret keeps the stored one when the authentication mode is unchanged.
type RecreateContainerRequest ¶ added in v0.1.1
type RecreateContainerRequest struct {
runtime.CreateSpec
// Pull pulls the image first: an update to the tag's newest image.
Pull bool `json:"pull"`
}
RecreateContainerRequest replaces a container (#18). Keep in sync with api/openapi.yaml.
type RemoveImagesResult ¶
type RemoveImagesResult struct {
Reference string `json:"reference"`
OK bool `json:"ok"`
Error *httpjson.ErrorDetail `json:"error,omitempty"`
}
RemoveImagesResult reports the removal of one reference. Keep in sync with api/openapi.yaml.
type Settings ¶
type Settings interface {
GetSetting(ctx context.Context, key string) (string, error)
SetSetting(ctx context.Context, arg db.SetSettingParams) error
DeleteSetting(ctx context.Context, key string) (int64, error)
}
Settings stores key/value settings; *db.Queries of the write connection implements it.
type StackLogLine ¶
type StackLogLine struct {
Service string `json:"service"`
Container string `json:"container,omitempty"`
ContainerID string `json:"containerId"`
runtime.LogLine
}
StackLogLine is a log line of a stack's container (#30). Keep in sync with api/openapi.yaml.
type StackOperationRequest ¶
type StackOperationRequest struct {
runtime.ComposeOptions
Confirm string `json:"confirm,omitempty"`
}
StackOperationRequest modifies a stack operation. Confirm must repeat the stack name when Volumes is set: `down -v` deletes the project's volumes.
type StackValidation ¶
type StackValidation struct {
Valid bool `json:"valid"`
Error string `json:"error,omitempty"`
Line int `json:"line,omitempty"`
Services []string `json:"services"`
}
StackValidation is the result of checking compose and .env content (#26). Line is the line of the error in the compose file when the loader reports it. Keep in sync with api/openapi.yaml.
type SummaryResponse ¶
type SummaryResponse struct {
runtime.Summary
// Stacks counts stacks with known files and compose projects seen in container labels.
Stacks int `json:"stacks"`
}
SummaryResponse is the dashboard of a host (#63). Keep in sync with api/openapi.yaml.
type TopContainer ¶
type TopContainer struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Namespace string `json:"namespace"`
CPUPercent float64 `json:"cpuPercent"`
MemoryUsage uint64 `json:"memoryUsage"`
MemoryPercent float64 `json:"memoryPercent"`
}
TopContainer is a running container's latest sample (#63).
type TopStats ¶
type TopStats struct {
Time time.Time `json:"ts"`
Running int `json:"running"`
CPU []TopContainer `json:"cpu"`
Memory []TopContainer `json:"memory"`
}
TopStats is one message of the top stream.
Source Files
¶
- container_actions.go
- container_create.go
- container_exec.go
- container_logs.go
- container_stats.go
- containers.go
- environments.go
- event_history.go
- events.go
- image_updates.go
- images.go
- jobs.go
- metrics_history.go
- namespaces.go
- networks.go
- ports.go
- prune.go
- registries.go
- stack_files.go
- stack_logs.go
- stacks.go
- summary.go
- volumes.go