update

package
v0.0.0-...-3bfe646 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

This file implements richer support for working with operation phases

This file implements a generic FSM update engine

Copyright 2018 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

This file implements a controller to run an update operation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMachine

func NewMachine(ctx context.Context, config Config, engine *Engine) (*fsm.FSM, error)

NewMachine returns a new state machine for an update operation.

func ResolvePlan

func ResolvePlan(plan *storage.OperationPlan)

ResolvePlan resolves dependencies between phases and renders IDs as absolute in the specified plan

func Retry

func Retry(ctx context.Context, fn func() error, timeout time.Duration) error

Retry runs the specified function fn. If the function fails, it is retried for the given timeout using exponential backoff

func SplitServers

func SplitServers(servers []storage.UpdateServer) (masters, nodes []storage.UpdateServer)

SplitServers splits the specified server list into servers with master cluster role and regular nodes.

func SyncChangelog

func SyncChangelog(src storage.Backend, dst storage.Backend, clusterName string, operationID string) error

SyncChangelog will sync changelog entries from src to dst storage

func SyncOperationPlan

func SyncOperationPlan(src storage.Backend, dst storage.Backend, plan storage.OperationPlan, operation storage.SiteOperation) error

SyncOperationPlan will synchronize the specified operation and its plan from source to destination backend

func WaitForEndpoints

func WaitForEndpoints(ctx context.Context, client corev1.CoreV1Interface, server storage.Server) error

WaitForEndpoints waits for service endpoints to become active for the server specified with nodeID. nodeID is assumed to be the name of the node as accepted by Kubernetes

Types

type Config

type Config struct {
	// Operation references the update operation
	Operation *ops.SiteOperation
	// Operator is the cluster operator service
	Operator ops.Operator
	// Backend specifies the cluster backend
	Backend storage.Backend
	// LocalBackend specifies the authoritative source for operation state
	LocalBackend storage.Backend
	// Runner specifies the runner for remote commands
	Runner rpc.AgentRepository
	// FieldLogger is the logger to use
	log.FieldLogger
	// Silent controls whether the process outputs messages to stdout
	localenv.Silent
}

Config describes configuration for executing an update operation

func (*Config) CheckAndSetDefaults

func (r *Config) CheckAndSetDefaults() error

CheckAndSetDefaults validates this object and sets defaults where necessary

type Dispatcher

type Dispatcher interface {
	// Dispatch returns an executor for the given parameters and the specified remote
	Dispatch(fsm.ExecutorParams, fsm.Remote) (fsm.PhaseExecutor, error)
}

Dispatcher routes the set of execution parameters to a specific operation phase

type Engine

type Engine struct {
	// Config specifies engine configuration
	Config
	// Silent controls whether the log output is verbose
	localenv.Silent
	// contains filtered or unexported fields
}

Engine is the updater engine

func NewEngine

func NewEngine(ctx context.Context, config Config, dispatcher Dispatcher) (*Engine, error)

NewEngine returns a new update engine using the given dispatcher to dispatch phases

func (*Engine) ChangePhaseState

func (r *Engine) ChangePhaseState(ctx context.Context, change fsm.StateChange) error

ChangePhaseState creates a new changelog entry

func (*Engine) Complete

func (r *Engine) Complete(ctx context.Context, fsmErr error) error

Complete marks the operation as either completed or failed based on the state of the operation plan

func (*Engine) GetExecutor

func (r *Engine) GetExecutor(params fsm.ExecutorParams, remote fsm.Remote) (fsm.PhaseExecutor, error)

GetExecutor returns a new executor based on the provided parameters

func (*Engine) GetPlan

func (r *Engine) GetPlan() (*storage.OperationPlan, error)

GetPlan returns the most up-to-date operation plan

func (*Engine) RunCommand

func (r *Engine) RunCommand(ctx context.Context, runner rpc.RemoteRunner, server storage.Server, params fsm.Params) error

RunCommand executes the phase specified by params on the specified server using the provided runner

func (*Engine) UpdateProgress

func (r *Engine) UpdateProgress(ctx context.Context, params fsm.Params) error

UpdateProgress creates an appropriate progress entry in the operator

type LocalPackageService

type LocalPackageService interface {
	pack.PackageService
	UnpackedPath(loc.Locator) (path string, err error)
	UnpackWithOptions(loc loc.Locator, targetDir string, opts *archive.TarOptions) error
	GetPackageManifest(loc loc.Locator) (*pack.Manifest, error)
}

LocalPackageService defines a package service on local host

type ParentPhase

type ParentPhase interface {
	ChildLiteral(sub string) string
}

type Phase

type Phase storage.OperationPhase

