2019-09-14 07:33:14 +03:00
|
|
|
// Package runtime is a service runtime manager
|
|
|
|
package runtime
|
|
|
|
|
2020-01-18 05:13:24 +03:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"time"
|
|
|
|
)
|
2019-11-02 16:25:10 +03:00
|
|
|
|
|
|
|
var (
|
2020-01-18 05:13:24 +03:00
|
|
|
ErrAlreadyExists = errors.New("already exists")
|
2019-11-02 16:25:10 +03:00
|
|
|
)
|
|
|
|
|
2019-09-14 07:33:14 +03:00
|
|
|
// Runtime is a service runtime manager
|
|
|
|
type Runtime interface {
|
2019-11-02 16:25:10 +03:00
|
|
|
// Init initializes runtime
|
|
|
|
Init(...Option) error
|
2019-11-15 16:41:40 +03:00
|
|
|
// Create registers a service
|
2019-09-24 20:32:35 +03:00
|
|
|
Create(*Service, ...CreateOption) error
|
2019-11-25 19:31:14 +03:00
|
|
|
// Read returns the service
|
2019-11-29 14:35:00 +03:00
|
|
|
Read(...ReadOption) ([]*Service, error)
|
2019-10-29 15:29:21 +03:00
|
|
|
// Update the service in place
|
2020-04-23 15:53:42 +03:00
|
|
|
Update(*Service, ...UpdateOption) error
|
2019-11-15 16:41:40 +03:00
|
|
|
// Remove a service
|
2020-04-23 15:53:42 +03:00
|
|
|
Delete(*Service, ...DeleteOption) error
|
2020-04-13 01:41:21 +03:00
|
|
|
// Logs returns the logs for a service
|
2020-08-12 00:57:30 +03:00
|
|
|
Logs(*Service, ...LogsOption) (Logs, error)
|
2019-11-15 16:41:40 +03:00
|
|
|
// Start starts the runtime
|
2019-09-14 07:58:03 +03:00
|
|
|
Start() error
|
2019-11-15 16:41:40 +03:00
|
|
|
// Stop shuts down the runtime
|
2019-09-14 07:33:14 +03:00
|
|
|
Stop() error
|
2020-04-13 01:41:21 +03:00
|
|
|
// String describes runtime
|
|
|
|
String() string
|
2020-08-24 18:54:39 +03:00
|
|
|
// CreateNamespace creates a new namespace in the runtime
|
|
|
|
CreateNamespace(string) error
|
|
|
|
// DeleteNamespace deletes a namespace in the runtime
|
|
|
|
DeleteNamespace(string) error
|
2020-04-01 16:40:15 +03:00
|
|
|
}
|
|
|
|
|
2020-08-12 00:57:30 +03:00
|
|
|
// Logs returns a log stream
|
|
|
|
type Logs interface {
|
2020-04-02 01:03:26 +03:00
|
|
|
Error() error
|
2020-08-12 00:57:30 +03:00
|
|
|
Chan() chan Log
|
2020-04-01 16:40:15 +03:00
|
|
|
Stop() error
|
|
|
|
}
|
|
|
|
|
2020-08-12 00:57:30 +03:00
|
|
|
// Log is a log message
|
|
|
|
type Log struct {
|
2020-04-01 16:40:15 +03:00
|
|
|
Message string
|
|
|
|
Metadata map[string]string
|
2019-09-14 07:33:14 +03:00
|
|
|
}
|
|
|
|
|
2020-01-16 16:34:04 +03:00
|
|
|
// Scheduler is a runtime service scheduler
|
|
|
|
type Scheduler interface {
|
|
|
|
// Notify publishes schedule events
|
2019-11-02 16:25:10 +03:00
|
|
|
Notify() (<-chan Event, error)
|
2020-01-16 16:34:04 +03:00
|
|
|
// Close stops the scheduler
|
2019-11-02 16:25:10 +03:00
|
|
|
Close() error
|
2019-09-14 07:33:14 +03:00
|
|
|
}
|
|
|
|
|
2020-01-16 16:34:04 +03:00
|
|
|
// EventType defines schedule event
|
2019-11-02 16:25:10 +03:00
|
|
|
type EventType int
|
2019-09-14 07:58:03 +03:00
|
|
|
|
2019-11-02 16:25:10 +03:00
|
|
|
const (
|
|
|
|
// Create is emitted when a new build has been craeted
|
|
|
|
Create EventType = iota
|
|
|
|
// Update is emitted when a new update become available
|
|
|
|
Update
|
|
|
|
// Delete is emitted when a build has been deleted
|
|
|
|
Delete
|
|
|
|
)
|
2019-10-29 15:29:21 +03:00
|
|
|
|
2019-11-02 16:25:10 +03:00
|
|
|
// String returns human readable event type
|
|
|
|
func (t EventType) String() string {
|
|
|
|
switch t {
|
|
|
|
case Create:
|
|
|
|
return "create"
|
|
|
|
case Delete:
|
|
|
|
return "delete"
|
|
|
|
case Update:
|
|
|
|
return "update"
|
|
|
|
default:
|
|
|
|
return "unknown"
|
|
|
|
}
|
2019-10-29 15:29:21 +03:00
|
|
|
}
|
|
|
|
|
2019-11-02 16:25:10 +03:00
|
|
|
// Event is notification event
|
|
|
|
type Event struct {
|
2020-05-19 12:14:07 +03:00
|
|
|
// ID of the event
|
|
|
|
ID string
|
2019-11-02 16:25:10 +03:00
|
|
|
// Type is event type
|
|
|
|
Type EventType
|
|
|
|
// Timestamp is event timestamp
|
|
|
|
Timestamp time.Time
|
2020-05-19 12:14:07 +03:00
|
|
|
// Service the event relates to
|
|
|
|
Service *Service
|
|
|
|
// Options to use when processing the event
|
|
|
|
Options *CreateOptions
|
2019-09-14 07:33:14 +03:00
|
|
|
}
|
|
|
|
|
2019-11-02 16:25:10 +03:00
|
|
|
// Service is runtime service
|
|
|
|
type Service struct {
|
|
|
|
// Name of the service
|
|
|
|
Name string
|
2019-11-24 01:50:13 +03:00
|
|
|
// Version of the service
|
|
|
|
Version string
|
2019-11-02 16:25:10 +03:00
|
|
|
// url location of source
|
|
|
|
Source string
|
2019-11-22 20:10:00 +03:00
|
|
|
// Metadata stores metadata
|
|
|
|
Metadata map[string]string
|
2019-09-14 07:33:14 +03:00
|
|
|
}
|
2020-08-14 13:47:28 +03:00
|
|
|
|
|
|
|
// Resources which are allocated to a serivce
|
|
|
|
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
|
|
|
|
}
|