-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwindows.ps1
108 lines (73 loc) · 2.98 KB
/
windows.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
$url_file = "https://github.com/KnicKnic/k3s/releases/download/files3/files.zip"
# $work_dir = $env:GITHUB_WORKSPACE
$drive = Split-Path $pwd -Qualifier
$work_dir = join-path $drive tmp knicknic temp-kubernetes-ci
$k3s_path = join-path $work_dir "k3s.exe"
$wins_path = Join-Path $work_dir "wins.exe"
$k3s_tmp_dir = join-path $work_dir "k3s_tmp"
$logs_file = join-path $k3s_tmp_dir "logs.txt"
$zip_file = join-path $work_dir "files.zip"
mkdir $work_dir -ErrorAction SilentlyContinue
function logMessage($msg){
$str = "{0} logMessage {1}" -f $(get-date), $msg
echo $str
}
logMessage "start download"
curl.exe -s -L -o $zip_file $url_file
logMessage "start extract"
Expand-Archive -Path $zip_file -DestinationPath $work_dir
$env:Path += ";$work_dir"
mkdir /etc -ErrorAction SilentlyContinue
mkdir $k3s_tmp_dir -ErrorAction SilentlyContinue
#setup environment
echo """
nameserver 8.8.8.8
""" > /etc/resolv.conf
logMessage "Get Ip info"
ipconfig /all
$hostNetwork = get-NetIPAddress -InterfaceAlias "Ethernet"| ?{$_.AddressFamily -eq "IPv4"}
$env:hostIp = $hostNetwork.IpAddress
$env:hostCidr = "{0}/{1}" -f $hostNetwork.IpAddress, $hostNetwork.PrefixLength
#for host-gw
#eventually need to get rid of KUBE_NETWORK
$env:KUBE_NETWORK="cbr0"
# Ideally I would directly launch k3s like 2 lines below, however when I do, pwsh gets wedged
start-process "pwsh.exe" -ArgumentList @("-command", "$k3s_path server -d $k3s_tmp_dir --flannel-backend host-gw --docker --disable-network-policy --pause-image mcr.microsoft.com/k8s/core/pause:1.0.0 --disable traefik,local-storage,metrics-server 2>&1 > $logs_file")
# $arguments = "server -d $k3s_tmp_dir --flannel-backend host-gw --docker --disable-network-policy --pause-image mcr.microsoft.com/k8s/core/pause:1.0.0 --disable servicelb,traefik,local-storage,metrics-server".Split()
# start-process $k3s_path -ArgumentList $arguments -RedirectStandardError $logs_file
# start wins in new windows
Start-Process "pwsh.exe" -ArgumentList @("-command", "$wins_path srv app run")
foreach ($seconds in 1..120) {
logMessage "waiting for ~/.kube/k3s.yaml"
$found = test-path "~/.kube/k3s.yaml"
sleep 1; # always sleep (?give time for file to flush?)
if($found)
{
break;
}
}
logMessage "copying kubeconfig"
copy "~/.kube/k3s.yaml" "~/.kube/config"
foreach ($seconds in 1..120) {
$empty = kubectl get node $([Environment]::MachineName)
if($LASTEXITCODE -eq 0)
{
break;
}
sleep 1;
}
logMessage "node exists"
# test for 120 to see if node will go ready
kubectl wait --timeout=120s --for=condition=Ready node/$([Environment]::MachineName)
logMessage "node ready"
# wait till default serviceacount was created
foreach($retries in 1..120){
kubectl get serviceaccount default
if($LASTEXITCODE -eq 0){
break
}
}
logMessage "default serviceaccount created"
type $logs_file
kubectl get node
logMessage "done"