models

package
v0.4.20 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2018 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//ClientIDEnvVar defines the name of the environment variable
	ClientIDEnvVar = "MYSTACK_GOOGLE_CLIENT_ID"
	//ClientSecretEnvVar defines the name of the environment variable
	ClientSecretEnvVar = "MYSTACK_GOOGLE_CLIENT_SECRET"
)

Variables

This section is empty.

Functions

func ClusterConfigDetails

func ClusterConfigDetails(db DB, clusterName string) (string, error)

ClusterConfigDetails return the cluster config yaml

func CreateNamespace

func CreateNamespace(clientset kubernetes.Interface, username string) error

CreateNamespace creates a namespace

func DeleteNamespace

func DeleteNamespace(clientset kubernetes.Interface, username string) error

DeleteNamespace delete the namespace

func GetDB

func GetDB(
	host string, user string, port int, sslmode string,
	dbName string, password string,
	maxIdleConns, maxOpenConns int,
	connectionTimeoutMS int,
) (*sqlx.DB, error)

GetDB Connection using the given properties

func ListClusterConfig

func ListClusterConfig(db DB) ([]string, error)

ListClusterConfig return the list of saved cluster configs

func ListNamespaces

func ListNamespaces(clientset kubernetes.Interface) (*v1.NamespaceList, error)

ListNamespaces returns a list of namespaces

func NamespaceExists

func NamespaceExists(clientset kubernetes.Interface, namespace string) bool

NamespaceExists return true if namespace is already created

func RemoveClusterConfig

func RemoveClusterConfig(
	db DB,
	clusterName string,
) error

RemoveClusterConfig writes cluster config on DB

func ServicePort added in v0.3.0

func ServicePort(clientset kubernetes.Interface, name, username string) (int, error)

ServicePort ...

func WriteClusterConfig

func WriteClusterConfig(
	db DB,
	clusterName string,
	yamlStr string,
) error

WriteClusterConfig writes cluster config on DB

Types

type Cluster

type Cluster struct {
	Namespace              string
	Username               string
	AppDeployments         []*Deployment
	SvcDeployments         []*Deployment
	K8sServices            map[*Deployment]*Service
	Job, PostJob           *Job
	PersistentVolumeClaims []*PersistentVolumeClaim
	DeploymentReadiness    Readiness
	JobReadiness           Readiness
}

Cluster represents a k8s cluster for a user

func NewCluster

func NewCluster(
	db DB,
	username, clusterName string,
	deploymentReadiness, jobReadiness Readiness,
	config *viper.Viper,
) (*Cluster, error)

NewCluster returns a new cluster ready to start

func (*Cluster) Apps

func (c *Cluster) Apps(
	config *viper.Viper,
	clientset kubernetes.Interface,
	k8sDomain string,
) (map[string][]string, error)

Apps returns a list of cluster apps

func (*Cluster) Create

func (c *Cluster) Create(logger logrus.FieldLogger, clientset kubernetes.Interface) error

Create creates namespace, deployments and services

func (*Cluster) Delete

func (c *Cluster) Delete(clientset kubernetes.Interface) error

Delete deletes namespace and all deployments and services

func (*Cluster) Services added in v0.3.0

func (c *Cluster) Services(clientset kubernetes.Interface) ([]string, error)

Services returns a list of cluster services

type ClusterAppConfig

type ClusterAppConfig struct {
	Image           string       `yaml:"image"`
	ImagePullPolicy string       `yaml:"imagePullPolicy"`
	Command         []string     `yaml:"command"`
	Ports           []string     `yaml:"ports"`
	Environment     []*EnvVar    `yaml:"env,flow"`
	ReadinessProbe  *Probe       `yaml:"readinessProbe"`
	VolumeMount     *VolumeMount `yaml:"volumeMount"`
	Links           []string     `yaml:"links"`
	Resources       *Resources   `yaml:"resources"`
	IsSocket        bool         `yaml:"isSocket"`
}

ClusterAppConfig defines the configuration of an app and service

type ClusterConfig

type ClusterConfig struct {
	Setup     *Setup                       `yaml:"setup"`
	PostSetup *Setup                       `yaml:"postSetup"`
	Volumes   []*PersistentVolumeClaim     `yaml:"volumes"`
	Services  map[string]*ClusterAppConfig `yaml:"services"`
	Apps      map[string]*ClusterAppConfig `yaml:"apps"`
}

ClusterConfig contains the elements of a config file

func LoadClusterConfig

func LoadClusterConfig(
	db DB,
	clusterName string,
) (
	*ClusterConfig,
	error,
)

LoadClusterConfig reads DB and create map with cluster configuration

func ParseYaml

func ParseYaml(yamlStr string) (*ClusterConfig, error)

ParseYaml convert string to maps

type Credentials

type Credentials interface {
	GetID() string
	GetSecret() string
}

Credentials is an interface with Get method to get ClientID and ClientSecret

type DB

type DB interface {
	NamedExec(query string, arg interface{}) (sql.Result, error)
	Get(dest interface{}, query string, args ...interface{}) error
	Select(dest interface{}, query string, args ...interface{}) error
}

DB is the mystack-controller db interface

type Deployment

type Deployment struct {
	Name            string
	Namespace       string
	Username        string
	Command         []string
	Image           string
	ImagePullPolicy string
	Ports           []int
	Environment     []*EnvVar
	ReadinessProbe  *Probe
	Volume          *VolumeMount
	Links           []*Deployment
	Resources       *Resources
}

Deployment represents a deployment

func NewDeployment

