state

package
v0.5.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StoreTypeFile = "file"
	StoreTypeEtcd = "etcd"
)
View Source
const (
	TLSCertificateImported      = "imported"
	TLSCertificateAzureKeyVault = "akv"
	TLSCertificateSelfSigned    = "selfsigned"
	TLSCertificateACME          = "acme"
)
View Source
const EtcdLockDuration = 20

Maximum lock duration, in seconds

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	RefreshHealth      chan int
	RefreshCerts       chan int
	DHParamsGenerating bool
	// contains filtered or unexported fields
}

Manager is the state manager class

var Instance *Manager

Instance is a singleton for Manager

func (*Manager) AcquireLock

func (m *Manager) AcquireLock(name string, timeout bool) (interface{}, error)

AcquireLock acquires a lock on the sync semaphore, ensuring that only one node at a time can be syncing

func (*Manager) AddSite

func (m *Manager) AddSite(site *SiteState) error

AddSite adds a site to the store

func (*Manager) ClusterHealth

func (m *Manager) ClusterHealth() (map[string]*utils.NodeStatus, error)

ClusterHealth returns the health of all members in the cluster

func (*Manager) DeleteSecret

func (m *Manager) DeleteSecret(key string) error

DeleteSecret deletes a secret

func (*Manager) DeleteSite

func (m *Manager) DeleteSite(domain string) error

DeleteSite remvoes a site from the store

func (*Manager) DumpState

func (m *Manager) DumpState() (*NodeState, error)

DumpState exports the entire state

func (*Manager) GetAllSiteHealth

func (m *Manager) GetAllSiteHealth() SiteHealth

GetAllSiteHealth returns the health of all objects

func (*Manager) GetCertificate

func (m *Manager) GetCertificate(typ string, nameOrDomains []string) (key []byte, cert []byte, err error)

GetCertificate returns a certificate pair (key and certificate) stored as secrets, PEM-encoded

func (*Manager) GetDHParams

func (m *Manager) GetDHParams() (string, *time.Time)

GetDHParams returns the PEM-encoded DH parameters and their date

func (*Manager) GetNodeHealth

func (m *Manager) GetNodeHealth() *utils.NodeStatus

GetNodeHealth gets the node status object

func (*Manager) GetSecret

func (m *Manager) GetSecret(key string) ([]byte, error)

GetSecret returns the value for a secret (encrypted in the state)

func (*Manager) GetSite

func (m *Manager) GetSite(domain string) *SiteState

GetSite returns the site object for a specific domain (including aliases)

func (*Manager) GetSiteHealth

func (m *Manager) GetSiteHealth(domain string) error

GetSiteHealth returns the health of a site

func (*Manager) GetSites

func (m *Manager) GetSites() []SiteState

GetSites returns the list of all sites

func (*Manager) GetStore

func (m *Manager) GetStore() StateStore

GetStore returns the instance of the store in use

func (*Manager) GetStoreType

func (m *Manager) GetStoreType() string

GetStoreType returns the type of the store in use

func (*Manager) Init

func (m *Manager) Init() (err error)

Init loads the state from the store

func (*Manager) LastUpdated

func (m *Manager) LastUpdated() *time.Time

LastUpdated returns the time the state was updated last

func (*Manager) ListImportedCertificates

func (m *Manager) ListImportedCertificates() (res []string)

ListImportedCertificates returns a list of the names of all imported certificates

func (*Manager) OnStateUpdate

func (m *Manager) OnStateUpdate(callback func())

OnStateUpdate stores the callback to invoke if the state is updated because of an external event

func (*Manager) ReleaseLock

func (m *Manager) ReleaseLock(leaseID interface{}) error

ReleaseSyncLock releases the lock on the sync semaphore

func (*Manager) RemoveCertificate

func (m *Manager) RemoveCertificate(typ string, nameOrDomains []string) (err error)

RemoveCertificate removes a certificate from the store

func (*Manager) ReplaceState

func (m *Manager) ReplaceState(state *NodeState) error

