controllers

package
v0.38.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 50 Imported by: 0

Documentation

Index

Constants

View Source
const OutcomeLabel = "outcome"

Variables

This section is empty.

Functions

func DeepEqual

func DeepEqual(v1, v2 interface{}) bool

func MemslotIdxFromName

func MemslotIdxFromName(name string) (int, error)

MemslotIdxFromName takes "/objects/memslot3" or "memslot3 and returns 3

func QmpAddMemoryBackend

func QmpAddMemoryBackend(mon QMPRunner, idx int, sizeBytes int64) error

QmpAddMemoryBackend adds a single memory slot to the VM with the given size.

The memory slot does nothing until a corresponding "device" is added to the VM for the same memory slot. See QmpAddMemoryDevice for more. When unplugging, QmpDelMemoryDevice must be called before QmpDelMemoryBackend.

func QmpAddMemoryDevice

func QmpAddMemoryDevice(mon *qmp.SocketMonitor, idx int) error

func QmpAddr

func QmpAddr(vm *vmv1.VirtualMachine) (ip string, port int32)

func QmpCancelMigration

func QmpCancelMigration(ip string, port int32) error

func QmpConnect

func QmpConnect(ip string, port int32) (*qmp.SocketMonitor, error)

func QmpDelMemoryBackend

func QmpDelMemoryBackend(mon *qmp.SocketMonitor, idx int) error

func QmpDelMemoryDevice

func QmpDelMemoryDevice(mon *qmp.SocketMonitor, idx int) error

func QmpGetCpus

func QmpGetCpus(ip string, port int32) ([]QmpCpuSlot, []QmpCpuSlot, error)

func QmpGetMemorySize

func QmpGetMemorySize(ip string, port int32) (*resource.Quantity, error)

func QmpPlugCpu

func QmpPlugCpu(ip string, port int32) error

func QmpQueryMemoryBackendIds

func QmpQueryMemoryBackendIds(mon *qmp.SocketMonitor) (map[int]struct{}, error)

func QmpQuit

func QmpQuit(ip string, port int32) error

func QmpSetMemorySlots

func QmpSetMemorySlots(
	ctx context.Context,
	vm *vmv1.VirtualMachine,
	targetCnt int,
	recorder record.EventRecorder,
) (int, error)

QmpSetMemorySlots attempts to plug/unplug memory slots to match targetCnt.

Returns the number of slots, which the function managed to plug. Ideally, it matches targetCnt, but can be less or more if there are errors.

Returns -1 if failed to father current state of memory, otherwise, the return value is valid even if there are errors.

In order for the hotplug to occur, we have to do two things: 1. Plug memory backend (memslot<n>) - a QEMU object, which physically allocates the memory from host 2. Plug DIMM device (dimm<n>) - a device, which exposes the memory to the host. dimm<n> is always plugged into memslot<n> with the same n.

In order to do hotunplug, we need to make the same actions in the reversed order.

func QmpSetVirtioMem

func QmpSetVirtioMem(vm *vmv1.VirtualMachine, targetVirtioMemSize int64) (previous int64, _ error)

QmpSetVirtioMem updates virtio-mem to the new target size, returning the previous target.

If the new target size is equal to the previous one, this function does nothing but query the target.

func QmpStartMigration

func QmpStartMigration(virtualmachine *vmv1.VirtualMachine, virtualmachinemigration *vmv1.VirtualMachineMigration) error

func QmpSyncCpuToTarget

func QmpSyncCpuToTarget(vm *vmv1.VirtualMachine, migration *vmv1.VirtualMachineMigration) error

func QmpSyncMemoryToTarget

func QmpSyncMemoryToTarget(vm *vmv1.VirtualMachine, migration *vmv1.VirtualMachineMigration) error

func QmpUnplugCpu

func QmpUnplugCpu(ip string, port int32) error

Types

type FailingRefresher

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

FailingRefresher is a wrapper, which implements manager.Runnable

func (FailingRefresher) Start

func (f FailingRefresher) Start(ctx context.Context) error

type MigrationInfo

