storage

package
v0.0.0-...-1eec387 Latest Latest
Warning

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

Go to latest
Published: May 25, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCheckUpdateInterval = 1 * time.Minute
	DefaultWorkerTimeout       = 60 * time.Minute
)

Default values

View Source
const (
	KeySabakanStateSetterLeader = "leader/sabakan-state-setter/"
	KeyUpdaterLeader            = "leader/updater/"
	KeyWorkerLeader             = "leader/worker/"
	KeyInfoPrefix               = "info/"
	KeyBootserversPrefix        = "info/bootservers/"
	KeyNecoRelease              = "info/neco-release"
	KeySSHPubkey                = "info/ssh-pubkey"
	KeyStatusPrefix             = "status/"
	KeyCurrent                  = "status/current"
	KeyWorkerStatusPrefix       = "status/bootservers/"
	KeyContentsPrefix           = "contents/"
	KeySabakanContents          = "contents/sabakan"
	KeyCKEContents              = "contents/cke"
	KeyDHCPJSONContents         = "contents/dhcp.json"
	KeyCKETemplateContents      = "contents/cke-template"
	KeyUserResourcesContents    = "contents/user-resources"
	KeyConfigPrefix             = "config/"
	KeyNotificationSlack        = "config/notification/slack"
	KeyProxy                    = "config/proxy"
	KeyQuayUsername             = "config/quay-username"
	KeyQuayPassword             = "config/quay-password"
	KeyEnv                      = "config/env"
	KeyCheckUpdateInterval      = "config/check-update-interval"
	KeyWorkerTimeout            = "config/worker-timeout"
	KeyGitHubToken              = "config/github-token"
	KeyNodeProxy                = "config/node-proxy"
	KeyExternalIPAddressBlock   = "config/external-ip-address-block"
	KeyLBAddressBlockDefault    = "config/lb-address-block-default"
	KeyLBAddressBlockBastion    = "config/lb-address-block-bastion"
	KeyLBAddressBlockInternet   = "config/lb-address-block-internet"
	KeyVaultUnsealKey           = "vault-unseal-key"
	KeyVaultRootToken           = "vault-root-token"
	KeyFinishPrefix             = "finish/"
	KeyContainersFormat         = "install/%d/containers/%s"
	KeyDebsFormat               = "install/%d/debs/%s"
	KeyInstallPrefix            = "install/"
	KeyBMCBMCUser               = "bmc/bmc-user"
	KeyBMCIPMIUser              = "bmc/ipmi-user"
	KeyBMCIPMIPassword          = "bmc/ipmi-password"
	KeyTeleportAuthToken        = "teleport/auth-token"
	KeyCKEWeight                = "cke/weight"
)

etcd keys

Variables

View Source
var (
	// ErrNotFound is returned when a key is not found in storage.
	ErrNotFound = errors.New("not found")

	// ErrNotStopped is returned when the updater did not stop.
	ErrNotStopped = errors.New("not stopped")

	// ErrNoLeader is returned when the caller lost leadership.
	ErrNoLeader = errors.New("lost leadership")

	// ErrTimedOut is returned when the request is timed out.
	ErrTimedOut = errors.New("timed out")
)

Functions

This section is empty.

Types

type Snapshot

type Snapshot struct {
	Revision int64
	Request  *neco.UpdateRequest
	Statuses map[int]*neco.UpdateStatus
	Latest   string
	Servers  []int
}

Snapshot is the up-to-date snapshot of etcd database.

type StatusWatcher

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

StatusWatcher has callback handlers to handle status changes

func NewStatusWatcher

func NewStatusWatcher(
	handleRequest func(context.Context, *neco.UpdateRequest) (bool, error),
	handleStatus func(context.Context, int, *neco.UpdateStatus) (bool, error),
	handleError func(context.Context, error) error,
) StatusWatcher

NewStatusWatcher creates a new StatusWatcher

func (StatusWatcher) Watch

func (w StatusWatcher) Watch(ctx context.Context, storage Storage, rev int64) error

