conversion

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

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

Go to latest
Published: Jul 12, 2026 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeNotValid          = "TypeNotValid"
	VMNotSet              = "VMNotSet"
	DisksNotSet           = "DisksNotSet"
	ConnectionNotSet      = "ConnectionNotSet"
	VDDKImageNotSet       = "VDDKImageNotSet"
	LUKSSecretNotSet      = "LUKSSecretNotSet"
	TargetNamespaceNotSet = "TargetNamespaceNotSet"
)

Types

View Source
const (
	Required = libcnd.Required
	Advisory = libcnd.Advisory
	Critical = libcnd.Critical
	Error    = libcnd.Error
	Warn     = libcnd.Warn
)

Categories

View Source
const (
	NotSet   = "NotSet"
	NotValid = "NotValid"
)

Reasons

View Source
const (
	True  = libcnd.True
	False = libcnd.False
)

Statuses

View Source
const (
	Name = "conversion"
)

Variables

View Source
var DeepInspectionPipelineStages = []PipelineStage{
	{Stage: api.StageCreateSnapshot, Predicate: snapshotOwnedByController},
	{Stage: api.StageWaitForSnapshot, Predicate: snapshotOwnedByController},
	{Stage: api.StageCreatePod},
	{Stage: api.StagePodRunning},
	{Stage: api.StageFetchingResults},
	{Stage: api.StageRemoveSnapshot, Predicate: snapshotOwnedByController},
	{Stage: api.StageWaitForSnapshotRemoval, Predicate: snapshotOwnedByController},
	{Stage: api.StageFinished},
}

DeepInspectionPipelineStages is the ordered list of stages for DeepInspection workloads. Stages that have a Predicate are skipped when the predicate returns false

View Source
var ErrNoPodFound = errors.New("no matching pod found")

ErrNoPodFound is returned by GetPod / GetPodByLabels when no matching pod exists. Callers that treat "not found" as a non-error condition should check with errors.Is.

View Source
var Settings = &settings.Settings
View Source
var VirtV2vPipelineStages = []PipelineStage{
	{Stage: api.StageCreatePod},
	{Stage: api.StagePodRunning},
	{Stage: api.StageFinished},
}

VirtV2vPipelineStages is the ordered list of stages for Inspection / InPlace / Remote workloads.

Functions

func Add

func Add(mgr manager.Manager) error

Creates a new Conversion Controller and adds it to the Manager.

func DiskRefsFromNames

func DiskRefsFromNames(diskNames []string) []api.DiskRef

DiskRefsFromNames builds DiskRef entries from disk path names.

func DiskRefsFromVolumes

func DiskRefsFromVolumes(volumes []core.Volume, mounts []core.VolumeMount, devices []core.VolumeDevice, pvcs []*core.PersistentVolumeClaim) []api.DiskRef

DiskRefsFromVolumes converts resolved volumes, mounts, devices and PVCs into DiskRef entries for a Conversion CR spec.

func EnsureVirtV2vPod

func EnsureVirtV2vPod(k8sClient client.Client, log logging.LevelLogger, vm *plan.VMStatus, volumes []core.Volume, mounts []core.VolumeMount, devices []core.VolumeDevice, secret *core.Secret, podType convctx.V2vPodType, inPlace bool, cfg convctx.PodConfig) error

EnsureVirtV2vPod creates the conversion or inspection pod if it does not already exist. Helper funvtion for the plan pod creation.

func GetPodByLabels

func GetPodByLabels(k8sClient client.Client, namespace string, labels map[string]string) (*core.Pod, error)

GetPodByLabels returns the first pod matching the given labels in the namespace or nil.

func GovmomiClientFromSecret

func GovmomiClientFromSecret(ctx context.Context, secret *core.Secret) (*govmomi.Client, error)

GovmomiClientFromSecret builds a logged-in govmomi client using credentials and connection parameters stored entirely in secret.Data. Required keys: "url", "user", "password". Optional keys: "fingerprint" (used when insecureSkipVerify is true).

func NetAppShiftDiskPermsInitContainer

func NetAppShiftDiskPermsInitContainer(mounts []core.VolumeMount, image string) core.Container

NetAppShiftDiskPermsInitContainer returns an init container that runs as root and sets ownership/permissions on NetApp Shift-migrated disk images so that virt-v2v can access them as the QEMU user.

func SetKvmOnPodSpec

func SetKvmOnPodSpec(podSpec *core.PodSpec, requestKVM bool)

