deployment

package
v0.0.0-...-1045ef1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateJobsCollection

func CreateJobsCollection(deployment string) error

CreateCollection create the job collection for a deployment

func CreateSecretsCollection

func CreateSecretsCollection(deployment string) error

CreateSecretsCollection creates secrets collection for a deployment

func Delete

func Delete(deployment string) error

Delete removes a deployments container resources and configuration. Note: This will also remove any existing collections created for the deployment (Secrets, Jobs, Config etc...)

func DeleteConfig

func DeleteConfig(deployment string) error

DeleteSecret removes a deployment configuration from the db

func DeleteJobsCollection

func DeleteJobsCollection(deployment string) error

DeleteCollection deletes the job collection for a deployment

func DeleteSecret

func DeleteSecret(deployment, key string) error

DeleteSecret deletes a deployment secret

func DeleteSecretsCollection

func DeleteSecretsCollection(deployment string) error

DeleteCollection deletes secrets collection for a deployment

func Exist

func Exist(deployment string) bool

Exist returns true if a deployment exist, false otherwise

func GetJobByID

func GetJobByID(deployment, id string, daysAgo uint) (job.Job, error)

GetJobByID returns a job by id

func GetJobs

func GetJobs(daysAgo uint) ([]job.Job, error)

GetJobs returns all deployment jobs within a given date range

func GetJobsByDeployment

func GetJobsByDeployment(deployment string, daysAgo uint) ([]job.Job, error)

GetJobs returns all jobs for a deployment within a time range

func RestartContainers

func RestartContainers(deployment string) error

RestartContainers will re-create container resources for a deployment Note: this almost the same call as 'Run' since they both re-create container resources based on the current configuration

func RetriableContainersHealthCheck

func RetriableContainersHealthCheck(containers []KraneContainer, retries int) error

RetriableContainersHealthCheck returns an error if a container is considered unhealthy

func Run

func Run(deployment string) error

Run a deployment runs the current configuration for a deployment creating or re-creating container resources

func SaveConfig

func SaveConfig(config Config) error

SaveConfig a deployment configuration into the db

func StartContainers

func StartContainers(deployment string) error

StartContainers starts current existing containers (if any) for a deployment Note: this does not re-create container resources, only start existing ones

func StopContainers

func StopContainers(deployment string) error

StopContainers stops current existing containers (if any) for a deployment Note: this does not re-create container resources, only stop existing ones

func SubscribeToContainerLogs

func SubscribeToContainerLogs(client *websocket.Conn, containerID string)

SubscribeToContainerLogs streams container logs to a websocket client

func SubscribeToDeploymentEvents

func SubscribeToDeploymentEvents(client *websocket.Conn, deployment string)

SubscribeToDeploymentEvents allows clients to subscribes to a particular deployments events

func SubscribeToDeploymentLogs

func SubscribeToDeploymentLogs(client *websocket.Conn, deployment string)

SubscribeToDeploymentLogs streams deployment logs to a websocket client

func UnSubscribeFromDeploymentEvents

func UnSubscribeFromDeploymentEvents(client *websocket.Conn, deployment string)

UnSubscribeFromDeploymentEvents unsubscribes a client from deployment events

Types

type Config

type Config struct {
	Name       string            `json:"name" binding:"required"`  // deployment name
	Image      string            `json:"image" binding:"required"` // container image
	Registry   Registry          `json:"registry"`                 // container registry credentials / auth
	Tag        string            `json:"tag"`                      // container image tag
	Alias      []string          `json:"alias"`                    // custom domain aliases (my-app.example.com or my-app.localhost)
	Env        map[string]string `json:"env"`                      // deployment environment variables
	Secrets    map[string]string `json:"secrets"`                  // deployment secrets resolved as environment variables
	Labels     map[string]string `json:"labels"`                   // container labels
	Ports      map[string]string `json:"ports"`                    // container ports to expose from the container to the host
	TargetPort string            `json:"target_port"`              // the target port to load-balance request through
	Volumes    map[string]string `json:"volumes"`                  // container volumes
	Command    string            `json:"command"`                  // container start command
	Entrypoint string            `json:"entrypoint"`               // container entrypoint
	Scale      int               `json:"scale"`                    // number of containers to create for the deployment
	Secure     bool              `json:"secure"`                   // enable/disable secure communication over HTTPS/TLS w/ auto generated certs
	Internal   bool              `json:"internal"`                 // whether a deployment is internal (ie. krane-proxy)
	RateLimit  uint              `json:"rate_limit"`               // requests per second for a given deployment (default 0, which means no rate limit)
}

