runtime

package
v3.10.7 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package runtime is a service runtime manager

Package runtime is a service runtime manager

Index

Constants

View Source
const (
	// EventTopic the events are published to
	EventTopic = "runtime"

	// EventServiceCreated is the topic events are published to when a service is created
	EventServiceCreated = "service.created"
	// EventServiceUpdated is the topic events are published to when a service is updated
	EventServiceUpdated = "service.updated"
	// EventServiceDeleted is the topic events are published to when a service is deleted
	EventServiceDeleted       = "service.deleted"
	EventNamespaceCreated     = "namespace.created"
	EventNamespaceDeleted     = "namespace.deleted"
	EventNetworkPolicyCreated = "networkpolicy.created"
	EventNetworkPolicyUpdated = "networkpolicy.updated"
	EventNetworkPolicyDeleted = "networkpolicy.deleted"
	EventResourceQuotaCreated = "resourcequota.created"
	EventResourceQuotaUpdated = "resourcequota.updated"
	EventResourceQuotaDeleted = "resourcequota.deleted"
)
View Source
const (
	TypeNamespace     = "namespace"
	TypeNetworkPolicy = "networkpolicy"
	TypeResourceQuota = "resourcequota"
	TypeService       = "service"
)

Variables

View Source
var (
	// DefaultRuntime implementation
	DefaultRuntime Runtime

	ErrAlreadyExists   = errors.New("already exists")
	ErrInvalidResource = errors.New("invalid resource")
	ErrNotFound        = errors.New("not found")
)

Functions

func Create

func Create(resource Resource, opts ...CreateOption) error

Create a resource

func Delete

func Delete(resource Resource, opts ...DeleteOption) error

Delete a resource

func Update

func Update(resource Resource, opts ...UpdateOption) error

Update the resource in place

Types

type CreateOption

type CreateOption func(o *CreateOptions)

func CreateContext

func CreateContext(ctx context.Context) CreateOption

CreateContext sets the context

func CreateEntrypoint

func CreateEntrypoint(e string) CreateOption

CreateEntrypoint sets the entrypoint

func CreateImage

func CreateImage(img string) CreateOption

CreateImage sets the image to use

func CreateInstances

func CreateInstances(v int) CreateOption

CreateInstances sets the number of instances

func CreateNamespace

func CreateNamespace(ns string) CreateOption

CreateNamespace sets the namespace

func CreateType

func CreateType(t string) CreateOption

CreateType sets the type of service to create

func ResourceLimits

func ResourceLimits(r *Resources) CreateOption

ResourceLimits sets the resources for the service to use

func WithArgs

func WithArgs(args ...string) CreateOption

WithArgs specifies the command to execute

func WithCommand

func WithCommand(cmd ...string) CreateOption

WithCommand specifies the command to execute

func WithEnv

func WithEnv(env []string) CreateOption

WithEnv sets the created service environment

func WithForce

func WithForce(f bool) CreateOption

WithForce sets the sign to force restart the service

func WithOutput

func WithOutput(out io.Writer) CreateOption

WithOutput sets the arg output

func WithPort

func WithPort(p string) CreateOption

WithPort sets the port to expose

func WithRetries

func WithRetries(retries int) CreateOption

WithRetries sets the max retries attemps

func WithSecret

func WithSecret(key, value string) CreateOption

WithSecret sets a secret to provide the service with

func WithServiceAccount

func WithServiceAccount(s string) CreateOption

WithServiceAccount sets the ServiceAccount

func WithVolume

func WithVolume(name, path string) CreateOption

WithVolume adds a volume to be mounted

type CreateOptions

type CreateOptions struct {
	// Command to execut
	Command []string
	// Args to pass into command
	Args []string
	// Environment to configure
	Env []string
	// Entrypoint within the folder (e.g. in the case of a mono-repo)
	Entrypoint string
	// Log output
	Output io.Writer
	// Type of service to create
	Type string
	// Retries before failing deploy
	Retries int
	// Specify the image to use
	Image string
	// Port to expose
	Port string
	// Namespace to create the service in
	Namespace string
	// Specify the context to use
	Context context.Context
	// Secrets to use
	Secrets map[string]string
	// Resources to allocate the service
	Resources *Resources
	// Volumes to mount
	Volumes map[string]string
	// ServiceAccount to start the container with
	ServiceAccount string
	// Number of instances to run
	Instances int
	// Force the service ignore the service status
	Force bool
}

CreateOptions configure runtime services

type DeleteOption

type DeleteOption func(o *DeleteOptions)

func DeleteContext

func DeleteContext(ctx context.Context) DeleteOption

DeleteContext sets the context

func DeleteNamespace

func DeleteNamespace(ns string) DeleteOption

DeleteNamespace sets the namespace

type DeleteOptions

type DeleteOptions struct {
	// Namespace the service is running in
	Namespace string
	// Specify the context to use
	Context context.Context
}

type Event