SetKvmOnPodSpec adds the devices.kubevirt.io/kvm resource request/limit and the kubevirt.io/schedulable node selector when requestKVM is true. This ensures the pod lands on a node with /dev/kvm so the virt-v2v appliance uses hardware virtualisation instead of emulation.

Types

type Builder

type Builder struct {
	Config convctx.PodConfig
}

Builder constructs virt-v2v pod specs from a fully-resolved PodConfig. Callers must populate all PodConfig fields before invoking the builder.

func (*Builder) BuildDeepInspectionPod

func (b *Builder) BuildDeepInspectionPod(vm *plan.VMStatus, volumes []core.Volume, volumeMounts []core.VolumeMount, volumeDevices []core.VolumeDevice, secret *core.Secret) (*core.Pod, error)

BuildDeepInspectionPod builds a pod for DeepInspection conversions.

func (*Builder) BuildDeepInspectionPodEnvironment

func (b *Builder) BuildDeepInspectionPodEnvironment(vm *plan.VMStatus) []core.EnvVar

BuildDeepInspectionPodEnvironment builds environment variables for deep inspection pods. Any SNAPSHOT_MOREF already present in Config.Environment is dropped so the controller value always takes precedent.

func (*Builder) BuildV2vPodEnvironment

func (b *Builder) BuildV2vPodEnvironment(env []core.EnvVar, vm *plan.VMStatus) ([]core.EnvVar, error)

BuildV2vPodEnvironment appends env vars from PodConfig, then adds common variables (memSize, smp, LOCAL_MIGRATION, encryption).

func (*Builder) BuildVirtV2vConversionPod

func (b *Builder) BuildVirtV2vConversionPod(pod *core.Pod, environment []core.EnvVar, vm *plan.VMStatus) error

BuildVirtV2vConversionPod applies conversion-specific settings to a pod.

func (*Builder) BuildVirtV2vInspectionPod

func (b *Builder) BuildVirtV2vInspectionPod(pod *core.Pod, environment []core.EnvVar, vm *plan.VMStatus) (*core.Pod, error)

BuildVirtV2vInspectionPod applies inspection-specific settings to a pod. Inspection env vars must be populated in b.Config.Environment by the caller.

func (*Builder) BuildVirtV2vPod

func (b *Builder) BuildVirtV2vPod(vm *plan.VMStatus, volumes []core.Volume, volumeMounts []core.VolumeMount, volumeDevices []core.VolumeDevice, v2vSecret *core.Secret, podType convctx.V2vPodType, inPlace bool) (pod *core.Pod, err error)

BuildVirtV2vPod is the main entry point that builds a complete pod for either conversion or inspection, calling the type-specific builder for additional settings. All data comes from b.Config.

func (*Builder) GetDeepInspectionPodSpec

func (b *Builder) GetDeepInspectionPodSpec(volumes []core.Volume, volumeMounts []core.VolumeMount, volumeDevices []core.VolumeDevice, secret *core.Secret) (*core.Pod, error)

GetDeepInspectionPodSpec builds a pod spec for the deep inspection

func (*Builder) GetVirtV2vPodSpec

func (b *Builder) GetVirtV2vPodSpec(vm *plan.VMStatus, volumes []core.Volume, volumeMounts []core.VolumeMount, volumeDevices []core.VolumeDevice, v2vSecret *core.Secret, inPlace bool) (pod *core.Pod, environment []core.EnvVar, err error)

GetVirtV2vPodSpec builds the barebones pod spec.

type Client

type Client struct {
	Log   logging.LevelLogger
	VMRef ref.Ref
	// contains filtered or unexported fields
}

Client performs vSphere snapshot operations for a single VM using one vSphere session.

func NewSnapshotClient

func NewSnapshotClient(log logging.LevelLogger, client *govmomi.Client, vmRef ref.Ref) (*Client, error)

NewSnapshotClient creates a snapshot client for the given VM and govmomi session.

func (*Client) CheckCreateTaskReady

func (r *Client) CheckCreateTaskReady(createTaskID string) (ready bool, snapshotID string, err error)

CheckCreateTaskReady waits for a snapshot create task to finish and returns the snapshot MoRef.

func (*Client) CheckRemoveTaskReady

func (r *Client) CheckRemoveTaskReady(removeTaskID string) (ready bool, err error)

CheckRemoveTaskReady waits for a snapshot remove task to finish.

func (*Client) Close

func (r *Client) Close()

Close logs out of the vSphere session.

func (*Client) CreateSnapshot

