yeoman

package
v0.0.0-...-22b0e53 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerConfigName = "yeoman.json"
	AppConfigName    = "app.json"
)
View Source
const Missing _error = "missing"

Variables

This section is empty.

Functions

func HTTPClient

func HTTPClient() *http.Client

HTTPClient returns an HTTP client that doesn't share a global transport. The implementation is taken from github.com/hashicorp/go-cleanhttp.

Types

type Config

type Config struct {
	Log                LogConfig          `json:"log,omitempty"`
	ProviderRegistries []ProviderRegistry `json:"providerRegistries"`
	Store              string             `json:"store"`
}

func ParseConfig

func ParseConfig(configPath string) (Config, error)

func ParseConfigForService

func ParseConfigForService(name string) (Config, error)

type ContainerRegistry

type ContainerRegistry struct {
	Name           string
	Path           string
	ServiceAccount string
}

type GPU

type GPU struct {
	Type  string `json:"type"`
	Count int    `json:"count"`
}

type IP

type IP struct {
	Name     string         `json:"name"`
	AddrPort netip.AddrPort `json:"addrPort"`
	InUse    bool           `json:"inUse"`
}

type IPStore

type IPStore interface {
	// GetStaticIPs to be used by newly created VMs.
	GetStaticIPs(context.Context, *slog.Logger) (StaticIPs, error)

	// CreateStaticIP reporting its address and type.
	CreateStaticIP(
		ctx context.Context,
		log *slog.Logger,
		name string,
		ipType IPType,
	) (IP, error)
}

type IPType

type IPType string
const (
	IPInternal IPType = "internal"
	IPExternal IPType = "external"
)

type LogConfig

type LogConfig struct {
	Format LogFormat `json:"format,omitempty"`
	Level  LogLevel  `json:"level,omitempty"`
}

type LogFormat

type LogFormat string
const (
	LogFormatDefault LogFormat = ""
	LogFormatConsole LogFormat = "console"
	LogFormatJSON    LogFormat = "json"
)

type LogLevel

type LogLevel string
const (
	LogLevelDefault LogLevel = ""
	LogLevelDebug   LogLevel = "debug"
	LogLevelInfo    LogLevel = "info"
)

type MockIPStore

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

MockIPStore implements the CloudProvider interface for simplified testing.

func (*MockIPStore) CreateStaticIP

func (m *MockIPStore) CreateStaticIP(
	ctx context.Context,
	name string,
	typ IPType,
) (IP, error)

func (*MockIPStore) GetStaticIPs

func (m *MockIPStore) GetStaticIPs(
	context.Context,
) (StaticIPs, error)

type MockVMStore

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

func (*MockVMStore) Create

func (m *MockVMStore) Create(ctx context.Context, vm *VM) error

func (*MockVMStore) Delete

func (m *MockVMStore) Delete(
	ctx context.Context,
	name string,
) error

func (*MockVMStore) GetAll

func (m *MockVMStore) GetAll(ctx context.Context) ([]*VM, error)

type ProviderRegistry

type ProviderRegistry struct {
	Provider       string `json:"provider"`
	Registry       string `json:"registry"`
	ServiceAccount string `json:"serviceAccount"`
}

type Server

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

Server tracks the state of services, manages autoscaling, and handles starting up and shutting down.

func NewServer

func NewServer(ctx context.Context, opts ServerOpts) (*Server, error)

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Targeted process structure: Server > ProviderRegion > Zone > Service * Server is the root responsible for everything else. * ProviderRegion monitors a single region, e.g. gcp:us-central1. * Zone monitors a single zone, e.g. us-central1-b. * Service represents one or more VMs, e.g. "dashboard".

type ServerOpts

type ServerOpts struct {
	Log                *slog.Logger
	ServiceStore       ServiceStore
	ProviderStores     map[string]IPStore
	ZoneStores         map[string]VMStore
	ProviderRegistries map[string]ContainerRegistry
}

type ServiceOpts

type ServiceOpts struct {
	Name        string    `json:"name"`
	MachineType string    `json:"machineType"`
	DiskSizeGB  int       `json:"diskSizeGB"`
	AllowHTTP   bool      `json:"allowHTTP"`
	StaticIP    bool      `json:"staticIP"`
	Seccomp     string    `json:"seccomp"`
	Count       int       `json:"count"`
	UpdatedAt   time.Time `json:"updatedAt"`
}

ServiceOpts contains the persistant state of a Service, as configured via `yeoman -count $count service create $name`.

type ServiceOptsByName

type ServiceOptsByName []ServiceOpts

func (ServiceOptsByName) Len

func (a ServiceOptsByName) Len() int

func (ServiceOptsByName) Less

func (a ServiceOptsByName) Less(i, j int) bool

func (ServiceOptsByName) Swap

func (a ServiceOptsByName) Swap(i, j int)

type ServiceStore

type ServiceStore interface {
	GetService(ctx context.Context, name string) (ServiceOpts, error)
	GetServices(ctx context.Context) (map[string]ServiceOpts, error)
	SetService(ctx context.Context, opts ServiceOpts) error
	SetServices(ctx context.Context, opts map[string]ServiceOpts) error
	DeleteService(ctx context.Context, name string) error
}

type StaticIPs

type StaticIPs struct {
	Internal []IP
	External []IP
}

type StaticVMIPs

type StaticVMIPs struct {
	Internal IP `json:"internal"`
	External IP `json:"external"`
}

type VM

type VM struct {
	// Name of the VM.
	Name string `json:"name"`

	// MachineType in the cloud provider.
	MachineType string `json:"machineType"`

	// Disk size in GB.
	Disk int `json:"disk"`

	// GPU to attach to the machine.
	GPU *GPU `json:"gpu,omitempty"`

	// Image installed on the disk.
	Image string `json:"image,omitempty"`

	// ContainerImage to be used if configured.
	ContainerImage string `json:"containerImage,omitempty"`

	// Tags on the box applied during creation to indicate the services to
	// be deployed.
	Tags []string `json:"-"`

	// IPs assigned to the box.
	IPs StaticVMIPs `json:"ips,omitempty"`

	// AllowHTTP will disable any cloud-based firewall on ports 80 and 443.
	// This is useful for reverse-proxy boxes that need to be exposed to
	// the public internet.
	AllowHTTP bool `json:"allowHTTP"`

	// Seccomp allows overwriting the default seccomp profile in Docker.
	// This is useful for running headless chromium, among other things.
	Seccomp string `json:"seccomp"`

	// Running is true when the VM is live and false in all other
	// circumstances.
	Running bool `json:"running"`
}

type VMStore

type VMStore interface {
	// GetAllVMs on the cloud provider.
	GetAllVMs(context.Context, *slog.Logger) ([]VM, error)

	// GetVM by name on the cloud provider.
	GetVM(context.Context, *slog.Logger, string) (VM, error)

	// DeleteVM. The implementation should shutdown the VM properly prior
	// to delete and hang until the box is completely deleted.
	DeleteVM(ctx context.Context, log *slog.Logger, name string) error

	// CreateVM. This must hang until boot completes.
	CreateVM(context.Context, *slog.Logger, VM) error

	// RestartVM. Hang until boot completes.
	RestartVM(context.Context, *slog.Logger, VM) error
}

Jump to

Keyboard shortcuts

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