func NewDeployment(
	name, username, image string,
	ports []int,
	environment []*EnvVar,
	readinessProbe *Probe,
	volume *VolumeMount,
	command []string,
	resources *Resources,
	config *viper.Viper,
) *Deployment

NewDeployment is the deployment ctor

func (*Deployment) Delete

func (d *Deployment) Delete(clientset kubernetes.Interface) error

Delete deletes deployment from cluster

func (*Deployment) Deploy

func (d *Deployment) Deploy(clientset kubernetes.Interface) (*v1beta1.Deployment, error)

Deploy creates a deployment from yaml

type DeploymentReadiness

type DeploymentReadiness struct{}

DeploymentReadiness implements Readiness interface

func (*DeploymentReadiness) WaitForCompletion

func (dr *DeploymentReadiness) WaitForCompletion(clientset kubernetes.Interface, d interface{}) error

WaitForCompletion waits until job has completed its task

type EnvVar

type EnvVar struct {
	Name  string `yaml:"name"`
	Value string `yaml:"value"`
}

EnvVar has name and value of an environment value

type Job

type Job struct {
	Name        string
	Namespace   string
	Username    string
	Environment []*EnvVar
	Setup       *Setup
}

Job represents a Kubernetes job

func NewJob

func NewJob(name, username string, setup *Setup, environment []*EnvVar) *Job

NewJob is the job ctor

func (*Job) Run

func (j *Job) Run(clientset kubernetes.Interface) (*v1.Job, error)

Run starts the Job

type JobReadiness

type JobReadiness struct{}

JobReadiness implements Readiness interface

func (*JobReadiness) WaitForCompletion

func (jr *JobReadiness) WaitForCompletion(
	clientset kubernetes.Interface,
	j interface{},
) error

WaitForCompletion waits until job has completed its task

type MemoryAndCPUResource added in v0.4.3

type MemoryAndCPUResource struct {
	CPU    string `yaml:"cpu"`
	Memory string `yaml:"memory"`
}

MemoryAndCPUResource has information about CPU and memory to be allocated to a pod

type MockCredentials

type MockCredentials struct {
	ID  string
	Key string
}

MockCredentials implements Credentials interface

func (*MockCredentials) GetID

func (m *MockCredentials) GetID() string

GetID gets ID from environment variable

func (*MockCredentials) GetSecret

func (m *MockCredentials) GetSecret() string

GetSecret gets secret from environment variable

type OSCredentials

type OSCredentials struct{}

OSCredentials implements Credentials interface

func (*OSCredentials) GetID

func (o *OSCredentials) GetID() string

GetID gets ID from environment variable

func (*OSCredentials) GetSecret

func (o *OSCredentials) GetSecret() string

GetSecret gets secret from environment variable

type PersistentVolumeClaim added in v0.2.0

type PersistentVolumeClaim struct {
	Name      string `yaml:"name"`
	Storage   string `yaml:"storage"`
	Namespace string
}

PersistentVolumeClaim gets volume configs from yaml

func NewPVC added in v0.2.0

func NewPVC(name, username, storage string) *PersistentVolumeClaim

NewPVC is the PersistentVolumeClaim constructor

func (*PersistentVolumeClaim) Delete added in v0.2.0

func (p *PersistentVolumeClaim) Delete(clientset kubernetes.Interface) error

Delete deletes persistent volume cluster

func (*PersistentVolumeClaim) Start added in v0.2.0

Start ...

type PortMap

type PortMap struct {
	Port       int
	TargetPort int
	Name       string
}

PortMap maps a port to a target por on service

type Probe

type Probe struct {
	Command       []string `yaml:"command"`
	PeriodSeconds int      `yaml:"periodSeconds"`
	//This timeout is different from the kubernetes object api timeoutSecond.
	//This timeout represents the total wait time until stop deployment initiation and rollback
	TimeoutSeconds int `yaml:"startDeploymentTimeoutSeconds"`
}

Probe refers to the Kubernetes readiness probe

type Readiness

type Readiness interface {
	WaitForCompletion(kubernetes.Interface, interface{}) error
}

Readiness is the interface that tell how much time to wait until the deployment is ready and its readiness probe reports Ready

type Resources added in v0.4.3

type Resources struct {
	Limits   *MemoryAndCPUResource `yaml:"limits"`
	Requests *MemoryAndCPUResource `yaml:"requests"`
}

Resources holds how much CPU and memory is allocated to the pod

type Service

type Service struct {
	Name         string
	Namespace    string
	Ports        []*PortMap
	IsMystackSvc bool
	SocketPorts  string
	IsSocket     bool
}

Service represents a service

func NewService

func NewService(name, username string, ports []*PortMap, isMystackSvc, isSocket bool) *Service

NewService is the service ctor

func (*Service) Delete

func (s *Service) Delete(clientset kubernetes.Interface) error

Delete deletes service

func (*Service) Expose

func (s *Service) Expose(clientset kubernetes.Interface) (*v1.Service, error)

Expose exposes a deployment

type Setup

type Setup struct {
	Image           string    `yaml:"image"`
	ImagePullPolicy string    `yaml:"imagePullPolicy"`
	Command         []string  `yaml:"command"`
	PeriodSeconds   int       `yaml:"periodSeconds"`
	Environment     []*EnvVar `yaml:"env"`
	TimeoutSeconds  int       `yaml:"timeoutSeconds"`
}

Setup has the job config to run and configure services

type VolumeMount added in v0.2.0

type VolumeMount struct {
	Name      string `yaml:"name"`
	MountPath string `yaml:"mountPath"`
}

VolumeMount helps getting PersistentVolume from yaml

Jump to

Keyboard shortcuts

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