Config represents a deployment configuration

func DeSerializeConfig

func DeSerializeConfig(bytes []byte) (Config, error)

DeSerialize returns a config from bytes

func GetAllDeploymentConfigs

func GetAllDeploymentConfigs() ([]Config, error)

GetAllDeploymentConfigs returns a list of all deployment configurations

func GetDeploymentConfig

func GetDeploymentConfig(deployment string) (Config, error)

GetDeploymentConfig returns a deployments configuration

func (Config) ApplyProxyLabels

func (config Config) ApplyProxyLabels()

ApplyProxyLabels applies network labels to a deployment config

func (Config) DockerConfig

func (config Config) DockerConfig() docker.DockerConfig

DockerConfig returns the docker configuration for creating a container

func (Config) DockerEnvs

func (config Config) DockerEnvs() []string

DockerEnvs returns a list of formatted Docker environment variables

func (Config) DockerLabels

func (config Config) DockerLabels() map[string]string

DockerLabels returns a map of Docker labels that are applied to Krane managed containers

func (Config) DockerPortSet

func (config Config) DockerPortSet() nat.PortSet

DockerPortSet returns Docker formatted port set

func (Config) DockerPorts

func (config Config) DockerPorts() nat.PortMap

DockerPorts returns Docker formatted port map

func (Config) DockerVolumeMount

func (config Config) DockerVolumeMount() []mount.Mount

DockerVolumeMount returns a list of formatted Docker volume mounts

func (Config) DockerVolumeSet

func (config Config) DockerVolumeSet() map[string]struct{}

DockerVolumeSet returns a set of Docker formatted volumes

func (Config) Empty

func (config Config) Empty() bool

Empty returns true if a config has not defined a deployment name or image

func (*Config) ResolveRegistryCredentials

func (config *Config) ResolveRegistryCredentials() error

func (Config) Serialize

func (config Config) Serialize() ([]byte, error)

Serialize returns the bytes for a deployment config

type ContainerState

type ContainerState struct {
	Status     string        `json:"status"` // created,started,running ...
	Running    bool          `json:"running"`
	Paused     bool          `json:"paused"`
	Restarting bool          `json:"restarting"`
	OOMKilled  bool          `json:"oom_killed"`
	Dead       bool          `json:"dead"`
	Pid        int           `json:"pid"`
	ExitCode   int           `json:"exit_code"`
	Error      string        `json:"error"`
	StartedAt  string        `json:"started_at"`
	FinishedAt string        `json:"finished_at"`
	Health     *types.Health `json:",omitempty"`
}

ContainerState represents the state of a Krane container

type ContainerStatus

type ContainerStatus string
const (
	ContainerRunning ContainerStatus = "running"
	ContainerStarted ContainerStatus = "started"
	ContainerCreated ContainerStatus = "created"
)

type Deployment

type Deployment struct {
	Config     Config           `json:"config"`
	Containers []KraneContainer `json:"containers"`
	Jobs       []job.Job        `json:"jobs"`
}

Deployment represent a Krane deployment and its configuration, current container resources, and recent job history

func GetAllDeployments

func GetAllDeployments() ([]Deployment, error)

GetAllDeployments returns a list of all deployments

func GetDeployment

func GetDeployment(deployment string) (Deployment, error)

GetDeployment returns a single deployment

type Event

type Event struct {
	JobID   string `json:"job_id"`
	Message string `json:"message"`
	Phase   Phase  `json:"phase"`
}

type EventEmitter

type EventEmitter struct {
	Deployment string
	JobID      string
	Phase      Phase
	Clients    []*websocket.Conn
}

type JobType

type JobType string
const (
	RunDeploymentJobType     JobType = "RUN_DEPLOYMENT"
	DeleteDeploymentJobType  JobType = "DELETE_DEPLOYMENT"
	StopContainersJobType    JobType = "STOP_CONTAINERS"
	StartContainersJobType   JobType = "START_CONTAINERS"
	RestartContainersJobType JobType = "RESTART_CONTAINERS"
)

