Skip to content

Commit

Permalink
test: add integration test for vm control logic
Browse files Browse the repository at this point in the history
Signed-off-by: Zespre Schmidt <starbops@zespre.com>
  • Loading branch information
starbops committed Jul 26, 2024
1 parent 991c4ac commit f847130
Show file tree
Hide file tree
Showing 9 changed files with 15,991 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ endif
# tools. (i.e. podman)
CONTAINER_TOOL ?= docker

# KUBEVIRT API version to use
KUBEVIRT_API_VERSION = v1.1.0

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
Expand Down Expand Up @@ -52,6 +55,15 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

.PHONY: generate-kubevirt-crd
generate-kubevirt-crd: controller-gen ## Clone KubeVirt API and generate CustomResourceDefinition objects for integration testing purposes.
TMP_DIR=$$(mktemp -d -p /tmp/); \
KUBEVIRT_API_DIR=$$TMP_DIR/kubevirt-api; \
git clone --depth 1 --branch $(KUBEVIRT_API_VERSION) https://github.com/kubevirt/api $$KUBEVIRT_API_DIR; \
$(CONTROLLER_GEN) crd:allowDangerousTypes=true paths="$$KUBEVIRT_API_DIR/core/v1/..." output:crd:artifacts:config=config/kubevirt-crd; \
rm -rvf $$TMP_DIR; \
rm -vf config/kubevirt-crd/kubevirt.io_datavolumetemplatespecs.yaml

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
Expand All @@ -61,7 +73,7 @@ vet: ## Run go vet against code.
go vet ./...

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
test: manifests generate generate-kubevirt-crd fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out

GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
Expand Down
2,874 changes: 2,874 additions & 0 deletions config/kubevirt-crd/kubevirt.io_kubevirts.yaml

Large diffs are not rendered by default.