type Event struct {
	// ID of the event
	ID string
	// Type is event type
	Type EventType
	// Timestamp is event timestamp
	Timestamp time.Time
	// Service the event relates to
	Service *Service
	// Options to use when processing the event
	Options *CreateOptions
}

Event is notification event

type EventPayload

type EventPayload struct {
	Type      string
	Service   *Service
	Namespace string
}

EventPayload which is published with runtime events

type EventResourcePayload

type EventResourcePayload struct {
	Type          string
	Name          string
	Namespace     string
	NetworkPolicy *NetworkPolicy
	ResourceQuota *ResourceQuota
	Service       *Service
}

EventResourcePayload which is published with runtime resource events

type EventType

type EventType int

EventType defines schedule event

const (
	// CreateEvent is emitted when a new build has been craeted
	CreateEvent EventType = iota
	// UpdateEvent is emitted when a new update become available
	UpdateEvent
	// DeleteEvent is emitted when a build has been deleted
	DeleteEvent
)

func (EventType) String

func (t EventType) String() string

String returns human readable event type

type Log

type Log struct {
	Message  string
	Metadata map[string]string
}

Log is a log message

type LogStream

type LogStream interface {
	Error() error
	Chan() chan Log
	Stop() error
}

LogStream returns a log stream

func Logs

func Logs(resource Resource, opts ...LogsOption) (LogStream, error)

Logs for a resource

type LogsOption

type LogsOption func(o *LogsOptions)

LogsOption configures runtime logging

func LogsContext

func LogsContext(ctx context.Context) LogsOption

LogsContext sets the context

func LogsCount

func LogsCount(count int64) LogsOption

LogsExistingCount confiures how many existing lines to show

func LogsNamespace

func LogsNamespace(ns string) LogsOption

LogsNamespace sets the namespace

func LogsStream

func LogsStream(stream bool) LogsOption

LogsStream configures whether to stream new lines

type LogsOptions

type LogsOptions struct {
	// How many existing lines to show
	Count int64
	// Stream new lines?
	Stream bool
	// Namespace the service is running in
	Namespace string
	// Specify the context to use
	Context context.Context
}

LogsOptions configure runtime logging

type Namespace

type Namespace struct {
	// Name of the namespace
	Name string
}

Namespace represents a logical namespace for organising resources

func NewNamespace

func NewNamespace(name string) (*Namespace, error)

NewNamespace mints a new namespace

func (*Namespace) String

func (r *Namespace) String() string

String implements Resource

func (*Namespace) Type

func (*Namespace) Type() string

Type implements Resource

type NetworkPolicy

type NetworkPolicy struct {
	// The labels allowed ingress by this policy
	AllowedLabels map[string]string
	// Name of the network policy
	Name string
	// Namespace the network policy belongs to
	Namespace string
}

NetworkPolicy represents an ACL of label pairs allowing ignress to a namespace

func NewNetworkPolicy

func NewNetworkPolicy(name, namespace string, allowedLabels map[string]string) (*NetworkPolicy, error)

NewNetworkPolicy mints a new networkpolicy

func (*NetworkPolicy) String

func (r *NetworkPolicy) String() string

String implements Resource

func (*NetworkPolicy) Type

func (*NetworkPolicy) Type() string

Type implements Resource

type Option

type Option func(o *Options)

func WithClient

func WithClient(c client.Client) Option

WithClient sets the client to use

func WithImage

func WithImage(t string) Option

WithImage sets the image to use

func WithSource

func WithSource(src string) Option

WithSource sets the base image / repository

func WithType

func WithType(t string) Option

WithType sets the service type to manage

type Options

type Options struct {
	// Service type to manage
	Type string
	// Client to use when making requests
	Client client.Client
	// Base image to use
	Image string
	// Source of the services repository
	Source string
	// Context to store additional options
	Context context.Context
}

Options configure runtime

type ReadOption

type ReadOption func(o *ReadOptions)

func ReadContext

func ReadContext(ctx context.Context) ReadOption

ReadContext sets the context

func ReadNamespace

func ReadNamespace(ns string) ReadOption

ReadNamespace sets the namespace

func ReadService

func ReadService(service string) ReadOption

ReadService returns services with the given name

func ReadType

func ReadType(t string) ReadOption

ReadType returns services of the given type

func ReadVersion

func ReadVersion(version string) ReadOption

ReadVersion configures service version

type ReadOptions

type ReadOptions struct {
	// Service name
	Service string
	// Version queries services with given version
	Version string
	// Type of service
	Type string
	// Namespace the service is running in
	Namespace string
	// Specify the context to use
	Context context.Context
}

ReadOptions queries runtime services

type Resource

type Resource interface {
	String() string
	Type() string
}

Resource represents any resource handled by runtime

type ResourceQuota

type ResourceQuota struct {
	// Name of the resource quota
	Name string
	// Namespace the resource quota belongs to
	Namespace string
	// Quota for resource REQUESTS
	Requests *Resources
	// Quota for resource LIMITS
	Limits *Resources
}

ResourceQuota represents an ACL of label pairs allowing ignress to a namespace

