Skip to content

Commit 86316b8

Browse files
committed
Updated examples
1 parent 3304b6a commit 86316b8

21 files changed

+219
-88
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/.vscode
22
/.zsh_history
3-
.ssh
43
.secrets
4+
.ssh
55
/result
66
/.env

examples/multi/.secrets/join.json

-4
This file was deleted.

examples/multi/multi-one.ts examples/multi/multi-1.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import { ServerInstanceConfig } from "../../src/types.ts";
22

33
export default {
44
role: "server",
5-
name: "jetski-multi-node-one",
5+
name: "jetski-multi-node-1",
6+
contextName: "jetski-multi",
67
image: "22.04",
7-
cpus: 1,
8-
memoryGiBs: 2,
9-
diskGiBs: 5,
8+
cpus: 15,
9+
memoryGiBs: 56,
10+
diskGiBs: 200,
1011
k3sVersion: "v1.24.17+k3s1",
11-
serviceCidr: "10.254.251.0/24",
12-
clusterCidr: "10.254.252.0/22",
13-
clusterDnsIp: "10.254.255.10",
14-
clusterDomain: "jetski.local",
12+
serviceCidr: "10.254.244.0/22",
13+
clusterCidr: "10.254.248.0/21",
14+
clusterDnsIp: "10.254.244.10",
15+
clusterDomain: "cluster.local",
1516
bridged: Boolean(Deno.env.get("JETSKI_INSTANCE_BRIDGED")),
1617
externalNetworkCidr: Deno.env.get("JETSKI_INSTANCE_NODE_IP_CIDR"),
1718
externalNetworkInterface: "eth1",

examples/multi/multi-two.ts examples/multi/multi-2.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AgentInstanceConfig } from "../../src/types.ts";
2-
import serverInstanceConfig from "./multi-one.ts";
2+
import serverInstanceConfig from "./multi-1.ts";
33

