vm-tests: the state gate refuses an empty volume until the marker is written
This commit is contained in:
parent
a4015fd03a
commit
b95d5feb26
1 changed files with 164 additions and 69 deletions
|
|
@ -18,8 +18,8 @@
|
|||
# open with `openFirewall`, where a second node dials it by name and verifies
|
||||
# the name. The exporter's port answers the host's own processes only;
|
||||
# - a stream written before the pod is deleted is read after;
|
||||
# - the store guard refuses an empty store unless it is marked fresh, run as
|
||||
# the pod's own image runs it;
|
||||
# - the pod's state gate marks the empty store as fresh, and passes the volume
|
||||
# with its marker after a pod delete;
|
||||
# - the switch back leaves no pod, Deployment or AddOn, and the container
|
||||
# starts after the prune unit.
|
||||
#
|
||||
|
|
@ -179,11 +179,11 @@ pkgs.testers.runNixOSTest {
|
|||
|
||||
specialisation.k8s.configuration.services.hyperhive.deploy.nats = {
|
||||
runtime = "k8s";
|
||||
k8s.freshStore = true;
|
||||
k8s.freshState = true;
|
||||
};
|
||||
specialisation.k8s-open.configuration.services.hyperhive.deploy.nats = {
|
||||
runtime = "k8s";
|
||||
k8s.freshStore = true;
|
||||
k8s.freshState = true;
|
||||
openFirewall = true;
|
||||
};
|
||||
|
||||
|
|
@ -422,7 +422,7 @@ pkgs.testers.runNixOSTest {
|
|||
except Exception:
|
||||
diagnose(["hyperhive-k8s-ca-trust.service"])
|
||||
print(machine.execute(f"kubectl -n {NS} describe pod {name}")[1])
|
||||
for container in ("store-guard", "tls-issue", "callout-config", SERVICE, "nats", "exporter"):
|
||||
for container in ("state-gate", "tls-issue", "callout-config", SERVICE, "nats", "exporter"):
|
||||
print(machine.execute(f"kubectl -n {NS} logs {name} -c {container} --tail=60")[1])
|
||||
raise
|
||||
return name
|
||||
|
|
@ -586,9 +586,9 @@ pkgs.testers.runNixOSTest {
|
|||
machine.fail("test -e /etc/nixos-containers/swarm-nats.conf")
|
||||
assert counts() == (1, 1), counts()
|
||||
|
||||
with subtest("the pod holds the guard, the leaf and the config as init containers, and publishes the client port on every address and the exporter's on the bridge"):
|
||||
with subtest("the pod holds the state gate, the leaf and the config as init containers, and publishes the client port on every address and the exporter's on the bridge"):
|
||||
spec = pod(machine, pod_name)["spec"]
|
||||
assert [c["name"] for c in spec["initContainers"]] == ["store-guard", "tls-issue", "callout-config"], spec["initContainers"]
|
||||
assert [c["name"] for c in spec["initContainers"]] == ["state-gate", "tls-issue", "callout-config"], spec["initContainers"]
|
||||
assert [c["name"] for c in spec["containers"]] == ["swarm-nats", "nats", "tls-renew", "exporter"], spec["containers"]
|
||||
assert spec["shareProcessNamespace"] is True, spec
|
||||
server = next(c for c in spec["containers"] if c["name"] == "nats")
|
||||
|
|
@ -614,8 +614,8 @@ pkgs.testers.runNixOSTest {
|
|||
machine.fail(f"grep -F '{mount}/nats-config ' /proc/mounts")
|
||||
issued = machine.succeed(f"kubectl -n {NS} logs {pod_name} -c tls-issue")
|
||||
assert f"requesting the queue's TLS leaf for {NAME} from the store" in issued, issued
|
||||
guard = machine.succeed(f"kubectl -n {NS} logs {pod_name} -c store-guard")
|
||||
assert "empty and marked fresh" in guard, guard
|
||||
guard = machine.succeed(f"kubectl -n {NS} logs {pod_name} -c state-gate")
|
||||
assert "the install is fresh: marked" in guard, guard
|
||||
# The pod's server keeps the descriptors the container's did.
|
||||
limits = machine.succeed("grep 'Max open files' /proc/$(pgrep -ox nats-server)/limits")
|
||||
print(limits)
|
||||
|
|
@ -665,49 +665,10 @@ pkgs.testers.runNixOSTest {
|
|||
assert json.loads(kube(machine, f"get pvc {SERVICE}-state -o json"))["metadata"]["uid"] == STATE_VOLUME
|
||||
machine.wait_until_succeeds(nats_cmd(SERVICES_ROOT, f"stream info {STREAM}"), timeout=120)
|
||||
assert stream_messages() == 1
|
||||
guard = machine.succeed(f"kubectl -n {NS} logs {pod_name} -c store-guard")
|
||||
assert "holds data" in guard, guard
|
||||
guard = machine.succeed(f"kubectl -n {NS} logs {pod_name} -c state-gate")
|
||||
assert "state volume is migrated" in guard, guard
|
||||
assert counts() == (1, 1), counts()
|
||||
|
||||
with subtest("the store guard refuses an empty store unless it is marked fresh, and passes one that holds data, run as the pod's own image runs it"):
|
||||
image = pod(machine, pod_name)["spec"]["initContainers"][0]["image"]
|
||||
|
||||
def one_off(name: str, fresh: str, volume: str) -> tuple[str, str]:
|
||||
manifest = {
|
||||
"apiVersion": "v1",
|
||||
"kind": "Pod",
|
||||
"metadata": {"name": name},
|
||||
"spec": {
|
||||
"restartPolicy": "Never",
|
||||
"securityContext": {"runAsUser": 65532, "runAsGroup": 65532, "fsGroup": 65532},
|
||||
"containers": [
|
||||
{
|
||||
"name": "guard",
|
||||
"image": image,
|
||||
"imagePullPolicy": "Never",
|
||||
"command": ["/bin/swarm-nats-store-guard"],
|
||||
"env": [{"name": "SWARM_NATS_FRESH_STORE", "value": fresh}],
|
||||
"volumeMounts": [{"name": "store", "mountPath": "/var/lib/nats", "readOnly": True}],
|
||||
}
|
||||
],
|
||||
"volumes": [{"name": "store", **json.loads(volume)}],
|
||||
},
|
||||
}
|
||||
machine.succeed(f"echo '{json.dumps(manifest)}' | kubectl apply -f -")
|
||||
machine.wait_until_succeeds(
|
||||
f"kubectl get pod {name} -o jsonpath='{{.status.phase}}' | grep -E 'Succeeded|Failed'",
|
||||
timeout=120,
|
||||
)
|
||||
phase = machine.succeed(f"kubectl get pod {name} -o jsonpath='{{.status.phase}}'").strip()
|
||||
return phase, machine.succeed(f"kubectl logs {name}")
|
||||
|
||||
phase, text = one_off("guard-empty", "false", '{"emptyDir": {}}')
|
||||
assert phase == "Failed" and "empty JetStream store" in text and "swarmctl migrate" in text, (phase, text)
|
||||
phase, text = one_off("guard-fresh", "true", '{"emptyDir": {}}')
|
||||
assert phase == "Succeeded" and "marked fresh" in text, (phase, text)
|
||||
phase, text = one_off("guard-data", "false", f'{{"persistentVolumeClaim": {{"claimName": "{SERVICE}-state"}}}}')
|
||||
assert phase == "Succeeded" and "holds data" in text, (phase, text)
|
||||
|
||||
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(pods()) == 1, pods()
|
||||
|
|
|
|||
Loading…
Reference in a new issue