@@ -12,9 +12,6 @@ using module "..\Private\CommonToolUtilities.psm1"
12
12
$ModuleParentPath = Split-Path - Parent $PSScriptRoot
13
13
Import-Module - Name " $ModuleParentPath \Private\CommonToolUtilities.psm1" - Force
14
14
15
- $WINCNI_PLUGIN_REPO = " microsoft/windows-container-networking"
16
- $CLOUDNATIVE_CNI_REPO = " containernetworking/plugins"
17
-
18
15
function Get-WinCNILatestVersion {
19
16
param (
20
17
[String ]$repo = " microsoft/windows-container-networking"
@@ -37,8 +34,8 @@ function Install-WinCNIPlugin {
37
34
[parameter (HelpMessage = " Windows CNI plugin version to use. Defaults to 'latest'" )]
38
35
[string ]$WinCNIVersion = " latest" ,
39
36
40
- [parameter (HelpMessage = " Path to cni folder ~\cni . Not ~\cni\bin" )]
41
- [String ]$WinCNIPath ,
37
+ [parameter (HelpMessage = " Path to cni folder ~\cni (not ~\cni\bin). Defaults to `$ env:ProgramFiles\containerd\cni) " )]
38
+ [String ]$WinCNIPath = " $ env: ProgramFiles \containerd\cni " ,
42
39
43
40
[parameter (HelpMessage = " Source of the Windows CNI plugins. Defaults to 'microsoft/windows-container-networking'" )]
44
41
[ValidateSet (" microsoft/windows-container-networking" , " containernetworking/plugins" )]
@@ -112,13 +109,13 @@ function Install-WinCNIPlugin {
112
109
113
110
# Download file from repo
114
111
$downloadParams = @ {
115
- ToolName = " $ToolName "
116
- Repository = $SourceRepo
117
- Version = $WinCNIVersion
118
- OSArchitecture = $OSArchitecture
119
- DownloadPath = " $HOME \Downloads\"
112
+ ToolName = " $ToolName "
113
+ Repository = $SourceRepo
114
+ Version = $WinCNIVersion
115
+ OSArchitecture = $OSArchitecture
116
+ DownloadPath = " $HOME \Downloads\"
120
117
ChecksumSchemaFile = $null
121
- FileFilterRegEx = $fileFilterRegEx
118
+ FileFilterRegEx = $fileFilterRegEx
122
119
}
123
120
$downloadParamsProperties = [FileDownloadParameters ]::new(
124
121
$downloadParams.ToolName ,
@@ -133,10 +130,10 @@ function Install-WinCNIPlugin {
133
130
134
131
# Untar and install tool
135
132
$params = @ {
136
- Feature = " $ToolName "
137
- InstallPath = " $WinCNIPath \bin"
138
- SourceFile = $sourceFile
139
- cleanup = $true
133
+ Feature = " $ToolName "
134
+ InstallPath = " $WinCNIPath \bin"
135
+ SourceFile = $sourceFile
136
+ cleanup = $true
140
137
UpdateEnvPath = $false
141
138
}
142
139
Install-RequiredFeature @params
@@ -169,8 +166,8 @@ function Initialize-NatNetwork {
169
166
[parameter (HelpMessage = " Windows CNI plugins version to use. Defaults to latest version." )]
170
167
[String ]$WinCNIVersion ,
171
168
172
- [parameter (HelpMessage = " Absolute path to cni folder ~\cni. Not ~\cni\bin" )]
173
- [String ]$WinCNIPath ,
169
+ [parameter (HelpMessage = " Absolute path to cni folder ~\cni (not ~\cni\bin). Defaults to `$ env:ProgramFiles\containerd\cni) " )]
170
+ [String ]$WinCNIPath = " $ env: ProgramFiles \containerd\cni " ,
174
171
175
172
[parameter (HelpMessage = " Bypass confirmation to install any missing dependencies (Windows CNI plugins and HNS module)" )]
176
173
[Switch ] $Force
@@ -212,20 +209,27 @@ function Initialize-NatNetwork {
212
209
Throw " Could not import HNS module. $_ "
213
210
}
214
211
212
+ Write-Information - MessageData " Creating NAT network" - InformationAction Continue
213
+
214
+ # Install missing WinCNI plugins
215
+ if (! $isInstalled ) {
216
+ if ($force ) {
217
+ Write-Warning " Windows CNI plugins have not been installed. Installing Windows CNI plugins at '$WinCNIPath '"
218
+ Install-WinCNIPlugin - WinCNIPath $WinCNIPath - WinCNIVersion $WinCNIVersion - Force:$force
219
+ }
220
+ else {
221
+ Write-Warning " Couldn't initialize NAT network. CNI plugins have not been installed. To install, run the command `" Install-WinCNIPlugin`" ."
222
+ return
223
+ }
224
+ }
225
+
215
226
# Check of NAT exists
216
227
$natInfo = Get-HnsNetwork - ErrorAction Ignore | Where-Object { $_.Name -eq $networkName }
217
228
if ($null -ne $natInfo ) {
218
229
Write-Warning " $networkName already exists. To view existing networks, use `" Get-HnsNetwork`" . To remove the existing network use the `" Remove-HNSNetwork`" command."
219
230
return
220
231
}
221
232
222
- Write-Information - MessageData " Creating NAT network" - InformationAction Continue
223
-
224
- # Install missing WinCNI plugins
225
- if (! $isInstalled ) {
226
- Install-MissingPlugin - WinCNIVersion $WinCNIVersion - Force:$Force
227
- }
228
-
229
233
New-Item - ItemType ' Directory' - Path $cniConfDir - Force | Out-Null
230
234
231
235
# Check if `New-HNSNetwork` command exists
@@ -380,30 +384,6 @@ function Import-HNSModule {
380
384
Throw " `" HostNetworkingService`" or `" HNS`" module is not installed. To resolve this issue, see`n`t https://github.com/microsoft/containers-toolkit/blob/main/docs/FAQs.md#2-new-hnsnetwork-command-does-not-exist"
381
385
}
382
386
383
- function Install-MissingPlugin {
384
- param (
385
- [parameter (HelpMessage = " Windows CNI plugin version to use. Defaults to latest version" )]
386
- [string ]$WinCNIVersion ,
387
-
388
- [Switch ]$Force
389
- )
390
- # Get user consent to install missing dependencies
391
- $consent = $Force
392
- if (! $Force ) {
393
- $title = " Windows CNI plugins have not been installed."
394
- $question = " Do you want to install the Windows CNI plugins?"
395
- $choices = ' &Yes' , ' &No'
396
- $consent = ([ActionConsent ](Get-Host ).UI.PromptForChoice($title , $question , $choices , 1 )) -eq [ActionConsent ]::Yes
397
-
398
- if (-not $consent ) {
399
- Throw " Windows CNI plugins have not been installed. To install, run the command `" Install-WinCNIPlugin`" ."
400
- }
401
- }
402
-
403
- Install-WinCNIPlugin - WinCNIVersion $WinCNIVersion - Force:$consent
404
- }
405
-
406
-
407
387
# FIXME: nerdctl- Warning when user tries to run container with this network config
408
388
function Set-DefaultCNIConfig {
409
389
[CmdletBinding (
0 commit comments