44
const {
55
k3sVersion,
@@ -20,11 +20,11 @@ export default {
2020
externalNetworkCidr,
2121
externalNetworkInterface,
2222
bridged,
23-
name: "jetski-multi-node-two",
23+
name: "jetski-multi-node-2",
2424
image: "22.04",
25-
cpus: 1,
26-
memoryGiBs: 2,
27-
diskGiBs: 5,
25+
cpus: 15,
26+
memoryGiBs: 55,
27+
diskGiBs: 200,
2828
nodeLabels: {
2929
"com.jetski/foo": "bar",
3030
"com.jetski/baz": "boo",

examples/multi/multi-three.ts examples/multi/multi-3.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { AgentInstanceConfig } from "../../src/types.ts";
2-
import agentInstanceConfig from "./multi-two.ts";
2+
import agentInstanceConfig from "./multi-2.ts";
33

44
export default {
55
...agentInstanceConfig,
6-
name: "jetski-multi-node-three",
6+
name: "jetski-multi-node-3",
77
nodeLabels: {
88
"com.jetski/foo": "something",
99
"com.jetski/baz": "else",

examples/multi/multi-4.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { AgentInstanceConfig } from "../../src/types.ts";
2+
import agentInstanceConfig from "./multi-2.ts";
3+
4+
export default {
5+
...agentInstanceConfig,
6+
name: "jetski-multi-node-4",
7+
nodeLabels: {
8+
"com.jetski/foo": "something",
9+
"com.jetski/baz": "else",
10+
},
11+
} satisfies AgentInstanceConfig;

examples/multi/multi-5.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { AgentInstanceConfig } from "../../src/types.ts";
2+
import agentInstanceConfig from "./multi-2.ts";
3+
4+
export default {
5+
...agentInstanceConfig,
6+
name: "jetski-multi-node-5",
7+
nodeLabels: {
8+
"com.jetski/foo": "something",
9+
"com.jetski/baz": "else",
10+
},
11+
} satisfies AgentInstanceConfig;

examples/multi/multi-6.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { AgentInstanceConfig } from "../../src/types.ts";
2+
import agentInstanceConfig from "./multi-2.ts";
3+
4+
export default {
5+
...agentInstanceConfig,
6+
name: "jetski-multi-node-6",
7+
nodeLabels: {
8+
"com.jetski/foo": "something",
9+
"com.jetski/baz": "else",
10+
},
11+
} satisfies AgentInstanceConfig;

examples/multi/run_agents.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
SCRIPT_DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
4+
5+
# Loop from 2 to 6
6+
for i in $(seq 2 6); do
7+
MULTIPASS_SERVER_ADDRESS="um790-${i}:51000" "${SCRIPT_DIR}"/../../cli.sh run --config ./examples/multi/multi-"${i}".ts "$@"
8+
done

examples/multi/run_server.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
SCRIPT_DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
4+
MULTIPASS_SERVER_ADDRESS="um790-1:51000" "${SCRIPT_DIR}"/../../cli.sh run --config ./examples/multi/multi-1.ts "$@"

examples/single/single.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ export default {
44
role: "server",
55
name: "jetski-single-node",
66
image: "22.04",
7-
cpus: 1,
8-
memoryGiBs: 2,
9-
diskGiBs: 5,
7+
cpus: 15,
8+
memoryGiBs: 56,
9+
diskGiBs: 200,
1010
k3sVersion: "v1.24.17+k3s1",
1111
clusterCidr: "10.254.254.0/24",
1212
serviceCidr: "10.254.255.0/24",
1313
clusterDnsIp: "10.254.255.10",
14-
clusterDomain: "jetski.local",
14+
clusterDomain: "cluster.local",
1515
bridged: Boolean(Deno.env.get("JETSKI_INSTANCE_BRIDGED")),
1616
externalNetworkCidr: Deno.env.get("JETSKI_INSTANCE_NODE_IP_CIDR"),
1717
disableComponents: {

scripts/sshd.ps1 scripts/00_setup_sshd.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
Add-WindowsCapability -Online -Name OpenSSH.Server
12
Get-Service sshd | Set-Service -StartupType Automatic
23

3-
$authorizedKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILmxihXDTbdPX7rVLKzZt6r/Qt9eZnrXCAWxCrmTOpZ6 [email protected]"
4+
$authorizedKey = "[YOUR_PUBLIC_KEY]"
45
Set-Content `
56
-Force -Path $env:ProgramData\ssh\administrators_authorized_keys `
67
-Value "$authorizedKey"

scripts/01_clean_windows.ps1

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Disable taskbar widgets
2+
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "TaskbarDa" /t REG_DWORD /d 0 /f
3+
Stop-Service 'WSearch'; Set-Service -Name 'WSearch' -StartupType 'Disabled'
4+
5+
Get-NetAdapter -Name "*Wi-FI*" | Disable-NetAdapter -Confirm:$false
6+
Get-PnpDevice | Where-Object {$_.Class -eq 'Bluetooth' -and $_.Name -like '*Wireless Bluetooth*'} | ForEach-Object { Disable-PnpDevice -InstanceId $_.DeviceID -Confirm:$false }
7+
8+
Get-AppxPackage *WindowsAlarms* | Remove-AppxPackage
9+
Get-AppxPackage *AV1VideoExtension* | Remove-AppxPackage
10+
Get-AppxPackage *WindowsCalculator* | Remove-AppxPackage
11+
Get-AppxPackage *Microsoft.549981C3F5F10* | Remove-AppxPackage
12+
Get-AppxPackage *WindowsFeedbackHub* | Remove-AppxPackage
13+
Get-AppxPackage *HEIFImageExtension* | Remove-AppxPackage
14+
Get-AppxPackage *GetHelp* | Remove-AppxPackage
15+
Get-AppxPackage *WindowsMaps* | Remove-AppxPackage
16+
Get-AppxPackage *Todos* | Remove-AppxPackage
17+
Get-AppxPackage *ZuneVideo* | Remove-AppxPackage
18+
Get-AppxPackage *MicrosoftOfficeHub* | Remove-AppxPackage
19+
Get-AppxPackage *Paint* | Remove-AppxPackage
20+
Get-AppxPackage *ZuneMusic* | Remove-AppxPackage
21+
Get-AppxPackage *BingNews* | Remove-AppxPackage
22+
Get-AppxPackage *OneDrive* | Remove-AppxPackage
23+
Get-AppxPackage *Windows.Photos* | Remove-AppxPackage
24+
Get-AppxPackage *ScreenSketch* | Remove-AppxPackage
25+
Get-AppxPackage *SkypeApp* | Remove-AppxPackage
26+
Get-AppxPackage *MicrosoftSolitaireCollection* | Remove-AppxPackage
27+
Get-AppxPackage *SpotifyAB.SpotifyMusic* | Remove-AppxPackage
28+
Get-AppxPackage *MicrosoftStickyNotes* | Remove-AppxPackage
29+
Get-AppxPackage *Teams* | Remove-AppxPackage
30+
Get-AppxPackage *WindowsSoundRecorder* | Remove-AppxPackage
31+
Get-AppxPackage *BingWeather* | Remove-AppxPackage
32+
Get-AppxPackage *WebpImageExtension* | Remove-AppxPackage
33+
Get-AppxPackage *YourPhone* | Remove-AppxPackage
34+
Get-AppxPackage *Microsoft.GamingApp* | Remove-AppxPackage
35+
Get-AppxPackage *Microsoft.OneConnect* | Remove-AppxPackage
36+
Get-AppxPackage *Microsoft.Whiteboard* | Remove-AppxPackage
37+
Get-AppxPackage *Microsoft.MinecraftEducationEdition* | Remove-AppxPackage
38+
Get-AppxPackage *Microsoft.MixedReality.Portal* | Remove-AppxPackage
39+
Get-AppxPackage *Clipchamp* | Remove-AppxPackage
40+
Get-AppxPackage *windowscommunicationsapps* | Remove-AppxPackage
41+
42+
winget uninstall Microsoft.OneDrive --accept-source-agreements
43+
44+
netsh advfirewall firewall add rule name="ICMP Allow incoming V4 echo request" protocol=icmpv4:8,any dir=in action=allow
45+
Get-NetAdapterBinding -ComponentID ms_tcpip6 | Disable-NetAdapterBinding -ComponentID ms_tcpip6

scripts/02_enable_hyper_v.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Enable-WindowsOptionalFeature -NoRestart -Online -FeatureName Microsoft-Hyper-V -All

scripts/03_setup_multipass_switch.ps1

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
try {
2+
New-VMSwitch -name MultipassSwitch -NetAdapterName Ethernet -AllowManagementOS $true
3+
}
4+
catch {
5+
if ($_.Exception.Message -notmatch "already bound") {
6+
Write-Output $_
7+
exit 1
8+
}
9+
}
10+
11+
Set-NetConnectionProfile -InterfaceAlias "vEthernet (MultipassSwitch)" -NetworkCategory Private

scripts/setup_multipassd.ps1 scripts/04_setup_multipassd.ps1

+51-46
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
Set-StrictMode -Version 2
22
$ErrorActionPreference = 'Stop'
33

4-
try {
5-
New-VMSwitch -name MultipassSwitch -NetAdapterName Ethernet -AllowManagementOS $true
6-
}
7-
catch {
8-
if ($_.Exception.Message -notmatch "already bound") {
9-
Write-Output $_
10-
exit 1
4+
if (-not (Get-Command multipass.exe -ErrorAction SilentlyContinue)) {
5+
$url = "https://multipass.run/download/windows"
6+
$dirPath = "C:\Temp"
7+
if (-Not (Test-Path $dirPath)) {
8+
New-Item -ItemType Directory -Path $dirPath
119
}
10+
$filePath = "$dirPath\Multipass-Installer.exe"
11+
Write-Output "Downloading Multipass from $url to $filePath"
12+
Invoke-WebRequest -Uri $url -OutFile $filePath
13+
# Install Multipass silently
14+
Write-Output "Installing Multipass from $filePath"
15+
Start-Process -FilePath $filePath -Args "/S" -Wait
16+
Write-Output "Installed Multipass"
1217
}
1318

1419
$hostname = $env:COMPUTERNAME.ToLower()
@@ -76,42 +81,42 @@ function Wait-ForMultipassd {
7681

7782
Wait-ForMultipassd
7883

79-
# Write-Output "Setting local.passphrase"
80-
# multipass.exe set local.passphrase=foo
81-
# if ($LASTEXITCODE -ne 0) {
82-
# Write-Output "Failed to set local.passphrase"
83-
# exit $LASTEXITCODE
84-
# }
85-
86-
# Wait-ForMultipassd
87-
# Write-Output "Setting local.bridged-network"
88-
# multipass.exe set local.bridged-network=MultipassSwitch
89-
# if ($LASTEXITCODE -ne 0) {
90-
# Write-Output "Failed to set local.bridged-network"
91-
# exit $LASTEXITCODE
92-
# }
93-
94-
# # # Wait-ForMultipassd
95-
# Write-Output "Getting ethernet IP"
96-
# try {
97-
# $ethIp = (Get-NetIPAddress -InterfaceAlias "vEthernet (MultipassSwitch)" -AddressFamily IPv4).IPAddress
98-
# }
99-
# catch {
100-
# Write-Output "Failed to get ethernet IP"
101-
# Write-Output $_
102-
# exit 1
103-
# }
104-
105-
# Write-Output "Found ethernet IP: $ethIp"
106-
107-
# Write-Output "Going to add portproxy rule for $($ethIp):$($multipassdPort)"
108-
# netsh interface portproxy add v4tov4 listenport=$multipassdPort listenaddress=$ethIp connectport=$multipassdPort connectaddress=127.0.0.1
109-
# if ($LASTEXITCODE -ne 0) {
110-
# exit $LASTEXITCODE
111-
# }
112-
113-
# Write-Output "Going to add firewall rule for $($ethIp):$($multipassdPort)"
114-
# New-NetFirewallRule -DisplayName "multipassd_51000" -Direction Inbound -Protocol TCP -LocalPort $multipassdPort -Action Allow -PolicyStore PersistentStore
115-
# if ($LASTEXITCODE -ne 0) {
116-
# exit $LASTEXITCODE
117-
# }
84+
Write-Output "Setting local.passphrase"
85+
multipass.exe set local.passphrase=foo
86+
if ($LASTEXITCODE -ne 0) {
87+
Write-Output "Failed to set local.passphrase"
88+
exit $LASTEXITCODE
89+
}
90+
91+
Wait-ForMultipassd
92+
Write-Output "Setting local.bridged-network"
93+
multipass.exe set local.bridged-network=MultipassSwitch
94+
if ($LASTEXITCODE -ne 0) {
95+
Write-Output "Failed to set local.bridged-network"
96+
exit $LASTEXITCODE
97+
}
98+
99+
# # Wait-ForMultipassd
100+
Write-Output "Getting ethernet IP"
101+
try {
102+
$ethIp = (Get-NetIPAddress -InterfaceAlias "vEthernet (MultipassSwitch)" -AddressFamily IPv4).IPAddress
103+
}
104+
catch {
105+
Write-Output "Failed to get ethernet IP"
106+
Write-Output $_
107+
exit 1
108+
}
109+
110+
Write-Output "Found ethernet IP: $ethIp"
111+
112+
Write-Output "Going to add portproxy rule for $($ethIp):$($multipassdPort)"
113+
netsh interface portproxy add v4tov4 listenport=$multipassdPort listenaddress=$ethIp connectport=$multipassdPort connectaddress=127.0.0.1
114+
if ($LASTEXITCODE -ne 0) {
115+
exit $LASTEXITCODE
116+
}
117+
118+
Write-Output "Going to add firewall rule for $($ethIp):$($multipassdPort)"
119+
New-NetFirewallRule -DisplayName "multipassd_51000" -Direction Inbound -Protocol TCP -LocalPort $multipassdPort -Action Allow -PolicyStore PersistentStore
120+
if ($LASTEXITCODE -ne 0) {
121+
exit $LASTEXITCODE
122+
}

scripts/ssh_pwsh.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ SCRIPT_DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
55
NODE_ADDRESS=${1:?"The remote node address is required"}
66
PS_SCRIPT=${2:?"The the powershell script name is required"}
77

8-
ssh -o LogLevel=error "${NODE_ADDRESS}" powershell.exe -NoLogo -NonInteractive -Command - < "${SCRIPT_DIR}/${PS_SCRIPT}.ps1"
8+
ssh -o LogLevel=error "${NODE_ADDRESS}" powershell.exe -NoLogo -Command - < "${SCRIPT_DIR}/${PS_SCRIPT}.ps1"

src/actions/create.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
multipassTailCloudInitOutputLog,
2020
multipassWaitForState,
2121
} from "../multipass.ts";
22-
import { InstanceConfig, InstanceConfigPathSchema, InstanceState } from "../types.ts";
22+
import { InstanceConfig, InstanceConfigPathSchema, InstanceState, ServerInstanceConfig } from "../types.ts";
2323
import {
2424
createCloudInitConfig,
2525
err,
@@ -31,9 +31,10 @@ import {
3131
} from "../utils.ts";
3232

3333
export async function updateKubeconfig(
34-
{ ip, instance }: { ip: string; instance: InstanceConfig },
34+
{ ip, instance }: { ip: string; instance: ServerInstanceConfig },
3535
) {
36-
const { name, sshDirectoryPath } = instance;
36+
const { name: instanceName, contextName = instanceName, sshDirectoryPath } = instance;
37+
3738
log(
3839
"Fetching instance's kubeconfig from /etc/rancher/k3s/k3s.yaml over SSH",
3940
);
@@ -47,12 +48,12 @@ export async function updateKubeconfig(
4748
) as any;
4849

4950
kubeconfig.clusters[0].cluster.server = `https://${ip}:6443`;
50-
kubeconfig.clusters[0].name = name;
51-
kubeconfig.contexts[0].context.cluster = name;
52-
kubeconfig.contexts[0].context.user = name;
53-
kubeconfig.contexts[0].name = name;
54-
kubeconfig["current-context"] = name;
55-
kubeconfig.users[0].name = name;
51+
kubeconfig.clusters[0].name = contextName;
52+
kubeconfig.contexts[0].context.cluster = contextName;
53+
kubeconfig.contexts[0].context.user = contextName;
54+
kubeconfig.contexts[0].name = contextName;
55+
kubeconfig["current-context"] = contextName;
56+
kubeconfig.users[0].name = contextName;
5657

5758
const tempDir = await Deno.makeTempDir();
5859
const tempKubeConfigFile = joinPath(tempDir, "kubeconfig.yaml");
@@ -77,7 +78,7 @@ export async function updateKubeconfig(
7778

7879
await Deno.writeTextFile(kubeConfigFile, newKubeConfig);
7980

80-
ok("Kubeconfig has been updated. The current context should now be", cyan(name));
81+
ok("Kubeconfig has been updated. The current context should now be", cyan(contextName));
8182
}
8283

8384
export async function createInstance(instance: InstanceConfig, signal: AbortSignal) {

0 commit comments

Comments
 (0)