updater

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actor

type Actor interface {
	// ScaleOut creates a new update instance
	ScaleOut(ctx context.Context) error

	// Update will update an instance CR
	// unavailable means update must choose an unavailable instance to update
	Update(ctx context.Context, unavailable bool) error

	// ScaleInOutdated will scale in an outdated instance
	// If unavailable is true, the chosen instance is unavailable
	ScaleInUpdate(ctx context.Context) (unavailable bool, _ error)

	// ScaleInUpdate will scale in an updated instance
	// If unavailable is true, the chosen instance is unavailable
	ScaleInOutdated(ctx context.Context) (unavailable bool, _ error)

	// Cleanup deletes all instances marked as defer deletion
	Cleanup(ctx context.Context) error
}

type AddHook

type AddHook[R runtime.Instance] interface {
	Add(update R) R
}

AddHook a hook executes when add an instance. e.g. for topology scheduling

func AllocateName

func AllocateName[R runtime.Instance](allocator tracker.Allocator) AddHook[R]

AllocateName will set name for new instance If a new name is allocated, it will be recorded until it is observed. This hook is defined to avoid dirty read(no read-after-write consistency) when scale out. For example, when a new item is created but not observed in next reconciliation, updater will create a new one again with a new name. It means an unexpected item may be created. This hook can ensure that updater will try to create the item again if it is not observed

type AddHookFunc

type AddHookFunc[PT runtime.Instance] func(update PT) PT

func (AddHookFunc[PT]) Add

func (f AddHookFunc[PT]) Add(update PT) PT

type Builder

type Builder[R runtime.Instance] interface {
	WithInstances(...R) Builder[R]
	WithDesired(desired int) Builder[R]
	WithMaxSurge(maxSurge int) Builder[R]
	WithMaxUnavailable(maxUnavailable int) Builder[R]
	WithRevision(rev string) Builder[R]
	WithClient(c client.Client) Builder[R]
	WithNewFactory(NewFactory[R]) Builder[R]
	WithAddHooks(hooks ...AddHook[R]) Builder[R]
	WithUpdateHooks(hooks ...UpdateHook[R]) Builder[R]
	WithDelHooks(hooks ...DelHook[R]) Builder[R]
	WithScaleInPreferPolicy(ps ...PreferPolicy[R]) Builder[R]
	WithUpdatePreferPolicy(ps ...PreferPolicy[R]) Builder[R]
	// NoInPlaceUpdate if true, actor will use Scale in and Scale out to replace Update operation
	WithNoInPaceUpdate(noUpdate bool) Builder[R]
	// MinReadySeconds means instances are available only when they keep ready more than minReadySeconds
	WithMinReadySeconds(minReadySeconds int64) Builder[R]
	Build() Executor
}

func New

func New[T runtime.Tuple[O, R], O client.Object, R runtime.Instance]() Builder[R]

type DelHook

type DelHook[R runtime.Instance] interface {
	Delete(name string)
}

type DelHookFunc

type DelHookFunc[PT runtime.Instance] func(name string)

func (DelHookFunc[PT]) Delete

func (f DelHookFunc[PT]) Delete(name string)

type Executor

type Executor interface {
	Do(ctx context.Context) (bool, error)
}

Executor is an executor that updates the instances. TODO: return instance list after Do

func NewExecutor

func NewExecutor(
	act Actor,
	update,
	outdated,
	desired,
	unavailableUpdate,
	unavailableOutdated,
	maxSurge,
	maxUnavailable int,
) Executor

type Metadata

type Metadata struct {
	ResourceVersion string             `json:"resourceVersion"`
	Annotations     map[string]*string `json:"annotations,omitempty"`
}

type NewFactory

type NewFactory[R runtime.Instance] interface {
	// New will generate a new object for scaling out and update.
	New() R
	// Adopt is only called when scaling out.
	// UnlockFunc will be called if apply is failed.
	// If no obj can be adopted, obj is nil and exists is false.
	//
	// This interface cannot ensure that R is a pointer(of course it is), so a
	// return val 'exists' is added to check whether the obj is nil.
	// We can add a new generic type param(runtime.InstanceSet) to ensure that R is a pointer, but it changes too much.
	Adopt() (obj R, fn UnlockFunc, exists bool)
}

NewFactory try to New a object to scale out The object returned by New may be - Doesn't exist, the obj will be created - Exists but is not managed, the obj will be adpoted The adopting obj will be locked until apply is done If apply is failed, we should call unlock to release the adopting object, so that it can be adopted by others.

type NewFunc

type NewFunc[R runtime.Instance] func() R

func (NewFunc[R]) Adopt

func (f NewFunc[R]) Adopt() (obj R, fn UnlockFunc, exists bool)

func (NewFunc[R]) New

func (f NewFunc[R]) New() R

type Patch

type Patch struct {
	Metadata Metadata `json:"metadata"`
	Spec     *Spec    `json:"spec,omitempty"`
}

type PreferPolicy

type PreferPolicy[R runtime.Instance] interface {
	Prefer([]R) []R
}

func PreferNotRunning

func PreferNotRunning[R runtime.Instance]() PreferPolicy[R]

func PreferUnready

func PreferUnready[R runtime.Instance]() PreferPolicy[R]

type PreferPolicyFunc

type PreferPolicyFunc[R runtime.Instance] func([]R) []R

func (PreferPolicyFunc[R]) Prefer

func (f PreferPolicyFunc[R]) Prefer(in []R) []R

type Score

type Score uint32

type ScoredPreferPolicy

type ScoredPreferPolicy[R runtime.Instance] interface {
	Score() Score
	Prefer([]R) []R
}

type Selector

type Selector[R runtime.Instance] interface {
	Choose([]R) string
}

func NewSelector

func NewSelector[R runtime.Instance](ps ...PreferPolicy[R]) Selector[R]

type Spec

type Spec struct {
	Offline bool `json:"offline"`
}

type State

type State[R runtime.Instance] interface {
	Add(obj R)
	Del(name string) R
	Get(name string) R
	List() []R
	Len() int
}

func NewState

func NewState[R runtime.Instance](instances []R) State[R]

type UnlockFunc

type UnlockFunc func()

type UpdateHook

type UpdateHook[R runtime.Instance] interface {
	Update(update, outdated R) R
}

UpdateHook a hook executes when update an instance. e.g. for some write once fields(name, topology, etc.)

func KeepName

func KeepName[R runtime.Instance]() UpdateHook[R]

KeepName does not change name when update obj

func KeepResourceVersion

func KeepResourceVersion[R runtime.Instance]() UpdateHook[R]

KeepResourceVersion set resourceVersion when update obj

func KeepTopology

func KeepTopology[R runtime.Instance]() UpdateHook[R]

KeepTopology does not change topology when update obj

type UpdateHookFunc

type UpdateHookFunc[R runtime.Instance] func(update, outdated R) R

func (UpdateHookFunc[R]) Update

func (f UpdateHookFunc[R]) Update(update, outdated R) R

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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