@@ -34,8 +34,8 @@ function Install-WinCNIPlugin {
34
34
[parameter (HelpMessage = " Windows CNI plugin version to use. Defaults to 'latest'" )]
35
35
[string ]$WinCNIVersion = " latest" ,
36
36
37
- [parameter (HelpMessage = " Path to cni folder ~\cni . Not ~\cni\bin" )]
38
- [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 " ,
39
39
40
40
[parameter (HelpMessage = " Source of the Windows CNI plugins. Defaults to 'microsoft/windows-container-networking'" )]
41
41
[ValidateSet (" microsoft/windows-container-networking" , " containernetworking/plugins" )]
@@ -109,13 +109,13 @@ function Install-WinCNIPlugin {
109
109
110
110
# Download file from repo
111
111
$downloadParams = @ {
112
- ToolName = " $ToolName "
113
- Repository = $SourceRepo
114
- Version = $WinCNIVersion
115
- OSArchitecture = $OSArchitecture
116
- DownloadPath = " $HOME \Downloads\"
112
+ ToolName = " $ToolName "
113
+ Repository = $SourceRepo
114
+ Version = $WinCNIVersion
115
+ OSArchitecture = $OSArchitecture
116
+ DownloadPath = " $HOME \Downloads\"
117
117
ChecksumSchemaFile = $null
118
- FileFilterRegEx = $fileFilterRegEx
118
+ FileFilterRegEx = $fileFilterRegEx
119
119
}
120
120
$downloadParamsProperties = [FileDownloadParameters ]::new(
121
121
$downloadParams.ToolName ,
@@ -130,10 +130,10 @@ function Install-WinCNIPlugin {
130
130
131
131
# Untar and install tool
132
132
$params = @ {
133
- Feature = " $ToolName "
134
- InstallPath = " $WinCNIPath \bin"
135
- SourceFile = $sourceFile
136
- cleanup = $true
133
+ Feature = " $ToolName "
134
+ InstallPath = " $WinCNIPath \bin"
135
+ SourceFile = $sourceFile
136
+ cleanup = $true
137
137
UpdateEnvPath = $false
138
138
}
139
139
Install-RequiredFeature @params
@@ -166,8 +166,8 @@ function Initialize-NatNetwork {
166
166
[parameter (HelpMessage = " Windows CNI plugins version to use. Defaults to latest version." )]
167
167
[String ]$WinCNIVersion ,
168
168
169
- [parameter (HelpMessage = " Absolute path to cni folder ~\cni. Not ~\cni\bin" )]
170
- [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 " ,
171
171
172
172
[parameter (HelpMessage = " Bypass confirmation to install any missing dependencies (Windows CNI plugins and HNS module)" )]
173
173
[Switch ] $Force
@@ -209,20 +209,27 @@ function Initialize-NatNetwork {
209
209
Throw " Could not import HNS module. $_ "
210
210
}
211
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
+
212
226
# Check of NAT exists
213
227
$natInfo = Get-HnsNetwork - ErrorAction Ignore | Where-Object { $_.Name -eq $networkName }
214
228
if ($null -ne $natInfo ) {
215
229
Write-Warning " $networkName already exists. To view existing networks, use `" Get-HnsNetwork`" . To remove the existing network use the `" Remove-HNSNetwork`" command."
216
230
return
217
231
}
218
232
219
- Write-Information - MessageData " Creating NAT network" - InformationAction Continue
220
-
221
- # Install missing WinCNI plugins
222
- if (! $isInstalled ) {
223
- Install-MissingPlugin - WinCNIVersion $WinCNIVersion - Force:$Force
224
- }
225
-
226
233
New-Item - ItemType ' Directory' - Path $cniConfDir - Force | Out-Null
227
234
228
235
# Check if `New-HNSNetwork` command exists
@@ -377,30 +384,6 @@ function Import-HNSModule {
377
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"
378
385
}
379
386
380
- function Install-MissingPlugin {
381
- param (
382
- [parameter (HelpMessage = " Windows CNI plugin version to use. Defaults to latest version" )]
383
- [string ]$WinCNIVersion ,
384
-
385
- [Switch ]$Force
386
- )
387
- # Get user consent to install missing dependencies
388
- $consent = $Force
389
- if (! $Force ) {
390
- $title = " Windows CNI plugins have not been installed."
391
- $question = " Do you want to install the Windows CNI plugins?"
392
- $choices = ' &Yes' , ' &No'
393
- $consent = ([ActionConsent ](Get-Host ).UI.PromptForChoice($title , $question , $choices , 1 )) -eq [ActionConsent ]::Yes
394
-
395
- if (-not $consent ) {
396
- Throw " Windows CNI plugins have not been installed. To install, run the command `" Install-WinCNIPlugin`" ."
397
- }
398
- }
399
-
400
- Install-WinCNIPlugin - WinCNIVersion $WinCNIVersion - Force:$consent
401
- }
402
-
403
-
404
387
# FIXME: nerdctl- Warning when user tries to run container with this network config
405
388
function Set-DefaultCNIConfig {
406
389
[CmdletBinding (
0 commit comments