Watch watches UpdateRequest or UpdateStatus is written to etcd

type Storage

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

Storage is storage client

func NewStorage

func NewStorage(etcd *clientv3.Client) Storage

NewStorage returns Storage that stores data in etcd.

func (Storage) ClearStatusAndContents

func (s Storage) ClearStatusAndContents(ctx context.Context) error

ClearStatusAndContents removes KeyStatusPrefix/* and KeyContentsPrefix/* from storage.

It first checks that "stop" field in KeyCurrent is true. If not, ErrNotStopped will be returned.

Then it removes status keys in a single transaction.

func (Storage) DeleteBootServer

func (s Storage) DeleteBootServer(ctx context.Context, lrn int) error

DeleteBootServer deletes boot server from etcd database.

func (Storage) DeleteVaultRootToken

func (s Storage) DeleteVaultRootToken(ctx context.Context) error

DeleteVaultRootToken deletes vault root token from storage

func (Storage) DeleteVaultUnsealKey

func (s Storage) DeleteVaultUnsealKey(ctx context.Context) error

DeleteVaultUnsealKey deletes vault unseal key from storage

func (Storage) Finish

func (s Storage) Finish(ctx context.Context, lrn int, stage int) error

Finish stores the finished stage number for a bootserver to storage

func (Storage) GetBMCBMCUser

func (s Storage) GetBMCBMCUser(ctx context.Context) (string, error)

GetBMCBMCUser returns bmc-user.json contents

func (Storage) GetBMCIPMIPassword

func (s Storage) GetBMCIPMIPassword(ctx context.Context) (string, error)

GetBMCIPMIPassword returns IPMI password.

func (Storage) GetBMCIPMIUser

func (s Storage) GetBMCIPMIUser(ctx context.Context) (string, error)

GetBMCIPMIUser returns IPMI username.

func (Storage) GetCKEContentsStatus

func (s Storage) GetCKEContentsStatus(ctx context.Context) (*neco.ContentsUpdateStatus, error)

GetCKEContentsStatus returns update status of CKE contents.

func (Storage) GetCKETemplateContentsStatus

func (s Storage) GetCKETemplateContentsStatus(ctx context.Context) (*neco.ContentsUpdateStatus, error)

GetCKETemplateContentsStatus returns update status of cke-template.yml.

func (Storage) GetCKEWeight

func (s Storage) GetCKEWeight(ctx context.Context) (map[string]float64, error)

GetCKEWeight returns weights of roles..

func (Storage) GetCheckUpdateInterval

func (s Storage) GetCheckUpdateInterval(ctx context.Context) (time.Duration, error)

GetCheckUpdateInterval returns check-update-interval config from storage. It returns default value if the key does not exist.

func (Storage) GetContainerTag

func (s Storage) GetContainerTag(ctx context.Context, lrn int, name string) (string, error)

GetContainerTag returns installed container image tag

func (Storage) GetDHCPJSONContentsStatus

func (s Storage) GetDHCPJSONContentsStatus(ctx context.Context) (*neco.ContentsUpdateStatus, error)

GetDHCPJSONContentsStatus returns update status of dhcp.json for sabakan.

func (Storage) GetDebVersion

func (s Storage) GetDebVersion(ctx context.Context, lrn int, name string) (string, error)

GetDebVersion returns installed debian package version

func (Storage) GetEnvConfig

func (s Storage) GetEnvConfig(ctx context.Context) (string, error)

GetEnvConfig returns proxy config from storage.

func (Storage) GetExternalIPAddressBlock

func (s Storage) GetExternalIPAddressBlock(ctx context.Context) (string, error)

GetExternalIPAddressBlock returns external ip address block from storage

func (Storage) GetFinished

func (s Storage) GetFinished(ctx context.Context, stage int) ([]int, error)

GetFinished returns a list of bootservers that completed specified stage of setup

func (Storage) GetGitHubToken

func (s Storage) GetGitHubToken(ctx context.Context) (string, error)

GetGitHubToken returns github-token from storage

func (Storage) GetLBAddressBlockBastion

func (s Storage) GetLBAddressBlockBastion(ctx context.Context) (string, error)

GetLBAddressBlockBastion returns LB address block for bastion from storage

func (Storage) GetLBAddressBlockDefault

func (s Storage) GetLBAddressBlockDefault(ctx context.Context) (string, error)

GetLBAddressBlockDefault returns LB address block for default from storage

func (Storage) GetLBAddressBlockInternet

func (s Storage) GetLBAddressBlockInternet(ctx context.Context) (string, error)

GetLBAddressBlockInternet returns LB address block for internet from storage

func (Storage) GetNecoRelease

func (s Storage) GetNecoRelease(ctx context.Context) (string, error)

GetNecoRelease gets the neco package version recorded in etcd.

func (Storage) GetNodeProxy

func (s Storage) GetNodeProxy(ctx context.Context) (string, error)

GetNodeProxy returns node-proxy from storage

func (Storage) GetProxyConfig

func (s Storage) GetProxyConfig(ctx context.Context) (string, error)

GetProxyConfig returns proxy config from storage.

func (Storage) GetQuayPassword

func (s Storage) GetQuayPassword(ctx context.Context) (string, error)

GetQuayPassword returns proxy config from storage.

func (Storage) GetQuayUsername

func (s Storage) GetQuayUsername(ctx context.Context) (string, error)

GetQuayUsername returns proxy config from storage.

func (Storage) GetRequest

func (s Storage) GetRequest(ctx context.Context) (*neco.UpdateRequest, error)

GetRequest returns UpdateRequest from storage If there is no request, this returns ErrNotFound

func (Storage) GetRequestWithRev

func (s Storage) GetRequestWithRev(ctx context.Context) (req *neco.UpdateRequest, modRev int64, rev int64, err error)

GetRequestWithRev returns UpdateRequest from storage with ModRevision and Revision. If there is no request, this returns ErrNotFound

func (Storage) GetSSHPubkey

func (s Storage) GetSSHPubkey(ctx context.Context) (string, error)

GetSSHPubkey retrieves a SSH public key for nodes.

func (Storage) GetSabakanContentsStatus

func (s Storage) GetSabakanContentsStatus(ctx context.Context) (*neco.ContentsUpdateStatus, error)

GetSabakanContentsStatus returns update status of Sabakan contents.

func (Storage) GetSlackNotification

func (s Storage) GetSlackNotification(ctx context.Context) (string, error)

GetSlackNotification returns SlackNotification from storage If not found, this returns ErrNotFound.

func (Storage) GetStatus

func (s Storage) GetStatus(ctx context.Context, lrn int) (*neco.UpdateStatus, error)

GetStatus returns UpdateStatus of a bootserver from storage If not found, this returns ErrNotFound.

func (Storage) GetStatuses

func (s Storage) GetStatuses(ctx context.Context) (map[int]*neco.UpdateStatus, error)

GetStatuses returns UpdateStatus of existing boot servers.

func (Storage) GetTeleportAuthToken

func (s Storage) GetTeleportAuthToken(ctx context.Context) (string, error)

GetTeleportAuthToken returns auth token

func (Storage) GetUserResourcesContentsStatus

func (s Storage) GetUserResourcesContentsStatus(ctx context.Context) (*neco.ContentsUpdateStatus, error)

GetUserResourcesContentsStatus returns update status of user-defined resources.

func (Storage) GetVaultRootToken

func (s Storage) GetVaultRootToken(ctx context.Context) (string, error)

GetVaultRootToken returns vault root token from storage

func (Storage) GetVaultUnsealKey

func (s Storage) GetVaultUnsealKey(ctx context.Context) (string, error)

GetVaultUnsealKey returns vault unseal key from storage

func (Storage) GetWorkerTimeout

func (s Storage) GetWorkerTimeout(ctx context.Context) (time.Duration, error)

GetWorkerTimeout returns worker-timeout config from storage. It returns default value if the key does not exist.

func (Storage) NewSnapshot

func (s Storage) NewSnapshot(ctx context.Context) (*Snapshot, error)

NewSnapshot takes the up-to-date snapshot.

func (Storage) PutBMCBMCUser

func (s Storage) PutBMCBMCUser(ctx context.Context, value string) error

PutBMCBMCUser stores bmc-user.json contents

func (Storage) PutBMCIPMIPassword

func (s Storage) PutBMCIPMIPassword(ctx context.Context, value string) error

PutBMCIPMIPassword stores IPMI password.

func (Storage) PutBMCIPMIUser

func (s Storage) PutBMCIPMIUser(ctx context.Context, value string) error

PutBMCIPMIUser stores IPMI username.

func (Storage) PutCKEContentsStatus

func (s Storage) PutCKEContentsStatus(ctx context.Context, st *neco.ContentsUpdateStatus, leaderKey string) error

PutCKEContentsStatus puts update status of CKE contents, only if caller is the leader.

func (Storage) PutCKETemplateContentsStatus

func (s Storage) PutCKETemplateContentsStatus(ctx context.Context, st *neco.ContentsUpdateStatus, leaderKey string) error

PutCKETemplateContentsStatus puts update status of cke-template.yml, only if caller is the leader.

func (Storage) PutCKEWeight

func (s Storage) PutCKEWeight(ctx context.Context, value map[string]float64) error

PutCKEWeight stores weights of roles.

func (Storage) PutCheckUpdateInterval

func (s Storage) PutCheckUpdateInterval(ctx context.Context, d time.Duration) error

PutCheckUpdateInterval stores check-update-interval config to storage.

func (Storage) PutDHCPJSONContentsStatus

func (s Storage) PutDHCPJSONContentsStatus(ctx context.Context, st *neco.ContentsUpdateStatus, leaderKey string) error

PutDHCPJSONContentsStatus puts update status of dhcp.json for sabakan, only if caller is the leader.

func (Storage) PutEnvConfig

func (s Storage) PutEnvConfig(ctx context.Context, env string) error

PutEnvConfig stores proxy config to storage.

func (Storage) PutExternalIPAddressBlock

func (s Storage) PutExternalIPAddressBlock(ctx context.Context, ipBlock string) error

PutExternalIPAddressBlock stores external ip address block config to storage.

func (Storage) PutGitHubToken

func (s Storage) PutGitHubToken(ctx context.Context, token string) error

PutGitHubToken stores github-token config to storage.

func (Storage) PutLBAddressBlockBastion

func (s Storage) PutLBAddressBlockBastion(ctx context.Context, ipBlock string) error

PutLBAddressBlockBastion stores LB address block for bastion to storage.

func (Storage) PutLBAddressBlockDefault

func (s Storage) PutLBAddressBlockDefault(ctx context.Context, ipBlock string) error

PutLBAddressBlockDefault stores LB address block for default to storage.

func (Storage) PutLBAddressBlockInternet

func (s Storage) PutLBAddressBlockInternet(ctx context.Context, ipBlock string) error

PutLBAddressBlockInternet stores LB address block for internet to storage.

func (Storage) PutNodeProxy

func (s Storage) PutNodeProxy(ctx context.Context, token string) error

PutNodeProxy stores node-proxy config to storage.

func (Storage) PutProxyConfig

func (s Storage) PutProxyConfig(ctx context.Context, proxy string) error

PutProxyConfig stores proxy config to storage.

func (Storage) PutQuayPassword

func (s Storage) PutQuayPassword(ctx context.Context, passwd string) error

PutQuayPassword stores proxy config to storage.

func (Storage) PutQuayUsername

func (s Storage) PutQuayUsername(ctx context.Context, username string) error

PutQuayUsername stores proxy config to storage.

func (Storage) PutReconfigureRequest

func (s Storage) PutReconfigureRequest(ctx context.Context, req neco.UpdateRequest, leaderKey string) error

PutReconfigureRequest stores UpdateRequest to storage and delete worker statuses in a single transaction. leaderKey is the current leader key. If the caller has lost the leadership, this returns ErrNoLeader.

func (Storage) PutRequest

func (s Storage) PutRequest(ctx context.Context, req neco.UpdateRequest, leaderKey string) error

PutRequest stores UpdateRequest to storage leaderKey is the current leader key. If the caller has lost the leadership, this returns ErrNoLeader.

func (Storage) PutSSHPubkey

func (s Storage) PutSSHPubkey(ctx context.Context, key string) error

PutSSHPubkey registers a SSH public key for nodes.

func (Storage) PutSabakanContentsStatus

func (s Storage) PutSabakanContentsStatus(ctx context.Context, st *neco.ContentsUpdateStatus, leaderKey string) error

PutSabakanContentsStatus puts update status of Sabakan contents, only if caller is the leader.

func (Storage) PutSlackNotification

func (s Storage) PutSlackNotification(ctx context.Context, url string) error

PutSlackNotification stores SlackNotification to storage

func (Storage) PutStatus

func (s Storage) PutStatus(ctx context.Context, lrn int, st neco.UpdateStatus) error

PutStatus stores UpdateStatus of a bootserver to storage

func (Storage) PutTeleportAuthToken

func (s Storage) PutTeleportAuthToken(ctx context.Context, token string) error

PutTeleportAuthToken stores auth token

func (Storage) PutUserResourcesContentsStatus

func (s Storage) PutUserResourcesContentsStatus(ctx context.Context, st *neco.ContentsUpdateStatus, leaderKey string) error

PutUserResourcesContentsStatus puts update status of user-defined resources, only if caller is the leader.

func (Storage) PutVaultRootToken

func (s Storage) PutVaultRootToken(ctx context.Context, token string) error

PutVaultRootToken stores vault root token to storage

func (Storage) PutVaultUnsealKey

func (s Storage) PutVaultUnsealKey(ctx context.Context, key string) error

PutVaultUnsealKey stores vault unseal key to storage

func (Storage) PutWorkerTimeout

func (s Storage) PutWorkerTimeout(ctx context.Context, d time.Duration) error

PutWorkerTimeout stores worker-timeout config to storage.

func (Storage) RecordContainerTag

func (s Storage) RecordContainerTag(ctx context.Context, lrn int, name string) error

RecordContainerTag records installed container image tag

func (Storage) RecordDebVersion

func (s Storage) RecordDebVersion(ctx context.Context, lrn int, name string) error

RecordDebVersion records installed debian package version

func (Storage) RegisterBootserver

func (s Storage) RegisterBootserver(ctx context.Context, lrn int) error

RegisterBootserver registers a bootserver with etcd database.

func (Storage) UpdateNecoRelease

func (s Storage) UpdateNecoRelease(ctx context.Context, version, leaderKey string) error

UpdateNecoRelease updates the neco package version with the latest GitHub release.

func (Storage) WaitConfigChange

func (s Storage) WaitConfigChange(ctx context.Context) error

WaitConfigChange waits config key change and return a non-nil error.

func (Storage) WaitInfo

func (s Storage) WaitInfo(ctx context.Context, rev int64) error

WaitInfo waits for update of keys under `info/`

func (Storage) WaitRequest

func (s Storage) WaitRequest(ctx context.Context, rev int64) (*neco.UpdateRequest, int64, error)

WaitRequest waits for a UpdateRequest to be written to etcd and returns it.

func (Storage) WaitRequestDeletion

func (s Storage) WaitRequestDeletion(ctx context.Context, rev int64) error

WaitRequestDeletion waits for a UpdateRequest to be deleted.

type WorkerWatcher

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

WorkerWatcher has callback handlers to handle status changes

func NewWorkerWatcher

func NewWorkerWatcher(
	handleStatus func(context.Context, int, *neco.UpdateStatus) bool,
) WorkerWatcher

NewWorkerWatcher creates a new WorkerWatcher

func (WorkerWatcher) Watch

func (w WorkerWatcher) Watch(ctx context.Context, rev int64, storage Storage) error

Watch watches worker changes until deadline is reached. If the handleStatus returns true, this returns nil. Otherwise non-nil error is returned.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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