talos/hack/test/e2e-qemu.sh

256 lines
5.1 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
set -eou pipefail
export USER_DISKS_MOUNTS="/var/lib/extra,/var/lib/p1,/var/lib/p2"
# shellcheck source=/dev/null
source ./hack/test/e2e.sh
PROVISIONER=qemu
CLUSTER_NAME="e2e-${PROVISIONER}"
QEMU_FLAGS=()
case "${CI:-false}" in
false)
QEMU_FLAGS+=("--with-bootloader=false")
;;
*)
;;
esac
case "${CUSTOM_CNI_URL:-false}" in
false)
;;
*)
QEMU_FLAGS+=("--custom-cni-url=${CUSTOM_CNI_URL}")
;;
esac
case "${WITH_UEFI:-none}" in
none)
;;
*)
QEMU_FLAGS+=("--with-uefi=${WITH_UEFI}")
;;
esac
case "${WITH_VIRTUAL_IP:-false}" in
true)
QEMU_FLAGS+=("--use-vip")
;;
esac
case "${WITH_CLUSTER_DISCOVERY:-true}" in
false)
QEMU_FLAGS+=("--with-cluster-discovery=false" "--kubeprism-port=0") # disable both KubePrism and cluster discovery
;;
esac
case "${WITH_KUBESPAN:-false}" in
true)
QEMU_FLAGS+=("--with-kubespan")
;;
esac
case "${WITH_CONTROL_PLANE_PORT:-false}" in
false)
;;
*)
QEMU_FLAGS+=("--control-plane-port=${WITH_CONTROL_PLANE_PORT}")
;;
esac
case "${VIA_MAINTENANCE_MODE:-false}" in
false)
;;
*)
# apply config via maintenance mode
QEMU_FLAGS+=("--skip-injecting-config" "--with-apply-config")
;;
esac
case "${DISABLE_DHCP_HOSTNAME:-false}" in
false)
;;
*)
QEMU_FLAGS+=("--disable-dhcp-hostname")
;;
esac
feat: add network chaos to qemu development environment Add flags for configuring the qemu bridge interface with chaos options: - network-chaos-enabled - network-jitter - network-latency - network-packet-loss - network-packet-reorder - network-packet-corrupt - network-bandwidth These flags are used in /pkg/provision/providers/vm/network.go at the end of the CreateNetwork function to first see if the network-chaos-enabled flag is set, and then check if bandwidth is set. This will allow developers to simulate clusters having a degraded WAN connection in the development environment and testing pipelines. If bandwidth is not set, it will then enable the other options. - Note that if bandwidth is set, the other options such as jitter, latency, packet loss, reordering and corruption will not be used. This is for two reasons: - Restriction the bandwidth can often intoduce many of the other issues being set by the other options. - Setting the bandwidth uses a separate queuing discipline (Token Bucket Filter) from the other options (Network Emulator) and requires a much more complex configuration using a Heirarchial Token Bucket Filter which cannot be configured at a granular enough level using the vishvananda/netlink library. Adding both queuing disciplines to the same interface may be an option to look into in the future, but would take more extensive testing and control over many more variables which I believe is out of the scope of this PR. It is also possible to add custom profiles, but will also take more research to develop common scenarios which combine different options in a realistic manner. Signed-off-by: Christian Rolland <christian.rolland@siderolabs.com> Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
2023-06-01 07:22:44 -04:00
case "${WITH_NETWORK_CHAOS:-false}" in
false)
;;
*)
QEMU_FLAGS+=("--with-network-chaos" "--with-network-packet-loss=0.01" "--with-network-latency=15ms" "--with-network-jitter=5ms")
feat: add network chaos to qemu development environment Add flags for configuring the qemu bridge interface with chaos options: - network-chaos-enabled - network-jitter - network-latency - network-packet-loss - network-packet-reorder - network-packet-corrupt - network-bandwidth These flags are used in /pkg/provision/providers/vm/network.go at the end of the CreateNetwork function to first see if the network-chaos-enabled flag is set, and then check if bandwidth is set. This will allow developers to simulate clusters having a degraded WAN connection in the development environment and testing pipelines. If bandwidth is not set, it will then enable the other options. - Note that if bandwidth is set, the other options such as jitter, latency, packet loss, reordering and corruption will not be used. This is for two reasons: - Restriction the bandwidth can often intoduce many of the other issues being set by the other options. - Setting the bandwidth uses a separate queuing discipline (Token Bucket Filter) from the other options (Network Emulator) and requires a much more complex configuration using a Heirarchial Token Bucket Filter which cannot be configured at a granular enough level using the vishvananda/netlink library. Adding both queuing disciplines to the same interface may be an option to look into in the future, but would take more extensive testing and control over many more variables which I believe is out of the scope of this PR. It is also possible to add custom profiles, but will also take more research to develop common scenarios which combine different options in a realistic manner. Signed-off-by: Christian Rolland <christian.rolland@siderolabs.com> Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
2023-06-01 07:22:44 -04:00
;;
esac
case "${WITH_FIREWALL:-false}" in
false)
;;
*)
QEMU_FLAGS+=("--with-firewall=${WITH_FIREWALL}")
;;
esac
case "${USE_DISK_IMAGE:-false}" in
false)
;;
*)
zstd -d < _out/metal-amd64.raw.zst > _out/metal-amd64.raw
QEMU_FLAGS+=("--disk-image-path=_out/metal-amd64.raw")
;;
esac
case "${WITH_DISK_ENCRYPTION:-false}" in
false)
;;
*)
QEMU_FLAGS+=("--encrypt-ephemeral" "--encrypt-state" "--disk-encryption-key-types=kms")
;;
esac
case "${WITH_CONFIG_PATCH:-false}" in
false)
;;
*)
[[ ! ${WITH_CONFIG_PATCH} =~ ^@ ]] && echo "WITH_CONFIG_PATCH variable should start with @" && exit 1
for i in ${WITH_CONFIG_PATCH//:/ }; do
QEMU_FLAGS+=("--config-patch=${i}")
done
;;
esac
case "${WITH_CONFIG_PATCH_WORKER:-false}" in
false)
;;
*)
[[ ! ${WITH_CONFIG_PATCH_WORKER} =~ ^@ ]] && echo "WITH_CONFIG_PATCH_WORKER variable should start with @" && exit 1
for i in ${WITH_CONFIG_PATCH_WORKER//:/ }; do
QEMU_FLAGS+=("--config-patch-worker=${i}")
done
;;
esac
case "${WITH_SKIP_K8S_NODE_READINESS_CHECK:-false}" in
false)
;;
*)
QEMU_FLAGS+=("--skip-k8s-node-readiness-check")
;;
esac
case "${WITH_CUSTOM_CNI:-none}" in
false)
;;
cilium)
QEMU_FLAGS+=("--kubeprism-port=13336")
;;
esac
case "${WITH_TRUSTED_BOOT_ISO:-false}" in
false)
;;
*)
INSTALLER_IMAGE=${INSTALLER_IMAGE}-amd64-secureboot
QEMU_FLAGS+=("--iso-path=_out/metal-amd64-secureboot.iso" "--with-tpm2" "--encrypt-ephemeral" "--encrypt-state" "--disk-encryption-key-types=tpm")
;;
esac
case "${WITH_SIDEROLINK_AGENT:-false}" in
false)
;;
*)
QEMU_FLAGS+=("--with-siderolink=${WITH_SIDEROLINK_AGENT}")
;;
esac
case "${WITH_APPARMOR_LSM_ENABLED:-false}" in
false)
;;
*)
cat <<EOF > "${TMP}/kernel-security.patch"
machine:
install:
extraKernelArgs:
- security=apparmor
EOF
QEMU_FLAGS+=("--config-patch=@${TMP}/kernel-security.patch")
;;
esac
case "${WITH_CONFIG_INJECTION_METHOD:-default}" in
default)
;;
*)
QEMU_FLAGS+=("--config-injection-method=${WITH_CONFIG_INJECTION_METHOD}")
;;
esac
function create_cluster {
build_registry_mirrors
"${TALOSCTL}" cluster create \
--provisioner="${PROVISIONER}" \
--name="${CLUSTER_NAME}" \
--kubernetes-version="${KUBERNETES_VERSION}" \
--controlplanes=3 \
--workers="${QEMU_WORKERS:-1}" \
--disk=15360 \
--extra-disks="${QEMU_EXTRA_DISKS:-0}" \
--extra-disks-size="${QEMU_EXTRA_DISKS_SIZE:-5120}" \
--extra-disks-drivers="${QEMU_EXTRA_DISKS_DRIVERS:-}" \
--mtu=1430 \
--memory=2048 \
--memory-workers="${QEMU_MEMORY_WORKERS:-2048}" \
--cpus="${QEMU_CPUS:-2}" \
--cpus-workers="${QEMU_CPUS_WORKERS:-2}" \
--cidr=172.20.1.0/24 \
--user-disk=/var/lib/extra:350MB \
--user-disk=/var/lib/p1:350MB:/var/lib/p2:350MB \
--install-image="${INSTALLER_IMAGE}" \
--with-init-node=false \
--cni-bundle-url="${ARTIFACTS}/talosctl-cni-bundle-\${ARCH}.tar.gz" \
"${REGISTRY_MIRROR_FLAGS[@]}" \
"${QEMU_FLAGS[@]}"
"${TALOSCTL}" config node 172.20.1.2
}
function destroy_cluster() {
"${TALOSCTL}" cluster destroy --name "${CLUSTER_NAME}" --provisioner "${PROVISIONER}"
}
create_cluster
case "${WITH_CUSTOM_CNI:-none}" in
cilium)
install_and_run_cilium_cni_tests
;;
*)
;;
esac
case "${TEST_MODE:-default}" in
fast-conformance)
run_kubernetes_conformance_test fast
;;
*)
get_kubeconfig
run_talos_integration_test
run_kubernetes_integration_test
if [ "${WITH_TEST:-none}" != "none" ]; then
"${WITH_TEST}"
fi
;;
esac
destroy_cluster