@intentius/chant-lexicon-k3s 0.44.3

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.
Files changed (110) hide show
  1. package/README.md +36 -0
  2. package/dist/codegen/docs.d.ts +7 -0
  3. package/dist/codegen/docs.d.ts.map +1 -0
  4. package/dist/codegen/generate-cli.d.ts +3 -0
  5. package/dist/codegen/generate-cli.d.ts.map +1 -0
  6. package/dist/codegen/generate-lexicon.d.ts +19 -0
  7. package/dist/codegen/generate-lexicon.d.ts.map +1 -0
  8. package/dist/codegen/generate-typescript.d.ts +11 -0
  9. package/dist/codegen/generate-typescript.d.ts.map +1 -0
  10. package/dist/codegen/generate.d.ts +15 -0
  11. package/dist/codegen/generate.d.ts.map +1 -0
  12. package/dist/codegen/naming.d.ts +13 -0
  13. package/dist/codegen/naming.d.ts.map +1 -0
  14. package/dist/codegen/package.d.ts +17 -0
  15. package/dist/codegen/package.d.ts.map +1 -0
  16. package/dist/codegen/parse.d.ts +93 -0
  17. package/dist/codegen/parse.d.ts.map +1 -0
  18. package/dist/generated/index.d.ts +8 -0
  19. package/dist/generated/index.d.ts.map +1 -0
  20. package/dist/generated/runtime.d.ts +5 -0
  21. package/dist/generated/runtime.d.ts.map +1 -0
  22. package/dist/index.d.ts +5 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/integrity.json +10 -0
  25. package/dist/lint/audit-catalog.d.ts +13 -0
  26. package/dist/lint/audit-catalog.d.ts.map +1 -0
  27. package/dist/lint/post-synth/index.d.ts +3 -0
  28. package/dist/lint/post-synth/index.d.ts.map +1 -0
  29. package/dist/lint/post-synth/k3s-helpers.d.ts +19 -0
  30. package/dist/lint/post-synth/k3s-helpers.d.ts.map +1 -0
  31. package/dist/lint/post-synth/k3s101.d.ts +13 -0
  32. package/dist/lint/post-synth/k3s101.d.ts.map +1 -0
  33. package/dist/lint/post-synth/k3s102.d.ts +11 -0
  34. package/dist/lint/post-synth/k3s102.d.ts.map +1 -0
  35. package/dist/lint/post-synth/k3s103.d.ts +11 -0
  36. package/dist/lint/post-synth/k3s103.d.ts.map +1 -0
  37. package/dist/lint/post-synth/k3s104.d.ts +12 -0
  38. package/dist/lint/post-synth/k3s104.d.ts.map +1 -0
  39. package/dist/lint/post-synth/k3s105.d.ts +11 -0
  40. package/dist/lint/post-synth/k3s105.d.ts.map +1 -0
  41. package/dist/lint/rules/index.d.ts +5 -0
  42. package/dist/lint/rules/index.d.ts.map +1 -0
  43. package/dist/lint/rules/token-literal.d.ts +17 -0
  44. package/dist/lint/rules/token-literal.d.ts.map +1 -0
  45. package/dist/lsp/completions.d.ts +7 -0
  46. package/dist/lsp/completions.d.ts.map +1 -0
  47. package/dist/lsp/hover.d.ts +6 -0
  48. package/dist/lsp/hover.d.ts.map +1 -0
  49. package/dist/manifest.json +6 -0
  50. package/dist/meta.json +37 -0
  51. package/dist/okf/index.md +9 -0
  52. package/dist/okf/types/Agent.md +55 -0
  53. package/dist/okf/types/Registries.md +14 -0
  54. package/dist/okf/types/Server.md +122 -0
  55. package/dist/package-cli.d.ts +3 -0
  56. package/dist/package-cli.d.ts.map +1 -0
  57. package/dist/plugin.d.ts +8 -0
  58. package/dist/plugin.d.ts.map +1 -0
  59. package/dist/serializer.d.ts +37 -0
  60. package/dist/serializer.d.ts.map +1 -0
  61. package/dist/skills/chant-k3s.md +90 -0
  62. package/dist/spec/fetch.d.ts +39 -0
  63. package/dist/spec/fetch.d.ts.map +1 -0
  64. package/dist/types/index.d.ts +370 -0
  65. package/dist/validate-cli.d.ts +3 -0
  66. package/dist/validate-cli.d.ts.map +1 -0
  67. package/dist/validate.d.ts +15 -0
  68. package/dist/validate.d.ts.map +1 -0
  69. package/package.json +68 -0
  70. package/src/codegen/docs.ts +25 -0
  71. package/src/codegen/generate-cli.ts +8 -0
  72. package/src/codegen/generate-lexicon.ts +58 -0
  73. package/src/codegen/generate-typescript.ts +63 -0
  74. package/src/codegen/generate.test.ts +157 -0
  75. package/src/codegen/generate.ts +116 -0
  76. package/src/codegen/naming.ts +42 -0
  77. package/src/codegen/package.ts +28 -0
  78. package/src/codegen/parse.ts +386 -0
  79. package/src/generated/.gitkeep +0 -0
  80. package/src/generated/index.d.ts +370 -0
  81. package/src/generated/index.ts +13 -0
  82. package/src/generated/lexicon-k3s.json +37 -0
  83. package/src/generated/runtime.ts +4 -0
  84. package/src/index.ts +11 -0
  85. package/src/lint/audit-catalog.ts +53 -0
  86. package/src/lint/post-synth/index.ts +15 -0
  87. package/src/lint/post-synth/k3s-helpers.ts +34 -0
  88. package/src/lint/post-synth/k3s101.ts +58 -0
  89. package/src/lint/post-synth/k3s102.ts +59 -0
  90. package/src/lint/post-synth/k3s103.ts +38 -0
  91. package/src/lint/post-synth/k3s104.ts +44 -0
  92. package/src/lint/post-synth/k3s105.ts +52 -0
  93. package/src/lint/post-synth/post-synth.test.ts +137 -0
  94. package/src/lint/rules/index.ts +7 -0
  95. package/src/lint/rules/token-literal.test.ts +53 -0
  96. package/src/lint/rules/token-literal.ts +87 -0
  97. package/src/lsp/completions.test.ts +10 -0
  98. package/src/lsp/completions.ts +25 -0
  99. package/src/lsp/hover.test.ts +10 -0
  100. package/src/lsp/hover.ts +43 -0
  101. package/src/package-cli.ts +24 -0
  102. package/src/plugin.test.ts +17 -0
  103. package/src/plugin.ts +129 -0
  104. package/src/serializer.acceptance.test.ts +137 -0
  105. package/src/serializer.test.ts +172 -0
  106. package/src/serializer.ts +191 -0
  107. package/src/skills/chant-k3s.md +90 -0
  108. package/src/spec/fetch.ts +80 -0
  109. package/src/validate-cli.ts +5 -0
  110. package/src/validate.ts +41 -0
