@highstate/k3s 0.4.2

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.
@@ -0,0 +1,85 @@
1
+ import { remote } from '@pulumi/command';
2
+ import { output, forUnit, all } from '@highstate/pulumi';
3
+ import { k3s } from '@highstate/library';
4
+
5
+ function getServerConnection(server) {
6
+ return output(server).apply((server2) => ({
7
+ host: server2.endpoint,
8
+ port: server2.sshCredentials?.port ?? 22,
9
+ user: server2.sshCredentials?.user ?? "root",
10
+ password: server2.sshCredentials?.password,
11
+ dialErrorLimit: 3
12
+ }));
13
+ }
14
+ class Server {
15
+ server;
16
+ connection;
17
+ get endpoint() {
18
+ return this.server.endpoint;
19
+ }
20
+ get hostname() {
21
+ return this.server.hostname;
22
+ }
23
+ constructor(server) {
24
+ this.server = output(server);
25
+ this.connection = getServerConnection(this.server);
26
+ }
27
+ command(options) {
28
+ return new remote.Command(
29
+ options.id,
30
+ {
31
+ connection: this.connection,
32
+ create: options.create,
33
+ update: options.update,
34
+ delete: options.delete
35
+ },
36
+ { dependsOn: options.dependsOn }
37
+ );
38
+ }
39
+ }
40
+
41
+ function text(array, ...values) {
42
+ const str = array.reduce((result, part, i) => result + part + (String(values[i]) || ""), "");
43
+ const lines = str.split("\n");
44
+ const indent = lines.filter((line) => line.trim() !== "").map((line) => line.match(/^\s*/)?.[0].length ?? 0).reduce((min, indent2) => Math.min(min, indent2), Infinity);
45
+ return lines.map((line) => line.slice(indent)).join("\n").trim();
46
+ }
47
+
48
+ const { inputs, outputs } = forUnit(k3s.cluster);
49
+ const server = new Server(inputs.server);
50
+ const k3sCommand = server.command({
51
+ id: "k3s",
52
+ create: "curl -sfL https://get.k3s.io | sh -"
53
+ });
54
+ const kubeconfigCommand = server.command({
55
+ id: "kubeconfig",
56
+ create: "cat /etc/rancher/k3s/k3s.yaml",
57
+ dependsOn: k3sCommand
58
+ });
59
+ const kubeconfig = all([kubeconfigCommand.stdout, server.endpoint]).apply(([kubeconfig2, endpoint]) => kubeconfig2.replace("127.0.0.1", endpoint));
60
+ var index = outputs({
61
+ k8sCluster: {
62
+ kubeconfig
63
+ },
64
+ $terminal: {
65
+ image: "ghcr.io/exeteres/highstate/terminal-kubectl",
66
+ command: ["bash", "/welcome.sh"],
67
+ files: {
68
+ "/kubeconfig": kubeconfig,
69
+ "/welcome.sh": text`
70
+ echo "Connecting to the cluster..."
71
+ kubectl cluster-info
72
+
73
+ echo "Use 'kubectl' and 'helm' to manage the cluster."
74
+ echo
75
+
76
+ exec script -q -c bash /dev/null
77
+ `
78
+ },
79
+ env: {
80
+ KUBECONFIG: "/kubeconfig"
81
+ }
82
+ }
83
+ });
84
+
85
+ export { index as default };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@highstate/k3s",
3
+ "version": "0.4.2",
4
+ "type": "module",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "exports": {
9
+ "./cluster": "./dist/cluster/index.js"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "scripts": {
15
+ "build": "pkgroll --tsconfig=tsconfig.build.json",
16
+ "generate-cilium": "bash ./scripts/generate-cilium.sh"
17
+ },
18
+ "dependencies": {
19
+ "@highstate/pulumi": "^0.4.2",
20
+ "@pulumi/command": "^1.0.1"
21
+ },
22
+ "peerDependencies": {
23
+ "@highstate/library": "workspace:^"
24
+ },
25
+ "devDependencies": {
26
+ "pkgroll": "^2.5.1"
27
+ },
28
+ "gitHead": "e88c7c588267cf028c054f694d402902dc057919"
29
+ }