roll

package
v0.0.0-...-8223eb1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: Apache-2.0 Imports: 30 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RetryOrQuit

func RetryOrQuit(ctx context.Context, f func() error, logger logging.Logger, errtext string) bool

retries a given function until it returns a nil error or the quit channel is closed. returns true if it exited in the former case, false in the latter. errors are sent to the given logger with the given string as the message.

Types

type Factory

type Factory interface {
	New(roll_fields.Update, logging.Logger, consul.Session) Update
}

type Farm

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

The Farm is responsible for spawning and reaping rolling updates as they are added to and deleted from Consul. Multiple farms can exist simultaneously, but each one must hold a different Consul session. This ensures that the farms do not instantiate the same rolling update multiple times.

Roll farms take an RC selector that is used to decide whether this farm should pick up a particular RU request. This can be used to assist in RU partitioning of work or to create test environments. Note that this is _not_ required for RU farms to cooperatively schedule work.

func NewFarm

func NewFarm(
	factory Factory,
	store Store,
	rls RollingUpdateStore,
	rcs RCGetter,
	sessions <-chan string,
	logger logging.Logger,
	labeler rc.Labeler,
	rcSelector klabels.Selector,
	txner transaction.Txner,
	config FarmConfig,
	alerter alerting.Alerter,
) *Farm

func (*Farm) Start

func (rlf *Farm) Start(quit <-chan struct{})

Start is a blocking function that monitors Consul for updates. The Farm will attempt to claim updates as they appear and, if successful, will start goroutines for those updates to do their job. Closing the quit channel will cause this function to return, releasing all locks it holds.

Start is not safe for concurrent execution. Do not execute multiple concurrent instances of Start.

type FarmConfig

type FarmConfig struct {
	// ShouldCreateAuditLogRecords determines whether the farm will create audit
	// log records when deleting a rolling update, which occurs after completing
	// the RU
	ShouldCreateAuditLogRecords bool
}

FarmConfig contains configuration options for the farm. All fields have safe defaults

type Labeler

type Labeler interface {
	rc.LabelMatcher
	audit.Labeler
}

type RCGetter

type RCGetter interface {
	Get(id fields.ID) (fields.RC, error)
}

type RCStatusStore

type RCStatusStore interface {
	Get(rcID rcf.ID) (rcstatus.Status, *api.QueryMeta, error)
}

type ReplicationControllerLocker

type ReplicationControllerLocker interface {
	LockForMutationTxn(
		lockCtx context.Context,
		rcID rcf.ID,
		session consul.Session,
	) (consul.TxnUnlocker, error)
}

type ReplicationControllerStore

type ReplicationControllerStore interface {
	Get(id rcf.ID) (rcf.RC, error)
	SetDesiredReplicas(id rcf.ID, n int) error
	Delete(id rcf.ID, force bool) error
	DeleteTxn(ctx context.Context, id rcf.ID, force bool) error
	TransferReplicaCounts(ctx context.Context, req rcstore.TransferReplicaCountsRequest) error
	DisableTxn(ctx context.Context, id rcf.ID) error
	EnableTxn(ctx context.Context, id rcf.ID) error
}

type RollingUpdateStore

type RollingUpdateStore interface {
	Watch(quit <-chan struct{}, jitterWindow time.Duration) (<-chan []roll_fields.Update, <-chan error)
	Delete(ctx context.Context, id roll_fields.ID) error
}

type ServiceWatcher

type ServiceWatcher interface {
	WatchService(
		ctx context.Context,
		serviceID string,
		resultCh chan<- map[types.NodeName]health.Result,
		errCh chan<- error,
		watchDelay time.Duration,
	)
	Service(
		serviceID string,
	) (map[types.NodeName]health.Result, error)
}

type Store

type Store interface {
	SetPod(podPrefix consul.PodPrefix, nodename types.NodeName, manifest manifest.Manifest) (time.Duration, error)
	Pod(podPrefix consul.PodPrefix, nodename types.NodeName, podId types.PodID) (manifest.Manifest, time.Duration, error)
	DeletePod(podPrefix consul.PodPrefix, nodename types.NodeName, podId types.PodID) (time.Duration, error)
	NewUnmanagedSession(session, name string) consul.Session
}

type Update

type Update interface {
	// Run will execute the Update and modify the passed context such that
	// its transaction removes the old RC upon completion. Run should claim
	// exclusive ownership of both affected RCs, and release that
	// exclusivity upon completion. Run is long-lived and blocking;
	// canceling the context causes it to terminate it early. If an Update
	// is interrupted or encounters an unrecoverable error such as a
	// transaction violation, Run should leave the RCs in a state such that
	// it can later be called again to resume. The return value indicates
	// if the update completed (true) or if it was terminated early
	// (false).
	Run(ctx context.Context) bool
}

func NewUpdate

func NewUpdate(
	f fields.Update,
	consuls Store,
	consulClient consulutil.ConsulClient,
	rcLocker ReplicationControllerLocker,
	rcStore ReplicationControllerStore,
	rcStatusStore RCStatusStore,
	rollStore RollingUpdateStore,
	txner transaction.Txner,
	hcheck ServiceWatcher,
	labeler Labeler,
	logger logging.Logger,
	session consul.Session,
	watchDelay time.Duration,
	alerter alerting.Alerter,
	shouldCreateAuditLogRecords bool,
	auditLogStore auditlogstore.ConsulStore,
) Update

Create a new Update. The consul.Store, rcstore.Store, and labels.Applicator arguments should be the same as those of the RCs themselves. The session must be valid for the lifetime of the Update; maintaining this is the responsibility of the caller.

type UpdateFactory

type UpdateFactory struct {
	Store         Store
	Client        consulutil.ConsulClient
	Txner         transaction.Txner
	RCLocker      ReplicationControllerLocker
	RCStore       ReplicationControllerStore
	RCStatusStore RCStatusStore
	RollStore     RollingUpdateStore
	HealthChecker checker.HealthChecker
	Labeler       labeler
	WatchDelay    time.Duration
	Alerter       alerting.Alerter

	ShouldCreateAuditLogRecords bool
	AuditLogStore               auditlogstore.ConsulStore
}

func NewUpdateFactory

func NewUpdateFactory(
	store Store,
	consulClient consulutil.ConsulClient,
	txner transaction.Txner,
	rcLocker ReplicationControllerLocker,
	rcStore ReplicationControllerStore,
	rcStatusStore RCStatusStore,
	rollStore RollingUpdateStore,
	healthChecker checker.HealthChecker,
	labeler labeler,
	watchDelay time.Duration,
	alerter alerting.Alerter,
	auditLogStore auditlogstore.ConsulStore,
	shouldCreateAuditLogRecords bool,
) UpdateFactory

func (UpdateFactory) New

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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