func (r *Client) CreateSnapshot() (snapshotID string, creationTaskID string, err error)

CreateSnapshot creates a VM snapshot and returns the vSphere create task id.

func (*Client) RemoveSnapshot

func (r *Client) RemoveSnapshot(snapshot string) (taskID string, err error)

RemoveSnapshot removes a snapshot by MoRef value; returns the remove task id.

type ConversionPipeline

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

ConversionPipeline drives reconciliation for a single Conversion CR.

func NewConversionPipeline

func NewConversionPipeline(ctx context.Context, cr *Reconciler, conv *api.Conversion) *ConversionPipeline

NewConversionPipeline builds a pipeline for the conversion type using the matching stage definition.

func (*ConversionPipeline) Run

func (p *ConversionPipeline) Run() (succeeded bool, err error)

Run executes one reconcile step and returns the conversion phase that was reached. When the phase is Pending it first runs runPhasePending, which transitions the conversion to Running or Failed. If the transition succeeds, pipeline immediately executes the first stage in the same reconcile cycle to avoid an extra reconcile. Run executes one reconcile step and returns (true, nil) when all pipeline stages have completed and the pod succeeded. Returns (false, nil) while work is still in progress

type ConversionPredicate

type ConversionPredicate struct {
	predicate.TypedFuncs[*api.Conversion]
}

func (ConversionPredicate) Create

func (ConversionPredicate) Delete

func (ConversionPredicate) Update

type Ensurer

type Ensurer struct {
	// Client is the local/host k8s client used for reading CRs,
	// providers, and secrets that live on the management cluster.
	Client client.Client
	// DestinationClient is the k8s client for the cluster where pods and
	// PVCs are created. For host providers it equals Client.
	DestinationClient client.Client
	Log               logging.LevelLogger
}

Ensurer manages pod lifecycle for a Conversion CR. It holds the local (host) client for CR and secret lookups, and a destination client for pod and PVC operations on the target cluster.

func NewEnsurer

func NewEnsurer(localClient client.Client, log logging.LevelLogger, spec api.ConversionSpec) (*Ensurer, error)

NewEnsurer builds an Ensurer for the given Conversion CR. When the spec references a remote destination provider a remote client is constructed automatically otherwise the local client is reused.

func (*Ensurer) DeletePod

func (e *Ensurer) DeletePod(conversion *api.Conversion) error

DeletePod finds the pod that was created for the Conversion CR and deletes it. Returns nil when no pod is found (already gone or never created).

func (*Ensurer) EnsurePod

func (e *Ensurer) EnsurePod(conversion *api.Conversion) (*core.Pod, error)

EnsurePod creates the pod for the Conversion CR if it does not already exist and returns it. Returns error when the conversion type is not recognised.

func (*Ensurer) GetPod

func (e *Ensurer) GetPod(conversion *api.Conversion, labels map[string]string) (*core.Pod, error)

GetPod returns the managed pod matching the given labels, or nil. It searches on the destination cluster.

func (*Ensurer) RemoveOwnedSnapshot

func (e *Ensurer) RemoveOwnedSnapshot(ctx context.Context, conversion *api.Conversion) (bool, error)

RemoveOwnedSnapshot drives async vSphere snapshot removal for a controller-owned DeepInspection snapshot. Returns (true, nil) when done or when there is nothing to remove. Returns (false, nil) while the vSphere task is still in flight; the caller must persist status and requeue.

func (*Ensurer) VolumesFromDiskRefs

func (e *Ensurer) VolumesFromDiskRefs(disks []api.DiskRef) (volumes []core.Volume, mounts []core.VolumeMount, devices []core.VolumeDevice, err error)

VolumesFromDiskRefs converts a slice of DiskRef into Kubernetes volume, mount, and device entries ready for a pod spec. Each PVC is looked up on the destination cluster in the namespace specified in the DiskRef so that volume mode can be determined when not already set.

type PipelineStage

type PipelineStage struct {
	Stage     api.ConversionStage
	Predicate func(conv *api.Conversion) bool
}

PipelineStage is a single entry in a ConversionPipeline stage sequence. When Predicate is non-nil and returns false for the current Conversion the stage is automatically skipped and pipeline advances to the next stage without calling the stage handler.

type Reconciler

type Reconciler struct {
	base.Reconciler
}

func (Reconciler) Reconcile

func (r Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (result reconcile.Result, err error)

Reconcile a Conversion CR. Note: Must not be a pointer receiver to ensure that the logger and other state is not shared.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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