Phase aliases the operation phase object from lib/storage

func RootPhase

func RootPhase(sub Phase) Phase

RootPhase makes the specified phase root

func (*Phase) Add

func (p *Phase) Add(subs ...Phase)

Add adds the specified sub-phases without dependency

func (*Phase) AddParallel

func (p *Phase) AddParallel(subs ...Phase)

AddParallel will append sub-phases which depend on parent only

func (*Phase) AddSequential

func (p *Phase) AddSequential(subs ...Phase)

AddSequential will append sub-phases which depend one upon another

func (*Phase) AddWithDependency

func (p *Phase) AddWithDependency(dep PhaseIder, subs ...Phase)

AddWithDependency sets phase as explicit dependency on subs

func (*Phase) Child

func (p *Phase) Child(sub Phase) string

Child formats sub as a child of this phase and returns the path

func (*Phase) ChildLiteral

func (p *Phase) ChildLiteral(sub string) string

ChildLiteral formats sub as a child of this phase and returns the path

func (Phase) GetID

func (p Phase) GetID() string

GetID returns this phase's ID. implements PhaseDependency

func (*Phase) Require

func (p *Phase) Require(reqs ...PhaseIder) *Phase

Require adds the specified phases reqs as requirements for this phase

func (*Phase) RequireLiteral

func (p *Phase) RequireLiteral(ids ...string) *Phase

RequireLiteral adds the specified phase IDs as requirements for this phase

type PhaseIder

type PhaseIder interface {
	// GetID identifies the phase by ID
	GetID() string
}

PhaseIder is an interface to identify phases

type PhaseRef

type PhaseRef string

PhaseRef refers to a phase by ID

func DependencyForServer

func DependencyForServer(phase Phase, server storage.Server) PhaseRef

DependencyForServer looks up a dependency in the list of sub-phases of the give phase that references the specified server and returns a reference to it. If no server has been found, it retruns the reference to the phase itself

func (PhaseRef) GetID

func (r PhaseRef) GetID() string

GetID returns the ID of the phase. implements PhaseIder

type Phases

type Phases []Phase

Phases is a list of Phase

func (Phases) AsPhases

func (r Phases) AsPhases() (result []storage.OperationPhase)

AsPhases converts this list to a slice of storate.OperationPhase

type Reconciler

type Reconciler interface {
	// ReconcilePlan syncs changes for the specified plan and returns the updated plan
	ReconcilePlan(context.Context, storage.OperationPlan) (*storage.OperationPlan, error)
}

Reconciler can sync plan changes between backends

func NewDefaultReconciler

func NewDefaultReconciler(remote, authoritative storage.Backend, clusterName, operationID string, logger logrus.FieldLogger) Reconciler

NewDefaultReconciler returns an implementation of Reconciler that syncs changes between the authoritative and the remote backends

type Updater

type Updater struct {
	// Config defines the updater configuration
	Config
	// contains filtered or unexported fields
}

Updater manages the operation specified with machine

func NewUpdater

func NewUpdater(ctx context.Context, config Config, machine *fsm.FSM) (*Updater, error)

NewUpdater returns a new updater for the specified operation using the given machine

func (*Updater) Activate

func (r *Updater) Activate() error

Activate activates the cluster.

func (*Updater) Check

func (r *Updater) Check(params fsm.Params) error

Check validates the provided FSM parameters.

func (*Updater) Close

func (r *Updater) Close() error

Close closes the underlying FSM

func (*Updater) Complete

func (r *Updater) Complete(ctx context.Context, fsmErr error) error

Complete completes the active operation

func (*Updater) GetPlan

func (r *Updater) GetPlan() (*storage.OperationPlan, error)

GetPlan returns the up-to-date operation plan

func (*Updater) RollbackPhase

func (r *Updater) RollbackPhase(ctx context.Context, params fsm.Params, phaseTimeout time.Duration) error

RollbackPhase rolls back the specified phase.

func (*Updater) Run

func (r *Updater) Run(ctx context.Context) (err error)

Run executes the operation plan to completion

func (*Updater) RunPhase

func (r *Updater) RunPhase(ctx context.Context, phase string, phaseTimeout time.Duration, force bool) error

RunPhase runs the specified phase.

func (*Updater) SetPhase

func (r *Updater) SetPhase(ctx context.Context, phase, state string) error

SetPhase sets phase state without executing it.

Directories

Path Synopsis
internal
builder
Package builder implements richer support for working with operation phases
Package builder implements richer support for working with operation phases
rollingupdate
This file implements a rolling update FSM
This file implements a rolling update FSM

Jump to

Keyboard shortcuts

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