type MigrationInfo struct {
	Status      string `json:"status"`
	TotalTimeMs int64  `json:"total-time"`
	SetupTimeMs int64  `json:"setup-time"`
	DowntimeMs  int64  `json:"downtime"`
	Ram         struct {
		Transferred    int64 `json:"transferred"`
		Remaining      int64 `json:"remaining"`
		Total          int64 `json:"total"`
		Duplicate      int64 `json:"duplicate"`
		Normal         int64 `json:"normal"`
		NormalBytes    int64 `json:"normal-bytes"`
		DirtySyncCount int64 `json:"dirty-sync-count"`
	} `json:"ram"`
	Compression struct {
		CompressedSize  int64   `json:"compressed-size"`
		CompressionRate float64 `json:"compression-rate"`
	} `json:"compression"`
}

func QmpGetMigrationInfo

func QmpGetMigrationInfo(ip string, port int32) (*MigrationInfo, error)

type QMPRunner

type QMPRunner interface {
	Run([]byte) ([]byte, error)
}

type QmpCpuSlot

type QmpCpuSlot struct {
	Core int32  `json:"core"`
	QOM  string `json:"qom"`
	Type string `json:"type"`
}

type QmpCpus

type QmpCpus struct {
	Return []struct {
		Props struct {
			CoreId   int32 `json:"core-id"`
			ThreadId int32 `json:"thread-id"`
			SocketId int32 `json:"socket-id"`
		} `json:"props"`
		VcpusCount int32   `json:"vcpus-count"`
		QomPath    *string `json:"qom-path"`
		Type       string  `json:"type"`
	} `json:"return"`
}

type QmpMemoryDevice

type QmpMemoryDevice struct {
	Type string `json:"type"`
	Data struct {
		Memdev       string `json:"memdev"`
		Hotplugged   bool   `json:"hotplugged"`
		Addr         int64  `json:"addr"`
		Hotplugguble bool   `json:"hotpluggable"`
		Size         int64  `json:"size"`
		Slot         int64  `json:"slot"`
		Node         int64  `json:"node"`
		Id           string `json:"id"`
	} `json:"data"`
}

func QmpMonQueryMemoryDevices

func QmpMonQueryMemoryDevices(mon *qmp.SocketMonitor) ([]QmpMemoryDevice, error)

func QmpQueryMemoryDevices

func QmpQueryMemoryDevices(ip string, port int32) ([]QmpMemoryDevice, error)

type QmpMemoryDevices

type QmpMemoryDevices struct {
	Return []QmpMemoryDevice `json:"return"`
}

type QmpMemorySetter

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

func (*QmpMemorySetter) AddBackends

func (r *QmpMemorySetter) AddBackends()

func (*QmpMemorySetter) AddDevices

func (r *QmpMemorySetter) AddDevices()

func (*QmpMemorySetter) Disconnect

func (r *QmpMemorySetter) Disconnect()

func (*QmpMemorySetter) RemoveBackends

func (r *QmpMemorySetter) RemoveBackends()

func (*QmpMemorySetter) RemoveDevices

func (r *QmpMemorySetter) RemoveDevices()

type QmpMemorySize

type QmpMemorySize struct {
	Return struct {
		BaseMemory    int64 `json:"base-memory"`
		PluggedMemory int64 `json:"plugged-memory"`
	} `json:"return"`
}

type QmpMigrationInfo

type QmpMigrationInfo struct {
	Return MigrationInfo `json:"return"`
}

type QmpObject

type QmpObject struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

type QmpObjects

type QmpObjects struct {
	Return []QmpObject `json:"return"`
}

type ReconcileOutcome

type ReconcileOutcome string
const (
	SuccessOutcome  ReconcileOutcome = "success"
	FailureOutcome  ReconcileOutcome = "failure"
	ConflictOutcome ReconcileOutcome = "conflict"
)

type ReconcileSnapshot

