k8s vm tests: create the agent netns before k3s starts a pod, and delete pods strictly again
This commit is contained in:
parent
87349989ac
commit
df4058d2f7
1 changed files with 35 additions and 16 deletions
|
|
@ -134,7 +134,10 @@ pkgs.testers.runNixOSTest {
|
|||
nodes.machine =
|
||||
{ config, ... }:
|
||||
{
|
||||
imports = [ self.nixosModules.default ];
|
||||
imports = [
|
||||
self.nixosModules.default
|
||||
./lib/agent-netns.nix
|
||||
];
|
||||
|
||||
services.hyperhive = {
|
||||
deploy.k8s.enable = true;
|
||||
|
|
@ -367,15 +370,6 @@ pkgs.testers.runNixOSTest {
|
|||
return machine.succeed(f"kubectl -n {NS} get pods --selector app.kubernetes.io/name={SERVICE} -o name || true").split()
|
||||
|
||||
|
||||
def live_pods() -> list[str]:
|
||||
"""The pods that are not terminating: a deleted pod whose sandbox the
|
||||
runtime can't remove stays in the list."""
|
||||
return machine.succeed(
|
||||
f"kubectl -n {NS} get pods --selector app.kubernetes.io/name={SERVICE} -o json "
|
||||
"| jq -r '.items[] | select(.metadata.deletionTimestamp == null) | .metadata.name'"
|
||||
).split()
|
||||
|
||||
|
||||
def pod_pid(container: str) -> str:
|
||||
id_ = machine.succeed(f"k3s crictl ps --name '^{container}$' --state running -q").split()[0]
|
||||
return machine.succeed(f"k3s crictl inspect {id_} | jq -r .info.pid").strip()
|
||||
|
|
@ -543,7 +537,7 @@ pkgs.testers.runNixOSTest {
|
|||
# The bridge's client: an agent's network namespace on the hive's bridge.
|
||||
BRIDGE_IF = machine.succeed("ip -o -4 addr show | grep -F 'inet ${bridgeIp}/' | cut -d' ' -f2").strip()
|
||||
machine.succeed(
|
||||
"ip netns add agent && ip link add va type veth peer name vb && ip link set vb netns agent "
|
||||
"ip link add va type veth peer name vb && ip link set vb netns agent "
|
||||
f"&& ip link set va master {BRIDGE_IF} && ip link set va up "
|
||||
"&& ip -n agent addr add ${agentIp}/24 dev vb && ip -n agent link set vb up && ip -n agent link set lo up "
|
||||
"&& ip -n agent route add default via ${bridgeIp}"
|
||||
|
|
@ -600,7 +594,7 @@ pkgs.testers.runNixOSTest {
|
|||
old_uid = pod(machine, pod_name)["metadata"]["uid"]
|
||||
kube(machine, f"label {node} {STATE_LABEL}-")
|
||||
assert STATE_LABEL not in node_labels()
|
||||
kube(machine, f"delete pod {pod_name} --wait=false")
|
||||
kube(machine, f"delete pod {pod_name} --wait=true --timeout=120s", 150)
|
||||
unscheduled = (
|
||||
f"kubectl -n {NS} get pods --selector app.kubernetes.io/name={SERVICE} -o json "
|
||||
"| jq -r '.items[].status.conditions[]? | select(.type == \"PodScheduled\" and .status == \"False\") | .message'"
|
||||
|
|
@ -712,7 +706,7 @@ pkgs.testers.runNixOSTest {
|
|||
|
||||
with subtest("deleting the pod keeps the stream: the volume is the same and the message is read after"):
|
||||
old_uid = pod(machine, pod_name)["metadata"]["uid"]
|
||||
kube(machine, f"delete pod {pod_name} --wait=false")
|
||||
kube(machine, f"delete pod {pod_name} --wait=true --timeout=120s", 150)
|
||||
pod_name = wait_pod_ready(old_uid)
|
||||
assert json.loads(kube(machine, f"get pvc {SERVICE}-store -o json"))["metadata"]["uid"] == STATE_VOLUME
|
||||
machine.wait_until_succeeds(nats_cmd(SERVICES_ROOT, f"stream info {STREAM}"), timeout=120)
|
||||
|
|
@ -722,7 +716,7 @@ pkgs.testers.runNixOSTest {
|
|||
|
||||
with subtest("with openFirewall a host outside the node dials the pod by name and verifies it, and is admitted"):
|
||||
switch("/run/booted-system/specialisation/k8s-open")
|
||||
assert len(live_pods()) == 1, live_pods()
|
||||
assert len(pods()) == 1, pods()
|
||||
machine.wait_until_succeeds(f"nc -z -w 4 {NODE} {PORT}", timeout=60)
|
||||
assert reachable(outside, NODE, PORT), "openFirewall left the pod's port closed to a host outside the node"
|
||||
root = machine.succeed(f"cat {SERVICES_ROOT}")
|
||||
|
|
|
|||
Loading…
Reference in a new issue