2019-09-24 18:32:35 +01:00
|
|
|
package runtime
|
|
|
|
|
2019-09-24 19:00:11 +01:00
|
|
|
import (
|
2020-04-23 13:53:42 +01:00
|
|
|
"context"
|
2019-09-24 19:00:11 +01:00
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2019-11-02 13:25:10 +00:00
|
|
|
type Option func(o *Options)
|
|
|
|
|
|
|
|
// Options configure runtime
|
|
|
|
type Options struct {
|
2020-01-16 13:34:04 +00:00
|
|
|
// Scheduler for updates
|
|
|
|
Scheduler Scheduler
|
2019-11-29 11:35:00 +00:00
|
|
|
// Service type to manage
|
|
|
|
Type string
|
2020-02-05 13:59:35 +00:00
|
|
|
// Source of the services repository
|
|
|
|
Source string
|
2020-03-13 18:39:59 +00:00
|
|
|
// Base image to use
|
|
|
|
Image string
|
2020-02-05 13:59:35 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 08:52:25 +00:00
|
|
|
// WithSource sets the base image / repository
|
2020-02-05 13:59:35 +00:00
|
|
|
func WithSource(src string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Source = src
|
|
|
|
}
|
2019-11-02 13:25:10 +00:00
|
|
|
}
|
|
|
|
|
2020-01-16 13:34:04 +00:00
|
|
|
// WithScheduler specifies a scheduler for updates
|
|
|
|
func WithScheduler(n Scheduler) Option {
|
2019-11-02 13:25:10 +00:00
|
|
|
return func(o *Options) {
|
2020-01-16 13:34:04 +00:00
|
|
|
o.Scheduler = n
|
2019-11-02 13:25:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-29 11:35:00 +00:00
|
|
|
// WithType sets the service type to manage
|
|
|
|
func WithType(t string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Type = t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-13 18:39:59 +00:00
|
|
|
// WithImage sets the image to use
|
|
|
|
func WithImage(t string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Image = t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 18:32:35 +01:00
|
|
|
type CreateOption func(o *CreateOptions)
|
|
|
|
|
2019-11-29 11:35:00 +00:00
|
|
|
type ReadOption func(o *ReadOptions)
|
|
|
|
|
2019-11-02 13:25:10 +00:00
|
|
|
// CreateOptions configure runtime services
|
2019-09-24 18:32:35 +01:00
|
|
|
type CreateOptions struct {
|
2020-03-13 18:39:59 +00:00
|
|
|
// Command to execut
|
2019-09-24 18:32:35 +01:00
|
|
|
Command []string
|
2020-03-13 18:39:59 +00:00
|
|
|
// Args to pass into command
|
|
|
|
Args []string
|
2019-09-24 18:32:35 +01:00
|
|
|
// Environment to configure
|
|
|
|
Env []string
|
2019-09-24 19:00:11 +01:00
|
|
|
// Log output
|
|
|
|
Output io.Writer
|
2019-11-29 11:35:00 +00:00
|
|
|
// Type of service to create
|
|
|
|
Type string
|
2020-02-07 12:02:41 +00:00
|
|
|
// Retries before failing deploy
|
|
|
|
Retries int
|
2020-03-13 18:39:59 +00:00
|
|
|
// Specify the image to use
|
|
|
|
Image string
|
2020-04-23 13:53:42 +01:00
|
|
|
// Namespace to create the service in
|
|
|
|
Namespace string
|
|
|
|
// Specify the context to use
|
|
|
|
Context context.Context
|
2019-11-29 11:35:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReadOptions queries runtime services
|
|
|
|
type ReadOptions struct {
|
|
|
|
// Service name
|
|
|
|
Service string
|
|
|
|
// Version queries services with given version
|
|
|
|
Version string
|
|
|
|
// Type of service
|
|
|
|
Type string
|
2020-04-23 13:53:42 +01:00
|
|
|
// Namespace the service is running in
|
|
|
|
Namespace string
|
|
|
|
// Specify the context to use
|
|
|
|
Context context.Context
|
2019-09-24 18:32:35 +01:00
|
|
|
}
|
|
|
|
|
2020-01-17 14:14:47 +00:00
|
|
|
// CreateType sets the type of service to create
|
|
|
|
func CreateType(t string) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
o.Type = t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-13 18:39:59 +00:00
|
|
|
// CreateImage sets the image to use
|
|
|
|
func CreateImage(img string) CreateOption {
|
2020-02-24 17:47:47 +00:00
|
|
|
return func(o *CreateOptions) {
|
2020-03-13 18:39:59 +00:00
|
|
|
o.Image = img
|
2020-02-24 17:47:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-23 13:53:42 +01:00
|
|
|
// CreateNamespace sets the namespace
|
|
|
|
func CreateNamespace(ns string) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
o.Namespace = ns
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateContext sets the context
|
|
|
|
func CreateContext(ctx context.Context) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
o.Context = ctx
|
2020-04-23 12:27:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 19:00:11 +01:00
|
|
|
// WithCommand specifies the command to execute
|
2020-03-13 18:39:59 +00:00
|
|
|
func WithCommand(cmd ...string) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
// set command
|
|
|
|
o.Command = cmd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithArgs specifies the command to execute
|
|
|
|
func WithArgs(args ...string) CreateOption {
|
2019-09-24 18:32:35 +01:00
|
|
|
return func(o *CreateOptions) {
|
|
|
|
// set command
|
2020-03-13 18:39:59 +00:00
|
|
|
o.Args = args
|
2019-09-24 18:32:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-07 12:02:41 +00:00
|
|
|
// WithRetries sets the max retries attemps
|
|
|
|
func WithRetries(retries int) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
o.Retries = retries
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-02 13:25:10 +00:00
|
|
|
// WithEnv sets the created service environment
|
2019-09-24 18:32:35 +01:00
|
|
|
func WithEnv(env []string) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
o.Env = env
|
|
|
|
}
|
|
|
|
}
|
2019-09-24 19:00:11 +01:00
|
|
|
|
|
|
|
// WithOutput sets the arg output
|
|
|
|
func WithOutput(out io.Writer) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
o.Output = out
|
|
|
|
}
|
|
|
|
}
|
2019-11-15 13:41:40 +00:00
|
|
|
|
2019-11-29 11:35:00 +00:00
|
|
|
// ReadService returns services with the given name
|
|
|
|
func ReadService(service string) ReadOption {
|
|
|
|
return func(o *ReadOptions) {
|
|
|
|
o.Service = service
|
|
|
|
}
|
2019-11-15 13:41:40 +00:00
|
|
|
}
|
|
|
|
|
2020-02-07 12:02:41 +00:00
|
|
|
// ReadVersion confifgures service version
|
2019-11-29 11:35:00 +00:00
|
|
|
func ReadVersion(version string) ReadOption {
|
2019-11-25 16:31:14 +00:00
|
|
|
return func(o *ReadOptions) {
|
2019-11-15 13:41:40 +00:00
|
|
|
o.Version = version
|
|
|
|
}
|
|
|
|
}
|
2019-11-29 11:35:00 +00:00
|
|
|
|
|
|
|
// ReadType returns services of the given type
|
|
|
|
func ReadType(t string) ReadOption {
|
|
|
|
return func(o *ReadOptions) {
|
|
|
|
o.Type = t
|
|
|
|
}
|
|
|
|
}
|
2020-04-01 15:40:15 +02:00
|
|
|
|
2020-04-23 13:53:42 +01:00
|
|
|
// ReadNamespace sets the namespace
|
|
|
|
func ReadNamespace(ns string) ReadOption {
|
|
|
|
return func(o *ReadOptions) {
|
|
|
|
o.Namespace = ns
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadContext sets the context
|
|
|
|
func ReadContext(ctx context.Context) ReadOption {
|
|
|
|
return func(o *ReadOptions) {
|
|
|
|
o.Context = ctx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type UpdateOption func(o *UpdateOptions)
|
|
|
|
|
|
|
|
type UpdateOptions struct {
|
|
|
|
// Namespace the service is running in
|
|
|
|
Namespace string
|
|
|
|
// Specify the context to use
|
|
|
|
Context context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateNamespace sets the namespace
|
|
|
|
func UpdateNamespace(ns string) UpdateOption {
|
|
|
|
return func(o *UpdateOptions) {
|
|
|
|
o.Namespace = ns
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateContext sets the context
|
|
|
|
func UpdateContext(ctx context.Context) UpdateOption {
|
|
|
|
return func(o *UpdateOptions) {
|
|
|
|
o.Context = ctx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type DeleteOption func(o *DeleteOptions)
|
|
|
|
|
|
|
|
type DeleteOptions struct {
|
|
|
|
// Namespace the service is running in
|
|
|
|
Namespace string
|
|
|
|
// Specify the context to use
|
|
|
|
Context context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteNamespace sets the namespace
|
|
|
|
func DeleteNamespace(ns string) DeleteOption {
|
|
|
|
return func(o *DeleteOptions) {
|
|
|
|
o.Namespace = ns
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteContext sets the context
|
|
|
|
func DeleteContext(ctx context.Context) DeleteOption {
|
|
|
|
return func(o *DeleteOptions) {
|
|
|
|
o.Context = ctx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 15:40:15 +02:00
|
|
|
// LogsOption configures runtime logging
|
|
|
|
type LogsOption func(o *LogsOptions)
|
|
|
|
|
|
|
|
// LogsOptions configure runtime logging
|
|
|
|
type LogsOptions struct {
|
|
|
|
// How many existing lines to show
|
|
|
|
Count int64
|
|
|
|
// Stream new lines?
|
|
|
|
Stream bool
|
2020-04-23 13:53:42 +01:00
|
|
|
// Namespace the service is running in
|
|
|
|
Namespace string
|
|
|
|
// Specify the context to use
|
|
|
|
Context context.Context
|
2020-04-01 15:40:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// LogsExistingCount confiures how many existing lines to show
|
|
|
|
func LogsCount(count int64) LogsOption {
|
|
|
|
return func(l *LogsOptions) {
|
|
|
|
l.Count = count
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// LogsStream configures whether to stream new lines
|
|
|
|
func LogsStream(stream bool) LogsOption {
|
|
|
|
return func(l *LogsOptions) {
|
|
|
|
l.Stream = stream
|
|
|
|
}
|
|
|
|
}
|
2020-04-23 13:53:42 +01:00
|
|
|
|
|
|
|
// LogsNamespace sets the namespace
|
|
|
|
func LogsNamespace(ns string) LogsOption {
|
|
|
|
return func(o *LogsOptions) {
|
|
|
|
o.Namespace = ns
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// LogsContext sets the context
|
|
|
|
func LogsContext(ctx context.Context) LogsOption {
|
|
|
|
return func(o *LogsOptions) {
|
|
|
|
o.Context = ctx
|
|
|
|
}
|
|
|
|
}
|