type ReconcileSnapshot struct {
	// ControllerName is the name of the controller: virtualmachine or virtualmachinemigration.
	ControllerName string `json:"controllerName"`

	// Failing is the list of objects currently failing to reconcile
	Failing []string `json:"failing"`

	// Conflicting is the list of objects currently failing to reconcile
	// due to a conflict
	Conflicting []string `json:"conflicting"`
}

ReconcileSnapshot provides a glimpse into the current state of ongoing reconciles

This type is (transitively) returned by the controller's "dump state" HTTP endpoint, and exists to allow us to get deeper information on the metrics - we can't expose information for every VirtualMachine into the metrics (it'd be too high cardinality), but we *can* make it available when requested.

type ReconcilerConfig

type ReconcilerConfig struct {
	// DisableRunnerCgroup, if true, disables running QEMU in a cgroup in new VM runner pods.
	// Fractional CPU scaling will continue to *pretend* to work, but it will not do anything in
	// practice.
	//
	// Under the hood, this results in passing -skip-cgroup-management and -enable-dummy-cpu-server
	// to neonvm-runner.
	DisableRunnerCgroup bool

	MaxConcurrentReconciles int

	// SkipUpdateValidationFor is the set of object names that we should ignore when doing webhook
	// update validation.
	SkipUpdateValidationFor map[types.NamespacedName]struct{}

	// QEMUDiskCacheSettings sets the values of the 'cache.*' settings used for QEMU disks.
	//
	// This field is passed to neonvm-runner as the `-qemu-disk-cache-settings` arg, and is directly
	// used in setting up the VM disks via QEMU's `-drive` flag.
	QEMUDiskCacheSettings string

	// DefaultMemoryProvider is the memory provider (dimm slots or virtio-mem) that will be used for
	// new VMs (or, when old ones restart) if nothing is explicitly set.
	DefaultMemoryProvider vmv1.MemoryProvider

	// MemhpAutoMovableRatio specifies the value that new neonvm-runners will set as the
	// kernel's 'memory_hotplug.auto_movable_ratio', iff the memory provider is virtio-mem.
	//
	// This value is passed directly to neonvm-runner as the '-memhp-auto-movable-ratio' flag.
	// We've confirmed sensible values are from 301 to 801 (i.e. 3.01:1 through 8.01:1).
	// The range of sensible values may extend further, but we have not tested that.
	MemhpAutoMovableRatio string

	// FailurePendingPeriod is the period for the propagation of
	// reconciliation failures to the observability instruments
	FailurePendingPeriod time.Duration

	// FailingRefreshInterval is the interval between consecutive
	// updates of metrics and logs, related to failing reconciliations
	FailingRefreshInterval time.Duration

	// AtMostOnePod is the flag that indicates whether we should only have one pod per VM.
	AtMostOnePod bool
	// DefaultCPUScalingMode is the default CPU scaling mode that will be used for VMs with empty spec.cpuScalingMode
	DefaultCPUScalingMode vmv1.CpuScalingMode
}

ReconcilerConfig stores shared configuration for VirtualMachineReconciler and VirtualMachineMigrationReconciler.

type ReconcilerMetrics

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

func MakeReconcilerMetrics

func MakeReconcilerMetrics() ReconcilerMetrics

func (ReconcilerMetrics) ObserveReconcileDuration

func (m ReconcilerMetrics) ObserveReconcileDuration(
	outcome ReconcileOutcome,
	duration time.Duration,
)

type ReconcilerWithMetrics

type ReconcilerWithMetrics interface {
	reconcile.Reconciler

	Snapshot() ReconcileSnapshot
	FailingRefresher() FailingRefresher
}

ReconcilerWithMetrics is a Reconciler produced by WithMetrics that can return a snapshot of the state backing the metrics.

func WithMetrics

func WithMetrics(
	reconciler reconcile.Reconciler,
	rm ReconcilerMetrics,
	cntrlName string,
	failurePendingPeriod time.Duration,
	refreshFailingInterval time.Duration,
) ReconcilerWithMetrics

WithMetrics wraps a given Reconciler with metrics capabilities.

The returned reconciler also provides a way to get a snapshot of the state of ongoing reconciles, to see the data backing the metrics.

type VMMigrationWebhook

type VMMigrationWebhook struct {
	Recorder record.EventRecorder
	Config   *ReconcilerConfig
}

func (*VMMigrationWebhook) Default

func (w *VMMigrationWebhook) Default(ctx context.Context, obj runtime.Object) error

Default implements webhook.CustomDefaulter

func (*VMMigrationWebhook) SetupWithManager

func (w *VMMigrationWebhook) SetupWithManager(mgr ctrl.Manager) error

func (*VMMigrationWebhook) ValidateCreate

func (w *VMMigrationWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error)

ValidateCreate implements webhook.CustomValidator

func (*VMMigrationWebhook) ValidateDelete

func (w *VMMigrationWebhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error)

ValidateDelete implements webhook.CustomValidator

func (*VMMigrationWebhook) ValidateUpdate

func (w *VMMigrationWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error)

ValidateUpdate implements webhook.CustomValidator

type VMReconciler

type VMReconciler struct {
	client.Client
	Scheme   *runtime.Scheme
	Recorder record.EventRecorder
	Config   *ReconcilerConfig

	Metrics ReconcilerMetrics `exhaustruct:"optional"`
}

VMReconciler reconciles a VirtualMachine object

func (*VMReconciler) Reconcile

func (r *VMReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

It is essential for the controller's reconciliation loop to be idempotent. By following the Operator pattern you will create Controllers which provide a reconcile function responsible for synchronizing resources until the desired state is reached on the cluster. Breaking this recommendation goes against the design principles of controller-runtime. and may lead to unforeseen consequences such as resources becoming stuck and requiring manual intervention. For further info: - About Operator Pattern: https://kubernetes.io/docs/concepts/extend-kubernetes/operator/ - About Controllers: https://kubernetes.io/docs/concepts/architecture/controller/ - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.13.0/pkg/reconcile

func (*VMReconciler) SetupWithManager

func (r *VMReconciler) SetupWithManager(mgr ctrl.Manager) (ReconcilerWithMetrics, error)

SetupWithManager sets up the controller with the Manager. Note that the Runner Pod will be also watched in order to ensure its desirable state on the cluster

type VMWebhook

type VMWebhook struct {
	Recorder record.EventRecorder
	Config   *ReconcilerConfig
}

func (*VMWebhook) Default

func (w *VMWebhook) Default(ctx context.Context, obj runtime.Object) error

Default implements webhook.CustomDefaulter

func (*VMWebhook) SetupWithManager

func (w *VMWebhook) SetupWithManager(mgr ctrl.Manager) error

func (*VMWebhook) ValidateCreate

func (w *VMWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error)

ValidateCreate implements webhook.CustomValidator

func (*VMWebhook) ValidateDelete

func (w *VMWebhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error)

ValidateDelete implements webhook.CustomValidator

func (*VMWebhook) ValidateUpdate

func (w *VMWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error)

ValidateUpdate implements webhook.CustomValidator

type VirtualMachineMigrationReconciler

type VirtualMachineMigrationReconciler struct {
	client.Client
	Scheme   *runtime.Scheme
	Recorder record.EventRecorder
	Config   *ReconcilerConfig

	Metrics ReconcilerMetrics
}

VirtualMachineMigrationReconciler reconciles a VirtualMachineMigration object

func (*VirtualMachineMigrationReconciler) Reconcile

It is essential for the controller's reconciliation loop to be idempotent. By following the Operator pattern you will create Controllers which provide a reconcile function responsible for synchronizing resources until the desired state is reached on the cluster. Breaking this recommendation goes against the design principles of controller-runtime. and may lead to unforeseen consequences such as resources becoming stuck and requiring manual intervention. For further info: - About Operator Pattern: https://kubernetes.io/docs/concepts/extend-kubernetes/operator/ - About Controllers: https://kubernetes.io/docs/concepts/architecture/controller/ - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.13.0/pkg/reconcile

func (*VirtualMachineMigrationReconciler) SetupWithManager

SetupWithManager sets up the controller with the Manager. Note that the Pods will be also watched in order to ensure its desirable state on the cluster

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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