Documentation
¶
Overview ¶
Package instance assembles and runs one emulator instance: state store, gateway, admin API and the selected services.
Index ¶
- Constants
- Variables
- type Abandoned
- type ContainerInfo
- type ExternalStatus
- type Factory
- type Instance
- func (in *Instance) AdminToken() string
- func (in *Instance) AdvanceClock(ctx context.Context, d time.Duration) error
- func (in *Instance) ApplySeed(ctx context.Context, path string) error
- func (in *Instance) ApplySeedData(ctx context.Context, b []byte, base string) error
- func (in *Instance) ConsoleServed() bool
- func (in *Instance) Containers(ctx context.Context) ([]ContainerInfo, error)
- func (in *Instance) DeleteSnapshot(name string) error
- func (in *Instance) Done() <-chan struct{}
- func (in *Instance) EnvVars() map[string]string
- func (in *Instance) ExportSeed(ctx context.Context) ([]byte, error)
- func (in *Instance) External(ctx context.Context) []ExternalStatus
- func (in *Instance) Faults() *fault.Set
- func (in *Instance) FrontendHosts() []string
- func (in *Instance) HoldReady(name, reason string) (release func())
- func (in *Instance) HostMode() hostmode.Status
- func (in *Instance) Operations(service, project string) []emu.OperationInfo
- func (in *Instance) Readiness() map[string]error
- func (in *Instance) Ready() bool
- func (in *Instance) RequestShutdown()
- func (in *Instance) Reset(ctx context.Context) error
- func (in *Instance) RestoreSnapshot(ctx context.Context, name string) error
- func (in *Instance) RuntimeStatus(ctx context.Context) RuntimeStatus
- func (in *Instance) SaveSnapshot(ctx context.Context, name string) (*SnapshotInfo, error)
- func (in *Instance) Services() []emu.Service
- func (in *Instance) Shutdown(ctx context.Context) error
- func (in *Instance) Snapshots() ([]SnapshotInfo, error)
- func (in *Instance) Start(ctx context.Context) error
- func (in *Instance) WaitReady(ctx context.Context) error
- func (in *Instance) WriteCABundle() (string, error)
- type RuntimeStatus
- type SnapshotInfo
Constants ¶
const ( EndpointsFile = "endpoints.json" PIDFile = "gcpemu.pid" LogFile = "gcpemu.log" StateFile = "state.db" IDFile = "instance-id" // AdminTokenFile holds the Admin token while an Instance bound beyond // loopback runs (FR-UI-009); CLI commands read it from there. AdminTokenFile = "admin-token" )
Files written in the instance directory.
const ADCKeyFile = "adc-key.json"
ADCKeyFile is the key file, in the data directory, that `gcpemu env` points GOOGLE_APPLICATION_CREDENTIALS at when gcloud's application-default credentials would otherwise win over the metadata server (ADR 0010).
const SnapshotsDir = "snapshots"
SnapshotsDir is the directory under the instance dir holding State snapshots.
Variables ¶
var ( // ErrSnapshotNotFound is returned for a State snapshot name that was never saved. ErrSnapshotNotFound = errors.New("State snapshot not found") // ErrSnapshotBusy is returned when the Instance cannot be snapshotted // right now: it is not ready, an Operation is running, or its state // kept changing while it was saved. ErrSnapshotBusy = errors.New("Instance busy") // ErrSnapshotName is returned for a name that is not a valid State snapshot name. ErrSnapshotName = errors.New("invalid State snapshot name") )
var Version = "dev"
Version is set at build time.
Functions ¶
This section is empty.
Types ¶
type Abandoned ¶ added in v0.6.0
type Abandoned struct {
ID string
// Unverified: none of its objects records its data dir (LabelDir), so
// only the dirs under StateHome were searched for one holding the ID;
// a --data-dir Instance elsewhere may still own it.
Unverified bool
// Dirs are the data dirs its objects record.
Dirs []string
Containers []runtime.Container
Networks []runtime.Network
Volumes []runtime.Volume
}
Abandoned is an Abandoned Instance ID: one that still tags containers, networks or volumes but that no data dir holds, so no future Instance reclaims them (#192).
func FindAbandoned ¶ added in v0.6.0
FindAbandoned returns the Abandoned Instance IDs on the runtime, sorted. An ID is never Abandoned while any of its containers runs, while a dir its objects record holds it in its instance-id file, or while a dir under stateHome does. A dir that looks missing may be on an unmounted disk or inside a container, so callers confirm before pruning.
type ContainerInfo ¶
type ContainerInfo struct {
Name string `json:"name"`
Service string `json:"service,omitempty"`
Resource string `json:"resource,omitempty"`
Role string `json:"role,omitempty"`
Image string `json:"image"`
State string `json:"state"`
}
ContainerInfo describes one container the instance owns (admin API, `gcpemu status`).
type ExternalStatus ¶ added in v0.12.0
type ExternalStatus struct {
gateway.DelegatedAPI
Reachable bool `json:"reachable"`
Error string `json:"error,omitempty"`
}
ExternalStatus is a Delegated API and whether its External emulator accepts connections.
type Instance ¶
type Instance struct {
Config *config.Config
Env *emu.Env
Log *reqlog.Log
// Events is the change feed served at /_emu/v1/events.
Events *events.Hub
ID string
Dir string
// contains filtered or unexported fields
}
Instance is a running emulator.
func (*Instance) AdminToken ¶ added in v0.6.0
AdminToken returns the Admin token, or "" when the gateway is bound to loopback and none is needed (FR-UI-009).
func (*Instance) AdvanceClock ¶
AdvanceClock moves the emulator clock forward (FR-GCS-008).
func (*Instance) ApplySeed ¶
ApplySeed applies a seed file (FR-CORE-011). Top-level keys are service names; each section is handed to that service's Seeder.
func (*Instance) ApplySeedData ¶ added in v0.6.0
ApplySeedData applies a seed file's contents (an uploaded seed file); relative paths in it resolve against base.
func (*Instance) ConsoleServed ¶ added in v0.6.0
ConsoleServed reports whether the gateway serves the Web console.
func (*Instance) Containers ¶
func (in *Instance) Containers(ctx context.Context) ([]ContainerInfo, error)
Containers lists the instance's containers (see containers.list).
func (*Instance) DeleteSnapshot ¶ added in v0.6.0
DeleteSnapshot removes the State snapshot name.
func (*Instance) Done ¶
func (in *Instance) Done() <-chan struct{}
Done is closed when Shutdown completes.
func (*Instance) EnvVars ¶
EnvVars collects client environment variables from all services, and the Load balancing frontends of the Linked Instances it delegates to.
func (*Instance) ExportSeed ¶ added in v0.6.0
ExportSeed writes the Instance's resources as a seed file (FR-CORE-013): its Projects, every SeedExporter's section in Service start order, and its Fault rules. Applying it to an empty Instance recreates them.
func (*Instance) External ¶ added in v0.12.0
func (in *Instance) External(ctx context.Context) []ExternalStatus
External returns each Delegated API, sorted by API name, with whether its External emulator accepts a TCP connection now. A Managed emulator has no address clients could dial, so none is reported for it.
func (*Instance) FrontendHosts ¶
FrontendHosts returns the real hostnames the Google frontend serves.
func (*Instance) HoldReady ¶
HoldReady keeps the instance not ready, with name and reason reported by Readiness, until release is called. The CLI holds it while the startup seed is applied, so that "ready" means seeded (FR-CI-001).
func (*Instance) Operations ¶ added in v0.2.0
func (in *Instance) Operations(service, project string) []emu.OperationInfo
Operations returns the Operations of every service, or of service and project when they are set, newest first.
func (*Instance) Readiness ¶
Readiness reports each service's readiness, and any readiness holds: nil error means ready.
func (*Instance) RequestShutdown ¶
func (in *Instance) RequestShutdown()
RequestShutdown triggers Shutdown asynchronously (used by the admin API).
func (*Instance) RestoreSnapshot ¶ added in v0.6.0
RestoreSnapshot replaces all of the Instance's state with the State snapshot name: it resets the Instance, loads the snapshot's Store and lets each Snapshotter restore what it saved. Configuration, Fault rules and the Emulator clock, which never goes back, are kept.
func (*Instance) RuntimeStatus ¶ added in v0.2.0
func (in *Instance) RuntimeStatus(ctx context.Context) RuntimeStatus
RuntimeStatus reports the container runtime the instance uses, or would use. It probes without connecting: no orphans are reclaimed until a service needs the runtime.
func (*Instance) SaveSnapshot ¶ added in v0.6.0
SaveSnapshot saves all of the Instance's state as the State snapshot name, replacing one saved under that name before. The Instance must be ready with no Operation running, so that no resource is half made.
func (*Instance) Shutdown ¶
Shutdown stops services in reverse order, closes the store and removes runtime files (FR-CORE-006).
func (*Instance) Snapshots ¶ added in v0.6.0
func (in *Instance) Snapshots() ([]SnapshotInfo, error)
Snapshots lists the saved State snapshots by name.
func (*Instance) Start ¶
Start registers routes, starts the gateway and every service, and writes endpoints.json. A failing service is reported not-ready rather than stopping the others (NFR-REL-003).
func (*Instance) WriteCABundle ¶
WriteCABundle (re)writes <instance-dir>/ca-bundle.pem: the host's system roots plus the instance CA, for SSL_CERT_FILE.
type RuntimeStatus ¶ added in v0.2.0
type RuntimeStatus struct {
Kind string `json:"kind"` // docker, podman or none
Version string `json:"version,omitempty"`
Reachable bool `json:"reachable"`
Error string `json:"error,omitempty"`
}
RuntimeStatus describes the container runtime (admin API /info).
type SnapshotInfo ¶ added in v0.6.0
type SnapshotInfo struct {
Name string `json:"name"`
// CreateTime is the host's wall-clock time of the save, not the Emulator clock.
CreateTime time.Time `json:"createTime"`
// Services are the Services the Instance ran when it was saved.
Services []string `json:"services"`
// SizeBytes is the size of the snapshot's files on disk.
SizeBytes int64 `json:"sizeBytes"`
}
SnapshotInfo describes a saved State snapshot.