Documentation
¶
Index ¶
- Constants
- Variables
- type APIError
- type ConfigFile
- type ConfigProvider
- type Container
- type ContainerFilter
- type Credential
- type DNSConfig
- type Engine
- func (e *Engine) Close()
- func (e *Engine) HaltAll()
- func (e *Engine) HaltAsync(instID string, done func())
- func (e *Engine) Launch(inst *Instance, creds func([]PullSecret) ([]Credential, error), ...)
- func (e *Engine) Logs(instID, ctrID string, previous bool) (string, error)
- func (e *Engine) Relaunch(inst *Instance, creds func([]PullSecret) ([]Credential, error), ...)
- func (e *Engine) SetPortPool(p gcpserve.PortPool)
- func (e *Engine) SetTiming(t Timer, backoff func(int) time.Duration, p Prober)
- type Handler
- func (h *Handler) ExtractOperation(c *echo.Context) string
- func (h *Handler) ExtractResource(c *echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) Reset()
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) Shutdown(ctx context.Context)
- func (h *Handler) StartWorker(ctx context.Context) error
- func (h *Handler) Trusted() echo.HandlerFunc
- type HealthCheck
- type HealthHeader
- type InMemoryBackend
- func (b *InMemoryBackend) ChangeCompartment(id, ifMatch, compartment string) (string, error)
- func (b *InMemoryBackend) Close()
- func (b *InMemoryBackend) Compartments() []string
- func (b *InMemoryBackend) CreateInstance(in createIn, token string) (instanceWire, string, string, error)
- func (b *InMemoryBackend) DeleteInstance(id, ifMatch string) (string, error)
- func (b *InMemoryBackend) EngineMode() string
- func (b *InMemoryBackend) GetContainer(id string) (containerWire, error)
- func (b *InMemoryBackend) GetInstance(id string) (instanceWire, string, error)
- func (b *InMemoryBackend) GetWorkRequest(id string) (WorkRequestWire, error)
- func (b *InMemoryBackend) ListContainers(f ContainerFilter, o ListOpts) (page.Page[containerSummaryWire], error)
- func (b *InMemoryBackend) ListInstances(f InstanceFilter, o ListOpts) (page.Page[instanceSummaryWire], error)
- func (b *InMemoryBackend) ListShapes(compartment string, o ListOpts) (page.Page[ShapeWire], error)
- func (b *InMemoryBackend) ListWorkRequests(f WorkRequestFilter, o ListOpts) (page.Page[WorkRequestWire], error)
- func (b *InMemoryBackend) Mutate(id string, fn func(*Instance))
- func (b *InMemoryBackend) Now() time.Time
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restart(id, ifMatch string) (string, error)
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) RetrieveLogs(id string, previous bool) (string, error)
- func (b *InMemoryBackend) SetClock(now func() time.Time)
- func (b *InMemoryBackend) SetCompartmentChecker(fn func(string) bool)
- func (b *InMemoryBackend) SetEngine(e *Engine)
- func (b *InMemoryBackend) SetSecretReader(fn SecretReader)
- func (b *InMemoryBackend) SetSubnetChecker(fn func(string) bool)
- func (b *InMemoryBackend) SetTransition(d time.Duration)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) Start(id, ifMatch string) (string, error)
- func (b *InMemoryBackend) Stop(id, ifMatch string) (string, error)
- func (b *InMemoryBackend) Sweep()
- func (b *InMemoryBackend) UpdateContainer(id, ifMatch string, u updateIn) (string, error)
- func (b *InMemoryBackend) UpdateInstance(id, ifMatch string, u updateIn) (string, error)
- func (b *InMemoryBackend) WorkRequestErrors(id string, o ListOpts) (page.Page[wrErrorWire], error)
- func (b *InMemoryBackend) WorkRequestLogs(id string, o ListOpts) (page.Page[wrLogWire], error)
- type Instance
- type InstanceFilter
- type ListOpts
- type Prober
- type Provider
- type PullSecret
- type ResourceConfig
- type Runtime
- type SecretReader
- type Settings
- type ShapeConfig
- type ShapeWire
- type Sink
- type Timer
- type Vnic
- type Volume
- type VolumeMount
- type WorkRequest
- type WorkRequestFilter
- type WorkRequestWire
Constants ¶
const ( EngineState = "state" EngineDocker = "docker" )
Engine modes (--oci-container-instances-engine).
const DefaultPort = 8167
DefaultPort is the dedicated control-plane listener's default TCP port.
const (
// Region is the fixed region baked into emulated OCIDs.
Region = "iad"
)
Variables ¶
var ErrNilAppContext = errors.New("ocicontainerinstances: nil app context")
ErrNilAppContext is returned when Init is called with a nil AppContext.
var ErrSnapshotNull = errors.New("ocicontainerinstances: null entry in snapshot")
ErrSnapshotNull is returned when a snapshot contains a null entry.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError is an OCI error response: HTTP status plus the `code` and `message` body fields.
type ConfigFile ¶
type ConfigFile struct {
FileName string `json:"fileName"`
Data string `json:"data"`
Path string `json:"path,omitempty"`
}
ConfigFile is one file of a CONFIGFILE volume; Data is base64.
type ConfigProvider ¶
type ConfigProvider interface {
GetOCIContainerInstancesSettings() Settings
}
ConfigProvider extracts OCI Container Instances configuration from the AppContext Config.
type Container ¶
type Container struct {
Created time.Time `json:"timeCreated"`
Updated *time.Time `json:"timeUpdated,omitempty"`
Terminated *time.Time `json:"timeTerminated,omitempty"`
ExitCode *int `json:"exitCode,omitempty"`
Resource *ResourceConfig `json:"resourceConfig,omitempty"`
Env map[string]string `json:"environmentVariables,omitempty"`
Freeform map[string]string `json:"freeformTags,omitempty"`
Defined map[string]any `json:"definedTags,omitempty"`
ID string `json:"id"`
DisplayName string `json:"displayName"`
ImageURL string `json:"imageUrl"`
State string `json:"lifecycleState"`
Details string `json:"lifecycleDetails,omitempty"`
WorkingDir string `json:"workingDirectory,omitempty"`
Security json.RawMessage `json:"securityContext,omitempty"`
Command []string `json:"command,omitempty"`
Args []string `json:"arguments,omitempty"`
Mounts []VolumeMount `json:"volumeMounts,omitempty"`
Health []*HealthCheck `json:"healthChecks,omitempty"`
RestartCount int `json:"restartCount"`
NoResourcePrn bool `json:"isResourcePrincipalDisabled"`
}
Container is one container of a container instance.
type ContainerFilter ¶
type ContainerFilter struct {
Compartment string
State string
DisplayName string
InstanceID string
AD string
}
ContainerFilter selects containers in a list.
type Credential ¶
Credential is a registry login resolved from an image pull secret.
type DNSConfig ¶
type DNSConfig struct {
Nameservers []string `json:"nameservers,omitempty"`
Searches []string `json:"searches,omitempty"`
Options []string `json:"options,omitempty"`
}
DNSConfig is a container instance DNS configuration.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine runs container instances in the container runtime.
func (*Engine) HaltAsync ¶
HaltAsync stops the instance's containers in the background and then calls done.
func (*Engine) Launch ¶
func (e *Engine) Launch( inst *Instance, creds func([]PullSecret) ([]Credential, error), done func(error), )
Launch (re)creates the instance's containers; done gets nil once every container started, or the failure.
func (*Engine) Logs ¶
Logs returns the container's stdout and stderr, from the previous run when previous is set.
func (*Engine) Relaunch ¶
func (e *Engine) Relaunch(inst *Instance, creds func([]PullSecret) ([]Credential, error), done func(error))
Relaunch stops the instance's containers and starts them again.
func (*Engine) SetPortPool ¶
SetPortPool wires the host port source for health check ports.
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
Port int
EnforceAuth bool
// contains filtered or unexported fields
}
Handler serves OCI Container Instances on its own listener.
func NewHandler ¶
func NewHandler(backend *InMemoryBackend) *Handler
NewHandler creates a Handler; callers override Port and EnforceAuth from Settings.
func (*Handler) ExtractOperation ¶
ExtractOperation returns the operation name for metrics.
func (*Handler) ExtractResource ¶
ExtractResource returns the addressed resource id for metrics.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations lists the supported operations.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns the Echo handler for all OCIContainerInstances requests.
func (*Handler) MatchPriority ¶
MatchPriority is irrelevant because RouteMatcher never matches.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches: OCIContainerInstances runs on its own listener.
func (*Handler) StartWorker ¶
StartWorker binds the dedicated listener synchronously so a port conflict is returned to the caller.
func (*Handler) Trusted ¶
func (h *Handler) Trusted() echo.HandlerFunc
Trusted returns a handler that skips request-signature verification, for the in-process dashboard proxy.
type HealthCheck ¶
type HealthCheck struct {
LastChecked *time.Time `json:"lastChecked,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type"`
Path string `json:"path,omitempty"`
Status string `json:"status"`
StatusDetails string `json:"statusDetails,omitempty"`
FailureAction string `json:"failureAction"`
Headers []HealthHeader `json:"headers,omitempty"`
Port int `json:"port"`
InitialDelay int `json:"initialDelayInSeconds"`
Interval int `json:"intervalInSeconds"`
FailureThresh int `json:"failureThreshold"`
SuccessThresh int `json:"successThreshold"`
Timeout int `json:"timeoutInSeconds"`
}
HealthCheck is a container health check and its observed status.
type HealthHeader ¶
HealthHeader is an HTTP health check header.
type InMemoryBackend ¶
InMemoryBackend holds every container instance and work request under one lock.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend creates an empty backend running in state-only mode.
func (*InMemoryBackend) ChangeCompartment ¶
func (b *InMemoryBackend) ChangeCompartment(id, ifMatch, compartment string) (string, error)
ChangeCompartment moves the instance to another compartment.
func (*InMemoryBackend) Close ¶
func (b *InMemoryBackend) Close()
Close stops every running container.
func (*InMemoryBackend) Compartments ¶
func (b *InMemoryBackend) Compartments() []string
Compartments lists the distinct compartments that hold container instances.
func (*InMemoryBackend) CreateInstance ¶
func (b *InMemoryBackend) CreateInstance(in createIn, token string) (instanceWire, string, string, error)
CreateInstance registers a container instance and starts its work request.
func (*InMemoryBackend) DeleteInstance ¶
func (b *InMemoryBackend) DeleteInstance(id, ifMatch string) (string, error)
DeleteInstance deletes a container instance.
func (*InMemoryBackend) EngineMode ¶
func (b *InMemoryBackend) EngineMode() string
EngineMode reports the active engine: EngineDocker or EngineState.
func (*InMemoryBackend) GetContainer ¶
func (b *InMemoryBackend) GetContainer(id string) (containerWire, error)
GetContainer returns one container.
func (*InMemoryBackend) GetInstance ¶
func (b *InMemoryBackend) GetInstance(id string) (instanceWire, string, error)
GetInstance returns one container instance with its etag.
func (*InMemoryBackend) GetWorkRequest ¶
func (b *InMemoryBackend) GetWorkRequest(id string) (WorkRequestWire, error)
GetWorkRequest returns one work request.
func (*InMemoryBackend) ListContainers ¶
func (b *InMemoryBackend) ListContainers(f ContainerFilter, o ListOpts) (page.Page[containerSummaryWire], error)
ListContainers lists containers of a compartment.
func (*InMemoryBackend) ListInstances ¶
func (b *InMemoryBackend) ListInstances(f InstanceFilter, o ListOpts) (page.Page[instanceSummaryWire], error)
ListInstances lists container instances of a compartment.
func (*InMemoryBackend) ListShapes ¶
ListShapes lists the container instance shapes.
func (*InMemoryBackend) ListWorkRequests ¶
func (b *InMemoryBackend) ListWorkRequests(f WorkRequestFilter, o ListOpts) (page.Page[WorkRequestWire], error)
ListWorkRequests lists the work requests of a compartment, newest first.
func (*InMemoryBackend) Mutate ¶
func (b *InMemoryBackend) Mutate(id string, fn func(*Instance))
Mutate runs fn on the instance under the write lock (Sink).
func (*InMemoryBackend) Now ¶
func (b *InMemoryBackend) Now() time.Time
Now returns the backend clock (Sink).
func (*InMemoryBackend) Reset ¶
func (b *InMemoryBackend) Reset()
Reset clears all state and stops every running container.
func (*InMemoryBackend) Restart ¶
func (b *InMemoryBackend) Restart(id, ifMatch string) (string, error)
Restart restarts a running container instance.
func (*InMemoryBackend) Restore ¶
func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
Restore loads backend state. Containers do not survive a restart: instances that were running come back INACTIVE.
func (*InMemoryBackend) RetrieveLogs ¶
func (b *InMemoryBackend) RetrieveLogs(id string, previous bool) (string, error)
RetrieveLogs returns the container's stdout and stderr.
func (*InMemoryBackend) SetClock ¶
func (b *InMemoryBackend) SetClock(now func() time.Time)
SetClock injects the time source used for lifecycle transitions.
func (*InMemoryBackend) SetCompartmentChecker ¶
func (b *InMemoryBackend) SetCompartmentChecker(fn func(string) bool)
SetCompartmentChecker validates compartmentId arguments against another service (OCI Identity).
func (*InMemoryBackend) SetEngine ¶
func (b *InMemoryBackend) SetEngine(e *Engine)
SetEngine switches the backend to docker mode.
func (*InMemoryBackend) SetSecretReader ¶
func (b *InMemoryBackend) SetSecretReader(fn SecretReader)
SetSecretReader resolves VAULT image pull secrets through OCI Vault.
func (*InMemoryBackend) SetSubnetChecker ¶
func (b *InMemoryBackend) SetSubnetChecker(fn func(string) bool)
SetSubnetChecker validates VNIC subnetIds against another service (OCI Core).
func (*InMemoryBackend) SetTransition ¶
func (b *InMemoryBackend) SetTransition(d time.Duration)
SetTransition sets how long asynchronous state-only operations take to complete.
func (*InMemoryBackend) Snapshot ¶
func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
Snapshot serialises the backend state, including registered API keys and image pull secrets.
func (*InMemoryBackend) Start ¶
func (b *InMemoryBackend) Start(id, ifMatch string) (string, error)
Start starts a stopped container instance.
func (*InMemoryBackend) Stop ¶
func (b *InMemoryBackend) Stop(id, ifMatch string) (string, error)
Stop stops a running container instance.
func (*InMemoryBackend) Sweep ¶
func (b *InMemoryBackend) Sweep()
Sweep applies due time-based transitions against the backend clock.
func (*InMemoryBackend) UpdateContainer ¶
func (b *InMemoryBackend) UpdateContainer(id, ifMatch string, u updateIn) (string, error)
UpdateContainer changes a container's display name and tags.
func (*InMemoryBackend) UpdateInstance ¶
func (b *InMemoryBackend) UpdateInstance(id, ifMatch string, u updateIn) (string, error)
UpdateInstance changes the display name and tags.
func (*InMemoryBackend) WorkRequestErrors ¶
WorkRequestErrors lists the errors of a failed work request.
func (*InMemoryBackend) WorkRequestLogs ¶
WorkRequestLogs lists the progress log of a work request, oldest first.
type Instance ¶
type Instance struct {
Created time.Time `json:"timeCreated"`
Updated *time.Time `json:"timeUpdated,omitempty"`
TransitionAt *time.Time `json:"transitionAt,omitempty"`
Graceful *int64 `json:"gracefulShutdownTimeoutInSeconds,omitempty"`
DNS *DNSConfig `json:"dnsConfig,omitempty"`
Freeform map[string]string `json:"freeformTags,omitempty"`
Defined map[string]any `json:"definedTags,omitempty"`
FaultDomain string `json:"faultDomain,omitempty"`
RetryToken string `json:"retryToken,omitempty"`
DisplayName string `json:"displayName"`
Compartment string `json:"compartmentId"`
AD string `json:"availabilityDomain"`
ID string `json:"id"`
State string `json:"lifecycleState"`
Details string `json:"lifecycleDetails,omitempty"`
Shape string `json:"shape"`
Restart string `json:"containerRestartPolicy"`
Etag string `json:"etag"`
Target string `json:"target,omitempty"`
Security json.RawMessage `json:"securityContext,omitempty"`
Containers []*Container `json:"containers"`
Volumes []Volume `json:"volumes,omitempty"`
Vnics []Vnic `json:"vnics"`
PullSecrets []PullSecret `json:"imagePullSecrets,omitempty"`
ShapeConfig ShapeConfig `json:"shapeConfig"`
}
Instance is a container instance.
type InstanceFilter ¶
InstanceFilter selects container instances in a list.
type Prober ¶
type Prober func(ctx context.Context, hc HealthCheck, hostPort int) error
Prober checks one health check against the container's loopback-published port.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for OCI Container Instances. It runs on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.
func (*Provider) Init ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init creates the backend and handler; the port is bound in StartWorker.
type PullSecret ¶
type PullSecret struct {
Type string `json:"type"`
Endpoint string `json:"registryEndpoint"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
SecretID string `json:"secretId,omitempty"`
}
PullSecret is an image pull secret; BASIC credentials never leave the backend.
type ResourceConfig ¶
type ResourceConfig struct {
VcpusLimit *float32 `json:"vcpusLimit,omitempty"`
MemoryLimitInGBs *float32 `json:"memoryLimitInGBs,omitempty"`
}
ResourceConfig caps a container's resources.
type Runtime ¶
type Runtime interface {
// Pull fetches ref when it is absent locally or when cred is set.
Pull(ctx context.Context, ref string, cred *Credential) error
Start(ctx context.Context, spec container.Spec) (string, error)
// Wait blocks until the container exits and returns its exit code.
Wait(ctx context.Context, id string) (int, error)
Logs(ctx context.Context, id string) (string, error)
// Kill stops the container but keeps it, so Wait reports its exit code and logs stay readable.
Kill(ctx context.Context, id string) error
Remove(ctx context.Context, id string) error
}
Runtime is the slice of the container runtime Container Instances need.
func NewDockerRuntime ¶
NewDockerRuntime wraps a pkgs/container runtime.
type SecretReader ¶
SecretReader returns the decoded content of a Vault secret.
type Settings ¶
type Settings struct {
Engine string `` //nolint:lll // config struct tags are intentionally verbose
/* 294-byte string literal not displayed */
Port int `` //nolint:lll // config struct tags are intentionally verbose
/* 231-byte string literal not displayed */
EnforceAuth bool `` //nolint:lll // config struct tags are intentionally verbose
/* 274-byte string literal not displayed */
}
Settings holds service-level configuration, embedded in the root CLI as CLI.OCIContainerInstances.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings returns the settings used when no ConfigProvider is available.
type ShapeConfig ¶
type ShapeConfig struct {
Processor string `json:"processorDescription"`
Ocpus float32 `json:"ocpus"`
Memory float32 `json:"memoryInGBs"`
Bandwidth float32 `json:"networkingBandwidthInGbps"`
}
ShapeConfig is the compute size of an instance.
type ShapeWire ¶
type ShapeWire struct {
Name string `json:"name"`
Processor string `json:"processorDescription"`
Ocpu struct {
Min float32 `json:"min"`
Max float32 `json:"max"`
} `json:"ocpuOptions"`
Memory struct {
MinInGBs float32 `json:"minInGBs"`
MaxInGBs float32 `json:"maxInGBs"`
DefPerOcpu float32 `json:"defaultPerOcpuInGBs"`
MinPerOcpu float32 `json:"minPerOcpuInGBs"`
MaxPerOcpu float32 `json:"maxPerOcpuInGBs"`
} `json:"memoryOptions"`
Bandwidth struct {
Min float32 `json:"minInGbps"`
Max float32 `json:"maxInGbps"`
DefPerOcpu float32 `json:"defaultPerOcpuInGbps"`
} `json:"networkingBandwidthOptions"`
}
ShapeWire is the wire form of a container instance shape.
type Volume ¶
type Volume struct {
Name string `json:"name"`
Type string `json:"type"`
BackingStore string `json:"backingStore,omitempty"`
Configs []ConfigFile `json:"configs,omitempty"`
}
Volume is a container instance volume.
type VolumeMount ¶
type VolumeMount struct {
ReadOnly *bool `json:"isReadOnly,omitempty"`
Partition *int `json:"partition,omitempty"`
MountPath string `json:"mountPath"`
VolumeName string `json:"volumeName"`
SubPath string `json:"subPath,omitempty"`
}
VolumeMount mounts a volume into a container.
type WorkRequest ¶
type WorkRequest struct {
Accepted time.Time `json:"timeAccepted"`
FinishAt *time.Time `json:"finishAt,omitempty"`
FinishedAt *time.Time `json:"timeFinished,omitempty"`
ID string `json:"id"`
Type string `json:"operationType"`
Compartment string `json:"compartmentId"`
ResourceID string `json:"resourceId"`
ResourceType string `json:"resourceType"`
Action string `json:"actionType"`
Status string `json:"status"`
ErrCode string `json:"errorCode,omitempty"`
ErrMsg string `json:"errorMessage,omitempty"`
Seq int64 `json:"seq"`
}
WorkRequest is an asynchronous operation record.
type WorkRequestFilter ¶
type WorkRequestFilter struct {
Compartment string
ID string
Status string
ResourceID string
AD string
}
WorkRequestFilter selects work requests in a list.
type WorkRequestWire ¶
type WorkRequestWire struct {
TimeAccepted time.Time `json:"timeAccepted"`
TimeStarted time.Time `json:"timeStarted"`
TimeFinished *time.Time `json:"timeFinished,omitempty"`
Type string `json:"operationType"`
Status string `json:"status"`
ID string `json:"id"`
Compartment string `json:"compartmentId"`
Resources []wrResourceWire `json:"resources"`
Percent float32 `json:"percentComplete"`
}
WorkRequestWire is the wire form of a work request.