@specific.dev/spectest 0.131.9 → 0.131.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/k3s-join.d.ts +2 -0
- package/dist/components/k3s-join.js +13 -0
- package/dist/components/k3s.js +3 -5
- package/package.json +1 -1
- package/src/components/k3s-docker.test.ts +7 -0
- package/src/components/k3s-join.test.ts +38 -0
- package/src/components/k3s-join.ts +17 -0
- package/src/components/k3s-nodes.test.ts +1 -1
- package/src/components/k3s.ts +3 -5
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const JOIN_DIRECTORY = "/etc/spectest-k3s-join";
|
|
2
|
+
// The join volume is private to one cluster and is captured with its network.
|
|
3
|
+
// Use the server's numeric address from the beginning: K3s otherwise demotes
|
|
4
|
+
// the DNS fallback after discovery and closes in-flight bootstrap requests.
|
|
5
|
+
export function prepareK3sJoin(server, directory = JOIN_DIRECTORY) {
|
|
6
|
+
if (server)
|
|
7
|
+
return ('SERVER="$(ip -4 route get 1.1.1.1 | awk \'{for (i=1;i<NF;i++) if ($i=="src") {print $(i+1); exit}}\')"; ' +
|
|
8
|
+
'case "$SERVER" in ""|*[!0-9.]*) echo "spectest: missing server IPv4 address" >&2; exit 1;; esac; ' +
|
|
9
|
+
`printf '%s\\n' "$SERVER" > ${directory}/server.tmp && mv ${directory}/server.tmp ${directory}/server || exit 1; ` +
|
|
10
|
+
`if [ ! -s ${directory}/token ]; then (umask 077; cat /proc/sys/kernel/random/uuid > ${directory}/token) || exit 1; fi; `);
|
|
11
|
+
return (`while [ ! -s ${directory}/token ] || [ ! -s ${directory}/server ]; do sleep 0.1; done; ` +
|
|
12
|
+
`SERVER="$(cat ${directory}/server)"; `);
|
|
13
|
+
}
|
package/dist/components/k3s.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isIP } from "node:net";
|
|
2
2
|
import { waitForK3sNodes } from "./k3s-nodes.js";
|
|
3
|
+
import { JOIN_DIRECTORY, prepareK3sJoin } from "./k3s-join.js";
|
|
3
4
|
import { installPodTrust } from "./k3s-trust.js";
|
|
4
5
|
import { k3sCoverage } from "./k3s-coverage.js";
|
|
5
6
|
import { waitForAll } from "../harness/concurrency.js";
|
|
@@ -21,7 +22,6 @@ import { deepUnwrap, readTag, wrap } from "../inspect.js";
|
|
|
21
22
|
import { recorderAnnotate, recorderRemove } from "../recorder.js";
|
|
22
23
|
/** Port the in-cluster registry listens on (plain HTTP). */
|
|
23
24
|
const K3S_REGISTRY_PORT = 5000;
|
|
24
|
-
const JOIN_DIRECTORY = "/etc/spectest-k3s-join";
|
|
25
25
|
/** The cluster's own containerd root, inside the k3s container. */
|
|
26
26
|
const CLUSTER_STORE_TARGET = "/var/lib/rancher/k3s/agent/containerd";
|
|
27
27
|
/** The socket of the throwaway daemon that prepares the store. */
|
|
@@ -1374,7 +1374,7 @@ function createK3sCluster(opts, count) {
|
|
|
1374
1374
|
"--kubelet-arg=kubelet-cgroups=/spectest-$(hostname)/k3s",
|
|
1375
1375
|
"--kubelet-arg=runtime-cgroups=/spectest-$(hostname)/k3s",
|
|
1376
1376
|
`--token-file=${JOIN_DIRECTORY}/token`,
|
|
1377
|
-
...(server ? [] : [
|
|
1377
|
+
...(server ? [] : ['--server="https://$SERVER:6443"']),
|
|
1378
1378
|
// CoreDNS / pod DNS upstream. Without this, k3s sees only the
|
|
1379
1379
|
// loopback 127.0.0.11 (Docker's embedded DNS) in the container's
|
|
1380
1380
|
// /etc/resolv.conf, decides no usable nameserver exists, and writes a
|
|
@@ -1464,9 +1464,7 @@ function createK3sCluster(opts, count) {
|
|
|
1464
1464
|
'sed "s/[^ ][^ ]*/+&/g" "/sys/fs/cgroup/$CG/cgroup.controllers" > "/sys/fs/cgroup/$CG/cgroup.subtree_control" || exit 1; ' +
|
|
1465
1465
|
'else for C in /sys/fs/cgroup/*; do [ ! -d "$C" ] || mkdir -p "$C/$CG/k3s" || exit 1; done; fi; ' +
|
|
1466
1466
|
storePrepareSh() +
|
|
1467
|
-
(server
|
|
1468
|
-
? `if [ ! -s ${JOIN_DIRECTORY}/token ]; then (umask 077; cat /proc/sys/kernel/random/uuid > ${JOIN_DIRECTORY}/token); fi; `
|
|
1469
|
-
: `while [ ! -s ${JOIN_DIRECTORY}/token ]; do sleep 0.1; done; `) +
|
|
1467
|
+
prepareK3sJoin(server) +
|
|
1470
1468
|
// Sticky and environment-local stores use overlayfs.
|
|
1471
1469
|
`exec ${nodeArgs} --snapshotter=$SNAP`;
|
|
1472
1470
|
// Plain /readyz probe. On a warm zot cache the cluster's images are
|
package/package.json
CHANGED
|
@@ -65,6 +65,13 @@ for (const count of [1, 3]) test.skipIf(!process.env.SPECTEST_TEST_K3S_DOCKER)(`
|
|
|
65
65
|
await Bun.sleep(250);
|
|
66
66
|
}
|
|
67
67
|
await primary.setup!({ name, helpers, exec } as unknown as ServiceSetupContext<K3sHelpers>);
|
|
68
|
+
// Discovery must retain the bootstrap address. A DNS fallback is demoted
|
|
69
|
+
// to standby and closes active requests, which can kill initial Flannel
|
|
70
|
+
// authorization even though the API server remains healthy.
|
|
71
|
+
for (const node of names.filter(node => node !== name)) {
|
|
72
|
+
const config = JSON.parse(await checked(["docker", "exec", node, "cat", "/var/lib/rancher/k3s/agent/etc/k3s-agent-load-balancer.json"]));
|
|
73
|
+
expect(config.ServerAddresses).toContain(new URL(config.ServerURL).host);
|
|
74
|
+
}
|
|
68
75
|
await helpers.apply(JSON.stringify({ apiVersion: "apps/v1", kind: "DaemonSet", metadata: { name: "web" }, spec: {
|
|
69
76
|
selector: { matchLabels: { app: "web" } }, template: { metadata: { labels: { app: "web" } }, spec: {
|
|
70
77
|
containers: [{ name: "web", image: "busybox:1.37", imagePullPolicy: "Never",
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { mkdtemp, readFile, rm, stat } from "node:fs/promises";
|
|
3
|
+
import { networkInterfaces, tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { prepareK3sJoin } from "./k3s-join";
|
|
6
|
+
|
|
7
|
+
test("concurrent agents join the server's real numeric identity and retain the private token on restart", async () => {
|
|
8
|
+
const directory = await mkdtemp(join(tmpdir(), "k3s-join-"));
|
|
9
|
+
const children: ReturnType<typeof Bun.spawn>[] = [];
|
|
10
|
+
const start = (server: boolean) => {
|
|
11
|
+
const child = Bun.spawn(["sh", "-c", prepareK3sJoin(server, directory) + 'printf "%s" "$SERVER"'], {
|
|
12
|
+
stdout: "pipe", stderr: "pipe",
|
|
13
|
+
});
|
|
14
|
+
children.push(child);
|
|
15
|
+
return child;
|
|
16
|
+
};
|
|
17
|
+
const finish = async (child: ReturnType<typeof start>) => {
|
|
18
|
+
expect(await child.exited).toBe(0);
|
|
19
|
+
return new Response(child.stdout).text();
|
|
20
|
+
};
|
|
21
|
+
try {
|
|
22
|
+
const agents = [start(false), start(false)];
|
|
23
|
+
const address = await finish(start(true));
|
|
24
|
+
const localAddresses = Object.values(networkInterfaces()).flat().filter(a => a?.family === "IPv4").map(a => a!.address);
|
|
25
|
+
expect(localAddresses).toContain(address);
|
|
26
|
+
expect(await Promise.all(agents.map(finish))).toEqual([address, address]);
|
|
27
|
+
expect((await readFile(join(directory, "server"), "utf8")).trim()).toBe(address);
|
|
28
|
+
const token = await readFile(join(directory, "token"), "utf8");
|
|
29
|
+
expect(token.trim()).toMatch(/^[0-9a-f-]{36}$/);
|
|
30
|
+
expect((await stat(join(directory, "token"))).mode & 0o777).toBe(0o600);
|
|
31
|
+
expect(await finish(start(true))).toBe(address);
|
|
32
|
+
expect(await readFile(join(directory, "token"), "utf8")).toBe(token);
|
|
33
|
+
} finally {
|
|
34
|
+
for (const child of children) if (child.exitCode === null) child.kill();
|
|
35
|
+
await Promise.all(children.map(child => child.exited));
|
|
36
|
+
await rm(directory, { recursive: true, force: true });
|
|
37
|
+
}
|
|
38
|
+
}, 10_000);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const JOIN_DIRECTORY = "/etc/spectest-k3s-join";
|
|
2
|
+
|
|
3
|
+
// The join volume is private to one cluster and is captured with its network.
|
|
4
|
+
// Use the server's numeric address from the beginning: K3s otherwise demotes
|
|
5
|
+
// the DNS fallback after discovery and closes in-flight bootstrap requests.
|
|
6
|
+
export function prepareK3sJoin(server: boolean, directory = JOIN_DIRECTORY): string {
|
|
7
|
+
if (server) return (
|
|
8
|
+
'SERVER="$(ip -4 route get 1.1.1.1 | awk \'{for (i=1;i<NF;i++) if ($i=="src") {print $(i+1); exit}}\')"; ' +
|
|
9
|
+
'case "$SERVER" in ""|*[!0-9.]*) echo "spectest: missing server IPv4 address" >&2; exit 1;; esac; ' +
|
|
10
|
+
`printf '%s\\n' "$SERVER" > ${directory}/server.tmp && mv ${directory}/server.tmp ${directory}/server || exit 1; ` +
|
|
11
|
+
`if [ ! -s ${directory}/token ]; then (umask 077; cat /proc/sys/kernel/random/uuid > ${directory}/token) || exit 1; fi; `
|
|
12
|
+
);
|
|
13
|
+
return (
|
|
14
|
+
`while [ ! -s ${directory}/token ] || [ ! -s ${directory}/server ]; do sleep 0.1; done; ` +
|
|
15
|
+
`SERVER="$(cat ${directory}/server)"; `
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -22,7 +22,7 @@ test("one and multiple nodes use the same topology and preserve primary override
|
|
|
22
22
|
for (const name of ["cluster-node-2", "cluster-node-3"]) {
|
|
23
23
|
const node = three.services[name];
|
|
24
24
|
expect(node.command).toContain("exec k3s agent");
|
|
25
|
-
expect(node.command).toContain(
|
|
25
|
+
expect(node.command).toContain('--server="https://$SERVER:6443"');
|
|
26
26
|
expect(node.command).toContain("--kubelet-arg=cgroup-root=/spectest-$(hostname)");
|
|
27
27
|
expect(node.dependsOn).toBeUndefined(); // joins while the server boots
|
|
28
28
|
expect(node.imageBuilds).toHaveLength(0); // build once, import into every node
|
package/src/components/k3s.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isIP } from "node:net";
|
|
2
2
|
import { waitForK3sNodes } from "./k3s-nodes.js";
|
|
3
|
+
import { JOIN_DIRECTORY, prepareK3sJoin } from "./k3s-join.js";
|
|
3
4
|
import { installPodTrust } from "./k3s-trust.js";
|
|
4
5
|
import { k3sCoverage } from "./k3s-coverage.js";
|
|
5
6
|
import { waitForAll } from "../harness/concurrency.js";
|
|
@@ -189,7 +190,6 @@ export interface K3sOptions {
|
|
|
189
190
|
|
|
190
191
|
/** Port the in-cluster registry listens on (plain HTTP). */
|
|
191
192
|
const K3S_REGISTRY_PORT = 5000;
|
|
192
|
-
const JOIN_DIRECTORY = "/etc/spectest-k3s-join";
|
|
193
193
|
|
|
194
194
|
/** The cluster's own containerd root, inside the k3s container. */
|
|
195
195
|
const CLUSTER_STORE_TARGET = "/var/lib/rancher/k3s/agent/containerd";
|
|
@@ -2008,7 +2008,7 @@ function createK3sCluster(opts: K3sOptions, count: number) {
|
|
|
2008
2008
|
"--kubelet-arg=kubelet-cgroups=/spectest-$(hostname)/k3s",
|
|
2009
2009
|
"--kubelet-arg=runtime-cgroups=/spectest-$(hostname)/k3s",
|
|
2010
2010
|
`--token-file=${JOIN_DIRECTORY}/token`,
|
|
2011
|
-
...(server ? [] : [
|
|
2011
|
+
...(server ? [] : ['--server="https://$SERVER:6443"']),
|
|
2012
2012
|
// CoreDNS / pod DNS upstream. Without this, k3s sees only the
|
|
2013
2013
|
// loopback 127.0.0.11 (Docker's embedded DNS) in the container's
|
|
2014
2014
|
// /etc/resolv.conf, decides no usable nameserver exists, and writes a
|
|
@@ -2099,9 +2099,7 @@ function createK3sCluster(opts: K3sOptions, count: number) {
|
|
|
2099
2099
|
'sed "s/[^ ][^ ]*/+&/g" "/sys/fs/cgroup/$CG/cgroup.controllers" > "/sys/fs/cgroup/$CG/cgroup.subtree_control" || exit 1; ' +
|
|
2100
2100
|
'else for C in /sys/fs/cgroup/*; do [ ! -d "$C" ] || mkdir -p "$C/$CG/k3s" || exit 1; done; fi; ' +
|
|
2101
2101
|
storePrepareSh() +
|
|
2102
|
-
(server
|
|
2103
|
-
? `if [ ! -s ${JOIN_DIRECTORY}/token ]; then (umask 077; cat /proc/sys/kernel/random/uuid > ${JOIN_DIRECTORY}/token); fi; `
|
|
2104
|
-
: `while [ ! -s ${JOIN_DIRECTORY}/token ]; do sleep 0.1; done; `) +
|
|
2102
|
+
prepareK3sJoin(server) +
|
|
2105
2103
|
// Sticky and environment-local stores use overlayfs.
|
|
2106
2104
|
`exec ${nodeArgs} --snapshotter=$SNAP`;
|
|
2107
2105
|
// Plain /readyz probe. On a warm zot cache the cluster's images are
|