@@ -0,0 +1,90 @@
1
+ ---
2
+ skill: chant-k3s
3
+ description: Declare k3s host configuration — server/agent config.yaml and registries.yaml — as typed chant source
4
+ user-invocable: true
5
+ ---
6
+
7
+ # k3s with chant
8
+
9
+ The k3s lexicon declares the files k3s itself consumes: `config.yaml` for
10
+ `k3s server` / `k3s agent`, and `registries.yaml` for the embedded
11
+ containerd. The emitted files are exactly what the native tool accepts —
12
+ drop them at `/etc/rancher/k3s/` (or pass `--config`) and chant is nowhere
13
+ in sight.
14
+
15
+ Config keys are the CLI flag names, verbatim. If `k3s server --help` shows
16
+ `--write-kubeconfig-mode`, the declaration key is `"write-kubeconfig-mode"`.
17
+ Quoted kebab-case keys are normal here.
18
+
19
+ ## Declaring a server
20
+
21
+ ```typescript
22
+ import { Server } from "@intentius/chant-lexicon-k3s";
23
+
24
+ export const controlPlane = new Server({
25
+ "cluster-init": true, // embedded etcd, first node
26
+ "tls-san": ["10.0.0.10", "cp.example.internal"],
27
+ "write-kubeconfig-mode": "0600", // wider than 0644 trips K3S104
28
+ disable: ["traefik"],
29
+ });
30
+ ```
31
+
32
+ ## Declaring an agent
33
+
34
+ ```typescript
35
+ import { Agent } from "@intentius/chant-lexicon-k3s";
36
+
37
+ export const worker = new Agent({
38
+ server: "https://cp.example.internal:6443", // required — K3S103 without it
39
+ "token-file": "/etc/rancher/k3s/agent-token",
40
+ });
41
+ ```
42
+
43
+ ## The token boundary
44
+
45
+ There is no `token` property, on purpose. The join secret reaches the node
46
+ as a file (`token-file`, `agent-token-file`) or as `K3S_TOKEN` /
47
+ `K3S_TOKEN_FILE` in the installer's environment — never as a value in
48
+ source. A literal that arrives through raw props anyway fails K3S001 at
49
+ lint and K3S101 at build. The same wall covers `etcd-s3-secret-key` and
50
+ `etcd-s3-session-token`; use `etcd-s3-config-secret` (a Secret on the
51
+ cluster) for snapshot-store credentials.
52
+
53
+ ## Private registries
54
+
55
+ ```typescript
56
+ import { Mirror, Registries, RegistryConfig, RegistryTLS } from "@intentius/chant-lexicon-k3s";
57
+
58
+ export const registries = new Registries({
59
+ mirrors: {
60
+ "docker.io": new Mirror({ endpoint: ["https://mirror.internal:5000"] }),
61
+ },
62
+ configs: {
63
+ "mirror.internal:5000": new RegistryConfig({
64
+ tls: new RegistryTLS({ ca_file: "/etc/ssl/certs/mirror-ca.pem" }),
65
+ }),
66
+ },
67
+ });
68
+ ```
69
+
70
+ Literal `auth.password` / `auth.token` fail K3S102; `insecure_skip_verify`
71
+ warns via K3S105 — pin the CA instead.
72
+
73
+ ## Output shape
74
+
75
+ One file per declared entity. The first Server/Agent config is the primary
76
+ build output; further configs land beside it as `<name>.config.yaml`, and
77
+ a Registries entity as `registries.yaml`. A build carrying an ownership
78
+ marker stamps it into `node-label`, so the registered Node is attributable
79
+ with any kubectl.
80
+
81
+ ## Rules
82
+
83
+ | Rule | Severity | What it catches |
84
+ |---|---|---|
85
+ | K3S001 | error | literal `token` / `agent-token` in source |
86
+ | K3S101 | error | a literal secret reaching the build (token, etcd S3 keys) |
87
+ | K3S102 | error | literal registry credentials in registries.yaml |
88
+ | K3S103 | error | an Agent with no `server` to join |
89
+ | K3S104 | warning | kubeconfig written wider than 0644 |
90
+ | K3S105 | warning | registry TLS verification disabled |
@@ -0,0 +1,80 @@
1
+ /**
2
+ * k3s CLI flag-definition fetching — downloads the pinned Go sources that
3
+ * define the server and agent flag surfaces, and caches them locally.
4
+ *
5
+ * k3s publishes no JSON Schema for config.yaml. The config file's keys ARE
6
+ * the CLI flag names ("Every flag can be a config key", docs.k3s.io), and
7
+ * the flags are defined as urfave/cli struct literals in pkg/cli/cmds/.
8
+ * Those literals carry name, usage, default and hidden-ness, so the tagged
9
+ * source tree is the machine-readable spec (#1599) — the same channel the
10
+ * k3s binary itself is built from, pinned the same way k3d pins its
11
+ * schema.json.
12
+ */
13
+
14
+ import { join } from "path";
15
+ import { homedir } from "os";
16
+ import { fetchWithCache, clearCacheFile } from "@intentius/chant/codegen/fetch";
17
+
18
+ /**
19
+ * Pinned upstream k3s release.
20
+ *
21
+ * Bump this constant (and re-generate) when adopting a newer k3s release.
22
+ * The acceptance test's rancher/k3s image tag derives from it (`+` → `-`).
23
+ */
24
+ export const K3S_VERSION = "v1.36.3+k3s1";
25
+
26
+ /** Docker image tag form of the pin: `+` is not legal in a tag. */
27
+ export const K3S_IMAGE_TAG = K3S_VERSION.replace("+", "-");
28
+
29
+ /**
30
+ * The files that define flags reachable from the server and agent flag
31
+ * lists. server.go owns ServerFlags; agent.go owns the agent command's
32
+ * flags plus the shared node/token flag vars; config.go, root.go and
33
+ * log.go define the shared vars both lists reference (ConfigFlag,
34
+ * DebugFlag, VLevel, LogFile, ...).
35
+ */
36
+ const SPEC_FILES = ["server.go", "agent.go", "config.go", "root.go", "log.go"] as const;
37
+
38
+ function rawUrl(file: string): string {
39
+ // '+' must be percent-encoded in the raw.githubusercontent path.
40
+ const tag = encodeURIComponent(K3S_VERSION);
41
+ return `https://raw.githubusercontent.com/k3s-io/k3s/${tag}/pkg/cli/cmds/${file}`;
42
+ }
43
+
44
+ function cachePath(file: string): string {
45
+ return join(homedir(), ".chant", `k3s-${K3S_VERSION}-${file}`);
46
+ }
47
+
48
+ /**
49
+ * Fetch all pinned spec files, keyed by filename.
50
+ */
51
+ export async function fetchSpecFiles(force?: boolean): Promise<Record<string, string>> {
52
+ const files: Record<string, string> = {};
53
+ for (const file of SPEC_FILES) {
54
+ const data = await fetchWithCache({ url: rawUrl(file), cacheFile: cachePath(file) }, force);
55
+ files[file] = data.toString("utf-8");
56
+ }
57
+ return files;
58
+ }
59
+
60
+ /**
61
+ * Fetch the spec as a Map<typeName, Buffer> compatible with the
62
+ * generatePipeline fetchSchemas callback.
63
+ *
64
+ * Single entry keyed "K3s::Config" whose buffer is a JSON envelope of the
65
+ * fetched files — the parse step needs them together to resolve flag-var
66
+ * references across files.
67
+ */
68
+ export async function fetchSchemas(force?: boolean): Promise<Map<string, Buffer>> {
69
+ const files = await fetchSpecFiles(force);
70
+ const schemas = new Map<string, Buffer>();
71
+ schemas.set("K3s::Config", Buffer.from(JSON.stringify(files), "utf-8"));
72
+ return schemas;
73
+ }
74
+
75
+ /**
76
+ * Clear the cached spec files.
77
+ */
78
+ export function clearCache(): void {
79
+ for (const file of SPEC_FILES) clearCacheFile(cachePath(file));
80
+ }
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env tsx
2
+ import { validate } from "./validate";
3
+
4
+ // `validate` takes an optional { basePath }; defaults to the lexicon root.
5
+ await validate();
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Validate generated lexicon-k3s artifacts.
3
+ *
4
+ * Thin wrapper around the core validation framework
5
+ * with k3s-specific configuration.
6
+ */
7
+
8
+ import { dirname } from "path";
9
+ import { fileURLToPath } from "url";
10
+ import { validateLexiconArtifacts, type ValidateResult } from "@intentius/chant/codegen/validate";
11
+
12
+ export type { ValidateCheck, ValidateResult } from "@intentius/chant/codegen/validate";
13
+
14
+ /**
15
+ * Every entity class, plus load-bearing config keys whose disappearance
16
+ * from a regeneration would mean the parser silently lost part of the
17
+ * flag surface (#1599): the join/identity block, the etcd S3 keys the
18
+ * lint layer references, and one representative per flag type.
19
+ */
20
+ const REQUIRED_NAMES: string[] = [
21
+ "Server",
22
+ "Agent",
23
+ "Registries",
24
+ "Mirror",
25
+ "RegistryConfig",
26
+ "RegistryAuth",
27
+ "RegistryTLS",
28
+ ];
29
+
30
+ /**
31
+ * Validate the generated lexicon-k3s artifacts.
32
+ */
33
+ export async function validate(opts?: { basePath?: string }): Promise<ValidateResult> {
34
+ const basePath = opts?.basePath ?? dirname(dirname(fileURLToPath(import.meta.url)));
35
+
36
+ return validateLexiconArtifacts({
37
+ lexiconJsonFilename: "lexicon-k3s.json",
38
+ requiredNames: REQUIRED_NAMES,
39
+ basePath,
40
+ });
41
+ }