266 changes: 266 additions & 0 deletions config/kubevirt-crd/kubevirt.io_virtualmachineinstancemigrations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.15.0
name: virtualmachineinstancemigrations.kubevirt.io
spec:
group: kubevirt.io
names:
kind: VirtualMachineInstanceMigration
listKind: VirtualMachineInstanceMigrationList
plural: virtualmachineinstancemigrations
singular: virtualmachineinstancemigration
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: |-
VirtualMachineInstanceMigration represents the object tracking a VMI's migration
to another host in the cluster
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
properties:
vmiName:
description: The name of the VMI to perform the migration on. VMI
must exist in the migration objects namespace
type: string
type: object
status:
description: VirtualMachineInstanceMigration reprents information pertaining
to a VMI's migration.
properties:
conditions:
items:
properties:
lastProbeTime:
format: date-time
nullable: true
type: string
lastTransitionTime:
format: date-time
nullable: true
type: string
message:
type: string
reason:
type: string
status:
type: string
type:
type: string
required:
- status
- type
type: object
type: array
migrationState:
description: Represents the status of a live migration
properties:
abortRequested:
description: Indicates that the migration has been requested to
abort
type: boolean
abortStatus:
description: Indicates the final status of the live migration
abortion
type: string
completed:
description: Indicates the migration completed
type: boolean
endTimestamp:
description: The time the migration action ended
format: date-time
nullable: true
type: string
failed:
description: Indicates that the migration failed
type: boolean
migrationConfiguration:
description: Migration configurations to apply
properties:
allowAutoConverge:
description: |-
AllowAutoConverge allows the platform to compromise performance/availability of VMIs to
guarantee successful VMI live migrations. Defaults to false
type: boolean
allowPostCopy:
description: |-
AllowPostCopy enables post-copy live migrations. Such migrations allow even the busiest VMIs
to successfully live-migrate. However, events like a network failure can cause a VMI crash.
If set to true, migrations will still start in pre-copy, but switch to post-copy when
CompletionTimeoutPerGiB triggers. Defaults to false
type: boolean
bandwidthPerMigration:
anyOf:
- type: integer
- type: string
description: |-
BandwidthPerMigration limits the amount of network bandwidth live migrations are allowed to use.
The value is in quantity per second. Defaults to 0 (no limit)
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
completionTimeoutPerGiB:
description: |-
CompletionTimeoutPerGiB is the maximum number of seconds per GiB a migration is allowed to take.
If a live-migration takes longer to migrate than this value multiplied by the size of the VMI,
the migration will be cancelled, unless AllowPostCopy is true. Defaults to 800
format: int64
type: integer
disableTLS:
description: |-
When set to true, DisableTLS will disable the additional layer of live migration encryption
provided by KubeVirt. This is usually a bad idea. Defaults to false
type: boolean
matchSELinuxLevelOnMigration:
description: |-
By default, the SELinux level of target virt-launcher pods is forced to the level of the source virt-launcher.
When set to true, MatchSELinuxLevelOnMigration lets the CRI auto-assign a random level to the target.
That will ensure the target virt-launcher doesn't share categories with another pod on the node.
However, migrations will fail when using RWX volumes that don't automatically deal with SELinux levels.
type: boolean
network:
description: |-
Network is the name of the CNI network to use for live migrations. By default, migrations go
through the pod network.
type: string
nodeDrainTaintKey:
description: |-
NodeDrainTaintKey defines the taint key that indicates a node should be drained.
Note: this option relies on the deprecated node taint feature. Default: kubevirt.io/drain
type: string
parallelMigrationsPerCluster:
description: |-
ParallelMigrationsPerCluster is the total number of concurrent live migrations
allowed cluster-wide. Defaults to 5
format: int32
type: integer
parallelOutboundMigrationsPerNode:
description: |-
ParallelOutboundMigrationsPerNode is the maximum number of concurrent outgoing live migrations
allowed per node. Defaults to 2
format: int32
type: integer
progressTimeout:
description: |-
ProgressTimeout is the maximum number of seconds a live migration is allowed to make no progress.
Hitting this timeout means a migration transferred 0 data for that many seconds. The migration is
then considered stuck and therefore cancelled. Defaults to 150
format: int64
type: integer
unsafeMigrationOverride:
description: |-
UnsafeMigrationOverride allows live migrations to occur even if the compatibility check
indicates the migration will be unsafe to the guest. Defaults to false
type: boolean
type: object
migrationPolicyName:
description: Name of the migration policy. If string is empty,
no policy is matched
type: string
migrationUid:
description: The VirtualMachineInstanceMigration object associated
with this migration
type: string
mode:
description: Lets us know if the vmi is currently running pre
or post copy migration
type: string
sourceNode:
description: The source node that the VMI originated on
type: string
startTimestamp:
description: The time the migration action began
format: date-time
nullable: true
type: string
targetAttachmentPodUID:
description: The UID of the target attachment pod for hotplug
volumes
type: string
targetCPUSet:
description: |-
If the VMI requires dedicated CPUs, this field will
hold the dedicated CPU set on the target node
items:
type: integer
type: array
x-kubernetes-list-type: atomic
targetDirectMigrationNodePorts:
additionalProperties:
type: integer
description: The list of ports opened for live migration on the
destination node
type: object
targetNode:
description: The target node that the VMI is moving to
type: string
targetNodeAddress:
description: The address of the target node to use for the migration
type: string
targetNodeDomainDetected:
description: The Target Node has seen the Domain Start Event
type: boolean
targetNodeDomainReadyTimestamp:
description: The timestamp at which the target node detects the
domain is active
format: date-time
type: string
targetNodeTopology:
description: |-
If the VMI requires dedicated CPUs, this field will
hold the numa topology on the target node
type: string
targetPod:
description: The target pod that the VMI is moving to
type: string
type: object
phase:
description: VirtualMachineInstanceMigrationPhase is a label for the
condition of a VirtualMachineInstanceMigration at the current time.
type: string
phaseTransitionTimestamps:
description: PhaseTransitionTimestamp is the timestamp of when the
last phase change occurred
items:
description: VirtualMachineInstanceMigrationPhaseTransitionTimestamp
gives a timestamp in relation to when a phase is set on a vmi
properties:
phase:
description: Phase is the status of the VirtualMachineInstanceMigrationPhase
in kubernetes world. It is not the VirtualMachineInstanceMigrationPhase
status, but partially correlates to it.
type: string
phaseTransitionTimestamp:
description: PhaseTransitionTimestamp is the timestamp of when
the phase change occurred
format: date-time
type: string
type: object
type: array
x-kubernetes-list-type: atomic
type: object
required:
- spec
type: object
served: true
storage: true
Loading

0 comments on commit f847130

Please sign in to comment.