func NewResourceQuota

func NewResourceQuota(name, namespace string, requests, limits *Resources) (*ResourceQuota, error)

NewResourceQuota mints a new resourcequota

func (*ResourceQuota) String

func (r *ResourceQuota) String() string

String implements Resource

func (*ResourceQuota) Type

func (*ResourceQuota) Type() string

Type implements Resource

type Resources

type Resources struct {
	// CPU is the maximum amount of CPU the service will be allocated (unit millicpu)
	// e.g. 0.25CPU would be passed as 250
	CPU int
	// Mem is the maximum amount of memory the service will be allocated (unit mebibyte)
	// e.g. 128 MiB of memory would be passed as 128
	Mem int
	// Disk is the maximum amount of disk space the service will be allocated (unit mebibyte)
	// e.g. 128 MiB of memory would be passed as 128
	Disk int
}

Resources which are allocated to a service

type Runtime

type Runtime interface {
	// Init initializes runtime
	Init(...Option) error
	// Create a resource
	Create(Resource, ...CreateOption) error
	// Read a resource
	Read(...ReadOption) ([]*Service, error)
	// Update a resource
	Update(Resource, ...UpdateOption) error
	// Delete a resource
	Delete(Resource, ...DeleteOption) error
	// Logs returns the logs for a resource
	Logs(Resource, ...LogsOption) (LogStream, error)
	// Start starts the runtime
	Start() error
	// Stop shuts down the runtime
	Stop() error
	// String defines the runtime implementation
	String() string
}

Runtime is a service runtime manager

type Service

type Service struct {
	// Name of the service
	Name string
	// Version of the service
	Version string
	// url location of source
	Source string
	// Metadata stores metadata
	Metadata map[string]string
	// Status of the service
	Status ServiceStatus
}

Service represents a Micro service running within a namespace

func NewService

func NewService(name, version string) (*Service, error)

NewService mints a new service

func Read

func Read(opts ...ReadOption) ([]*Service, error)

Read returns the service

func (*Service) String

func (r *Service) String() string

String implements Resource

func (*Service) Type

func (*Service) Type() string

Type implements Resource

type ServiceStatus

type ServiceStatus int

ServiceStatus defines service statuses

const (
	// Unknown indicates the status of the service is not known
	Unknown ServiceStatus = iota
	// Pending is the initial status of a service
	Pending
	// Building is the status when the service is being built
	Building
	// Starting is the status when the service has been started but is not yet ready to accept traffic
	Starting
	// Running is the status when the service is active and accepting traffic
	Running
	// Stopping is the status when a service is stopping
	Stopping
	// Stopped is the status when a service has been stopped or has completed
	Stopped
	// Error is the status when an error occured, this could be a build error or a run error. The error
	// details can be found within the service's metadata
	Error
)

func (ServiceStatus) String

func (s ServiceStatus) String() string

String returns human-readable service status

type UpdateOption

type UpdateOption func(o *UpdateOptions)

func UpdateContext

func UpdateContext(ctx context.Context) UpdateOption

UpdateContext sets the context

func UpdateEntrypoint

func UpdateEntrypoint(e string) UpdateOption

UpdateEntrypoint sets the entrypoint

func UpdateInstances

func UpdateInstances(v int) UpdateOption

UpdateInstances sets the number of instances

func UpdateNamespace

func UpdateNamespace(ns string) UpdateOption

UpdateNamespace sets the namespace

func UpdateSecret

func UpdateSecret(key, value string) UpdateOption

WithSecret sets a secret to provide the service with

type UpdateOptions

type UpdateOptions struct {
	// Entrypoint within the folder (e.g. in the case of a mono-repo)
	Entrypoint string
	// Namespace the service is running in
	Namespace string
	// Specify the context to use
	Context context.Context
	// Secrets to use
	Secrets map[string]string
	// Number of instances
	Instances int
}

Directories

Path Synopsis
Package kubernetes implements kubernetes micro runtime
Package kubernetes implements kubernetes micro runtime
api
client
Package client provides an implementation of a restricted subset of kubernetes API client
Package client provides an implementation of a restricted subset of kubernetes API client
process
Package process executes a binary
Package process executes a binary
process/os
Package os runs processes locally
Package os runs processes locally
test/bar
Package main is used to test the local runtime, specifically the entrypoint function
Package main is used to test the local runtime, specifically the entrypoint function
test/foo/cmd/bar
Package main is used to test the local runtime, specifically the entrypoint function
Package main is used to test the local runtime, specifically the entrypoint function
test/foo/cmd/baz
Package main is used to test the local runtime, specifically the entrypoint function
Package main is used to test the local runtime, specifically the entrypoint function
test/qux/cmd/test
Package main is used to test the local runtime, specifically the entrypoint function
Package main is used to test the local runtime, specifically the entrypoint function
Package source retrieves source code
Package source retrieves source code
git
go
Package golang is a source for Go
Package golang is a source for Go

Jump to

Keyboard shortcuts

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