ReplaceState replaces the full state for the node with the provided one

func (*Manager) SetCertificate

func (m *Manager) SetCertificate(typ string, nameOrDomains []string, key []byte, cert []byte) (err error)

SetCertificate stores a PEM-encoded certificate pair (key and certificate) as a secret

func (*Manager) SetDHParams

func (m *Manager) SetDHParams(val string) error

SetDHParams stores new PEM-encoded DH parameters

func (*Manager) SetNodeHealth

func (m *Manager) SetNodeHealth(health *utils.NodeStatus) error

SetNodeHealth stores the node status object

func (*Manager) SetSecret

func (m *Manager) SetSecret(key string, value []byte) error

SetSecret sets the value for a secret (encrypted in the state)

func (*Manager) SetSiteHealth

func (m *Manager) SetSiteHealth(domain string, err error)

SetSiteHealth sets the health of a site

func (*Manager) StoreHealth

func (m *Manager) StoreHealth() (healthy bool, err error)

StoreHealth returns true if the store is healthy

func (*Manager) TriggerRefreshCerts

func (m *Manager) TriggerRefreshCerts()

TriggerRefreshCerts triggers a background job that re-checks all certificates and refreshes them

func (*Manager) TriggerRefreshHealth

func (m *Manager) TriggerRefreshHealth()

TriggerRefreshHealth triggers a background job that re-checks the health of all websites

func (*Manager) UpdateSite

func (m *Manager) UpdateSite(site *SiteState, setUpdated bool) error

UpdateSite updates a site with the same Domain

type NodeDHParams

type NodeDHParams struct {
	Date *time.Time `json:"time"`
	PEM  string     `json:"pem"`
}

NodeDHParams represents the DH Parameters file (PEM-encoded) and their age

type NodeState

type NodeState struct {
	Sites    []SiteState       `json:"sites"`
	Secrets  map[string][]byte `json:"secrets,omitempty"`
	DHParams *NodeDHParams     `json:"dhparams,omitempty"`
}

NodeState represents the global state of the node

type SiteApp

type SiteApp struct {
	// App details
	Name string `json:"name" binding:"required"`

	// App manifest (for internal use)
	Manifest *utils.AppManifest `json:"-"`
}

SiteApp represents the state of an app deployed or being deployed

func (*SiteApp) Validate

func (a *SiteApp) Validate() bool

Validate returns true if the app object is valid

type SiteHealth

type SiteHealth map[string]error

SiteHealth represents the health of each site in the node

type SiteState

type SiteState struct {
	// Domains: primary and aliases
	Domain  string   `json:"domain" binding:"ne=_default"`
	Aliases []string `json:"aliases" binding:"dive,ne=_default"`

	// Temporary site (e.g. for testing)
	Temporary bool `json:"temporary,omitempty"`

	// TLS configuration
	TLS *SiteTLS `json:"tls"`

	// App
	App *SiteApp `json:"app"`
}

SiteState represents the state of a single site

type SiteTLS

type SiteTLS struct {
	Type        string  `json:"type"`
	Certificate *string `json:"cert,omitempty"`
	Version     *string `json:"ver,omitempty"`
}

SiteTLS represents the TLS configuration for the site

type StateStore

type StateStore interface {
	Init() error
	AcquireLock(name string, timeout bool) (interface{}, error)
	ReleaseLock(leaseID interface{}) error
	GetState() *NodeState
	SetState(*NodeState) error
	WriteState() error
	ReadState() error
	Healthy() (bool, error)
	OnStateUpdate(func())
	ClusterHealth() (map[string]*utils.NodeStatus, error)
	StoreNodeHealth(health *utils.NodeStatus) error
}

StateStore is the interface for the state stores

type StateStoreEtcd

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

func (*StateStoreEtcd) AcquireLock

func (s *StateStoreEtcd) AcquireLock(name string, timeout bool) (interface{}, error)

AcquireLock acquires a lock, with an optional timeout

func (*StateStoreEtcd) ClusterHealth

func (s *StateStoreEtcd) ClusterHealth() (map[string]*utils.NodeStatus, error)

