control

package
v0.0.0-...-8018142 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: MPL-2.0 Imports: 15 Imported by: 4

README

control

GoDoc

Documentation

Overview

Package control provides a HTTP server listening on the unix domain socket for use as a control plane, as well as all the HTTP endpoints.

Index

Constants

This section is empty.

Variables

View Source
var (
	SocketType     = "unix"
	ErrMissingAddr = errors.New("control server not loading due to missing config")
)

SocketType is the default listener type

View Source
var DefaultSocket = "/var/run/containerpilot.socket"

DefaultSocket is the default location of the unix domain socket file

Functions

func GetPing

func GetPing(w http.ResponseWriter, r *http.Request)

GetPing allows us to check if the control socket is up without making a mutation of ContainerPilot's state

Types

type Config

type Config struct {
	SocketPath string `mapstructure:"socket"`
}

Config represents the location on the file system which serves the Unix control socket file.

func NewConfig

func NewConfig(raw interface{}) (*Config, error)

NewConfig parses a json config into a validated Config used by control Server.

type Endpoints

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

Endpoints wraps the EventBus so we can bridge data across the App and HTTPServer API boundary

func (Endpoints) PostDisableMaintenanceMode

func (e Endpoints) PostDisableMaintenanceMode(r *http.Request) (interface{}, int)

PostDisableMaintenanceMode handles incoming HTTP POST requests and toggles ContainerPilot maintenance mode on. Returns empty response or HTTP422.

func (Endpoints) PostEnableMaintenanceMode

func (e Endpoints) PostEnableMaintenanceMode(r *http.Request) (interface{}, int)

PostEnableMaintenanceMode handles incoming HTTP POST requests and toggles ContainerPilot maintenance mode on. Returns empty response or HTTP422.

func (Endpoints) PostMetric

func (e Endpoints) PostMetric(r *http.Request) (interface{}, int)

PostMetric handles incoming HTTP POST requests, serializes the metrics into Events, and publishes them for sensors to record their values. Returns empty response or HTTP422.

func (Endpoints) PostReload

func (e Endpoints) PostReload(r *http.Request) (interface{}, int)

PostReload handles incoming HTTP POST requests and reloads our current ContainerPilot process configuration. Returns empty response or HTTP422.

func (Endpoints) PutEnviron

func (e Endpoints) PutEnviron(r *http.Request) (interface{}, int)

PutEnviron handles incoming HTTP POST requests containing JSON environment variables and updates the environment of our current ContainerPilot process. Returns empty response or HTTP422.

type HTTPServer

type HTTPServer struct {
	Addr string
	Bus  *events.EventBus

	http.Server
	events.Publisher
}

HTTPServer contains the state of the HTTP Server used by ContainerPilot's HTTP transport control plane. Currently this is listening via a UNIX socket file.

func NewHTTPServer

func NewHTTPServer(cfg *Config) (*HTTPServer, error)

NewHTTPServer initializes a new control server for manipulating ContainerPilot's runtime configuration.

func (*HTTPServer) Run

func (srv *HTTPServer) Run(pctx context.Context, bus *events.EventBus)

Run executes the event loop for the control server

func (*HTTPServer) Start

func (srv *HTTPServer) Start(cancel context.CancelFunc)

Start sets up API routes with the event bus, listens on the control socket, and serves the HTTP server.

func (*HTTPServer) Stop

func (srv *HTTPServer) Stop() error

Stop shuts down the control server gracefully

func (*HTTPServer) Validate

func (srv *HTTPServer) Validate() error

Validate validates the state of the control server and ensures that the socket does not exist prior to setting up the listener (bind).

type PostHandler

type PostHandler func(*http.Request) (interface{}, int)

PostHandler is an adapter which allows a normal function to serve itself and handle incoming HTTP POST requests, and allows us to pass thru EventBus to handlers

func (PostHandler) ServeHTTP

func (pw PostHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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