type KraneContainer

type KraneContainer struct {
	ID         string            `json:"id"`
	Deployment string            `json:"deployment"`
	Name       string            `json:"name"`
	NetworkID  string            `json:"network_id"`
	Image      string            `json:"image"`
	ImageID    string            `json:"image_id"`
	CreatedAt  int64             `json:"created_at"`
	Labels     map[string]string `json:"labels"`
	State      ContainerState    `json:"state"`
	Ports      []Port            `json:"ports"`
	Volumes    []Volume          `json:"volumes"`
	Command    []string          `json:"command"`
	Entrypoint []string          `json:"entrypoint"`
}

KraneContainer represents a Krane managed container

func ContainerCreate

func ContainerCreate(config Config) (KraneContainer, error)

ContainerCreate creates a docker container from a deployment config

func GetContainers

func GetContainers() ([]KraneContainer, error)

GetContainers get all containers managed by Krane

func GetContainersByDeployment

func GetContainersByDeployment(deployment string) ([]KraneContainer, error)

GetContainersByDeployment get containers filtered by deployment

func (KraneContainer) Remove

func (c KraneContainer) Remove() error

Remove removes a Krane managed Docker container

func (KraneContainer) Running

func (c KraneContainer) Running() (bool, error)

Running returns whether a container is in a running state

func (KraneContainer) Start

func (c KraneContainer) Start() error

Start starts a Krane managed Docker Container

func (KraneContainer) Stop

func (c KraneContainer) Stop() error

Stop stops a Krane managed Docker Container

type Phase

type Phase string

Phases represents a particular step a deployment could be going through during its deployment cycle. They are attached to jobs allowing clients to react or filter for particular phases of the deployments cycle.

const (
	SetupPhase           Phase = "DEPLOYMENT_SETUP"
	HealthCheckPhase     Phase = "DEPLOYMENT_HEALTHCHECK"
	TeardownPhase        Phase = "DEPLOYMENT_TEARDOWN"
	DonePhase            Phase = "DEPLOYMENT_DONE"
	PullImagePhase       Phase = "PULL_IMAGE"
	CreateContainerPhase Phase = "CREATE_CONTAINER"
	StartContainerPhase  Phase = "START_CONTAINER"
)

type Port

type Port struct {
	IP            string `json:"ip"`
	Type          string `json:"type"`
	HostPort      string `json:"host_port"`
	ContainerPort string `json:"container_port"`
}

type PortProtocol

type PortProtocol string
const (
	TCP PortProtocol = "tcp"
)

type Registry

type Registry struct {
	URL      string `json:"url"`
	Username string `json:"username"`
	Password string `json:"password"`
}

type Secret

type Secret struct {
	Deployment string `json:"deployment"`
	Key        string `json:"key"`
	Value      string `json:"value"`
	Alias      string `json:"alias"`
}

func AddSecret

func AddSecret(deployment, key, value string) (*Secret, error)

AddSecret adds a secret to a deployment. Secrets are injected to the container during the container 'run' step. When a secret is created, an alias is returned and can be used to reference the secret in the `deployment.json` ie. SECRET_TOKEN=@secret-token (@secret-token was returned and how you reference the value for SECRET_TOKEN)

func GetAllSecrets

func GetAllSecrets(deployment string) ([]*Secret, error)

GetAllSecrets returns all secrets for a deployment

func GetAllSecretsRedacted

func GetAllSecretsRedacted(deployment string) []Secret

GetAllSecretsRedacted returns all deployment secrets with <redacted> a their value

func GetSecret

func GetSecret(deployment, key string) (*Secret, error)

GetSecret returns a deployment secret if it exists

func (*Secret) Redact

func (s *Secret) Redact()

Redact masks the value for a secret

func (Secret) SerializeSecret

func (s Secret) SerializeSecret() ([]byte, error)

type Volume

type Volume struct {
	HostVolume      string `json:"host_volume"`
	ContainerVolume string `json:"container_volume"`
}

Jump to

Keyboard shortcuts

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