ClusterHealth returns the health of all members in the cluster

func (*StateStoreEtcd) GetClient

func (s *StateStoreEtcd) GetClient() *clientv3.Client

GetClient returns the etcd client with the active connection

func (*StateStoreEtcd) GetContext

func (s *StateStoreEtcd) GetContext() (context.Context, context.CancelFunc)

GetContext returns a context that times out

func (*StateStoreEtcd) GetMemberId

func (s *StateStoreEtcd) GetMemberId() string

GetMemberId returns the ID of this member in the cluster

func (*StateStoreEtcd) GetState

func (s *StateStoreEtcd) GetState() *NodeState

GetState returns the full state

func (*StateStoreEtcd) Healthy

func (s *StateStoreEtcd) Healthy() (healthy bool, err error)

Healthy returns true if the connection with etcd is active

func (*StateStoreEtcd) Init

func (s *StateStoreEtcd) Init() (err error)

Init initializes the object

func (*StateStoreEtcd) OnStateUpdate

func (s *StateStoreEtcd) OnStateUpdate(callback func())

OnStateUpdate stores the callback that is invoked when there's a new state from etcd

func (*StateStoreEtcd) ReadState

func (s *StateStoreEtcd) ReadState() (err error)

ReadState reads the state from etcd

func (*StateStoreEtcd) ReleaseLock

func (s *StateStoreEtcd) ReleaseLock(leaseID interface{}) error

ReleaseLock releases a lock

func (*StateStoreEtcd) SetState

func (s *StateStoreEtcd) SetState(state *NodeState) (err error)

StoreState replaces the current state

func (*StateStoreEtcd) StoreNodeHealth

func (s *StateStoreEtcd) StoreNodeHealth(health *utils.NodeStatus) error

StoreNodeHealth stores the health of this node in etcd

func (*StateStoreEtcd) WriteState

func (s *StateStoreEtcd) WriteState() (err error)

WriteState stores the state in etcd

type StateStoreFile

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

func (*StateStoreFile) AcquireLock

func (s *StateStoreFile) AcquireLock(name string, timeout bool) (interface{}, error)

AcquireLock acquires a lock, with an optional timeout

func (*StateStoreFile) ClusterHealth

func (s *StateStoreFile) ClusterHealth() (map[string]*utils.NodeStatus, error)

ClusterHealth returns the health of all members in the cluster

func (*StateStoreFile) GetState

func (s *StateStoreFile) GetState() *NodeState

GetState returns the full state

func (*StateStoreFile) Healthy

func (s *StateStoreFile) Healthy() (bool, error)

Healthy returns always true

func (*StateStoreFile) Init

func (s *StateStoreFile) Init() (err error)

Init initializes the object

func (*StateStoreFile) OnStateUpdate

func (s *StateStoreFile) OnStateUpdate(callback func())

OnStateUpdate isn't used with this store

func (*StateStoreFile) ReadState

func (s *StateStoreFile) ReadState() (err error)

ReadState reads the state from disk

func (*StateStoreFile) ReleaseLock

func (s *StateStoreFile) ReleaseLock(leaseID interface{}) error

ReleaseLock releases a lock

func (*StateStoreFile) SetState

func (s *StateStoreFile) SetState(state *NodeState) (err error)

StoreState replaces the current state

func (*StateStoreFile) StoreNodeHealth

func (s *StateStoreFile) StoreNodeHealth(health *utils.NodeStatus) error

StoreNodeHealth isn't used with this store

func (*StateStoreFile) WriteState

func (s *StateStoreFile) WriteState() (err error)

WriteState stores the state on disk

type WorkerController

type WorkerController interface {
	Init(store StateStore)
	IsLeader() bool
	AddJob(job utils.JobData) (string, error)
	CompleteJob(jobID string) error
	WaitForJob(jobID string, ch chan error)
}

WorkerController is the interface for the controller

var Worker WorkerController

Worker is a singleton for the WorkerController

Jump to

Keyboard shortcuts

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