Skip to content

Commit 54ff8ef

Browse files
jaer-tsunYongli Chen
authored andcommitted
Adding powershell script to call cni. (#282)
1 parent 96b4401 commit 54ff8ef

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

scripts/Invoke-wincni.ps1

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Param(
2+
[parameter(Mandatory=$true)]
3+
[string] $containerName,
4+
5+
[parameter(Mandatory=$true)]
6+
[string] $namespace,
7+
8+
[parameter(Mandatory=$true)]
9+
[string] $image,
10+
11+
[parameter (Mandatory=$true)]
12+
[string] $command
13+
)
14+
15+
$contid=''
16+
17+
if ( $command -eq 'ADD' ) {
18+
$contid=(docker run -d --name $containerName --net=none $image powershell Start-Sleep -m 1000000)
19+
$env:CNI_CONTAINERID=$contid
20+
$env:CNI_COMMAND='ADD'
21+
}
22+
else {
23+
$contid=(docker inspect -f '{{ .Id }}' $containerName)
24+
$env:CNI_CONTAINERID=$contid
25+
$env:CNI_COMMAND='DEL'
26+
}
27+
28+
$env:CNI_NETNS='none'
29+
$env:CNI_PATH='C:\k\azurecni\bin'
30+
$env:PATH="$env:CNI_PATH;"+$env:PATH
31+
$k8sargs='IgnoreUnknown=1;K8S_POD_NAMESPACE={0};K8S_POD_NAME={1};K8S_POD_INFRA_CONTAINER_ID={2}' -f $namespace, $containerName, $contid
32+
$env:CNI_ARGS=$k8sargs
33+
$env:CNI_IFNAME='eth0'
34+
35+
$config=(jq-win64 '.plugins[0]' C:\k\azurecni\netconf\10-azure.conflist)
36+
$name=(jq-win64 -r '.name' C:\k\azurecni\netconf\10-azure.conflist)
37+
$config=(echo $config | jq-win64 --arg name $name '. + {name: $name}')
38+
$cniVersion=(jq-win64 -r '.cniVersion' C:\k\azurecni\netconf\10-azure.conflist)
39+
$config=(echo $config | jq-win64 --arg cniVersion $cniVersion '. + {cniVersion: $cniVersion}')
40+
41+
$res=(echo $config | azure-vnet)
42+
43+
echo $res

0 commit comments

Comments
 (0)