@@ -54,12 +54,55 @@ function New-AzConnectedKubernetes {
54
54
# The ID of the target subscription.
55
55
${SubscriptionId} ,
56
56
57
+ [Parameter ()]
58
+ [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category (' Path' )]
59
+ [System.Uri ]
60
+ # The http URI of the proxy server for the kubernetes cluster to use
61
+ ${HttpProxy} ,
62
+
63
+ [Parameter ()]
64
+ [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category (' Path' )]
65
+ [System.Uri ]
66
+ # The https URI of the proxy server for the kubernetes cluster to use
67
+ ${HttpsProxy} ,
68
+
69
+ [Parameter ()]
70
+ [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category (' Path' )]
71
+ [System.String ]
72
+ # The comma-separated list of hostnames that should be excluded from the proxy server for the kubernetes cluster to use
73
+ ${NoProxy} ,
74
+
75
+ [Parameter ()]
76
+ [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category (' Path' )]
77
+ [System.String ]
78
+ # The path to the certificate file for proxy or custom Certificate Authority.
79
+ ${ProxyCert} ,
80
+
81
+ [Parameter ()]
82
+ [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category (' Path' )]
83
+ [ValidateRange (0 , 3600 )]
84
+ [Int ]
85
+ # The time required (in seconds) for the arc-agent pods to be installed on the kubernetes cluster.
86
+ ${OnboardingTimeout} = 600 ,
87
+
88
+ [Parameter ()]
89
+ [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category (' Path' )]
90
+ [System.Management.Automation.SwitchParameter ]
91
+ # Flag to disable auto upgrade of arc agents.
92
+ ${DisableAutoUpgrade} ,
93
+
94
+ [Parameter ()]
95
+ [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category (' Path' )]
96
+ [System.String ]
97
+ # Override the default container log path to enable fluent-bit logging.
98
+ ${ContainerLogPath} ,
99
+
57
100
[Parameter (HelpMessage = " Path to the kube config file" )]
58
101
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category (' Body' )]
59
102
[System.String ]
60
103
# Path to the kube config file
61
104
${KubeConfig} ,
62
-
105
+
63
106
[Parameter (HelpMessage = " Kubconfig context from current machine" )]
64
107
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category (' Body' )]
65
108
[System.String ]
@@ -172,14 +215,14 @@ function New-AzConnectedKubernetes {
172
215
[Parameter (DontShow)]
173
216
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category (' Runtime' )]
174
217
[System.Uri ]
175
- # The URI for the proxy server to use
218
+ # The URI of the proxy server for host os to use
176
219
${Proxy} ,
177
220
178
221
[Parameter (DontShow)]
179
222
[ValidateNotNull ()]
180
223
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category (' Runtime' )]
181
224
[System.Management.Automation.PSCredential ]
182
- # Credentials for a proxy server to use for the remote call
225
+ # The credential of the proxy server for host os to use
183
226
${ProxyCredential} ,
184
227
185
228
[Parameter (DontShow)]
@@ -224,7 +267,7 @@ function New-AzConnectedKubernetes {
224
267
if ($PSBoundParameters.ContainsKey (' KubeContext' )) {
225
268
$Null = $PSBoundParameters.Remove (' KubeContext' )
226
269
}
227
- if (($KubeContext -eq $null ) -or ($KubeContext -eq ' ' )) {
270
+ if (($null -eq $KubeContext ) -or ($KubeContext -eq ' ' )) {
228
271
$KubeContext = kubectl config current- context
229
272
}
230
273
@@ -260,9 +303,10 @@ function New-AzConnectedKubernetes {
260
303
# EndRegion
261
304
262
305
# Region get release namespace
306
+ Set-Variable ReleaseInstallNamespace - option Constant - value " azure-arc-release"
263
307
$ReleaseNamespace = $null
264
308
try {
265
- $ReleaseNamespace = (helm status azure- arc - o json -- kubeconfig $KubeConfig -- kube- context $KubeContext | ConvertFrom-Json ).namespace
309
+ $ReleaseNamespace = (helm status azure- arc - o json -- kubeconfig $KubeConfig -- kube- context $KubeContext - n $ReleaseInstallNamespace | ConvertFrom-Json ).namespace
266
310
} catch {
267
311
Write-Error " Fail to find the namespace for azure-arc."
268
312
}
@@ -302,6 +346,15 @@ function New-AzConnectedKubernetes {
302
346
} else {
303
347
$ReleaseTrain = ' stable'
304
348
}
349
+
350
+ $AzLocation = Get-AzLocation | Where-Object { ($_.DisplayName -ieq $Location ) -or ($_.Location -ieq $Location )}
351
+ $Region = $AzLocation.Location
352
+ if ($null -eq $Region ) {
353
+ Write-Error " Invalid location: $Location "
354
+ return
355
+ } else {
356
+ $Location = $Region
357
+ }
305
358
$ChartLocationUrl = " https://${Location} .dp.kubernetesconfiguration.azure.com/azure-arc-k8sagents/GetLatestHelmPackagePath?api-version=2019-11-01-preview&releaseTrain=${ReleaseTrain} "
306
359
307
360
$Uri = [System.Uri ]::New($ChartLocationUrl )
@@ -315,7 +368,7 @@ function New-AzConnectedKubernetes {
315
368
$HeaderParameter = @ {
316
369
" Authorization" = " Bearer $AccessToken "
317
370
}
318
- $Response = Invoke-WebRequest - Uri $Uri - Headers $HeaderParameter - Method Post
371
+ $Response = Invoke-WebRequest - Uri $Uri - Headers $HeaderParameter - Method Post - UseBasicParsing
319
372
if ($Response.StatusCode -eq 200 ) {
320
373
$RegisteryPath = ($Response.Content | ConvertFrom-Json ).repositoryPath
321
374
} else {
@@ -354,27 +407,104 @@ function New-AzConnectedKubernetes {
354
407
. " $PSScriptRoot /../utils/RSAHelper.ps1"
355
408
$AgentPublicKey = ExportRSAPublicKeyBase64($RSA )
356
409
$AgentPrivateKey = ExportRSAPrivateKeyBase64($RSA )
410
+ $AgentPrivateKey = " -----BEGIN RSA PRIVATE KEY-----`n " + $AgentPrivateKey + " `n -----END RSA PRIVATE KEY-----"
357
411
} catch {
358
412
Write-Error " Unable to generate RSA keys"
359
413
throw
360
414
}
361
415
} else {
362
416
$AgentPublicKey = [System.Convert ]::ToBase64String($RSA.ExportRSAPublicKey ())
363
- $AgentPrivateKey = " -----BEGIN RSA PRIVATE KEY-----`n " + [System.Convert ]::ToBase64String($RSA.ExportRSAPrivateKey ()) + " `n -----END RSA PRIVATE KEY-----"
417
+ $AgentPrivateKey = " -----BEGIN RSA PRIVATE KEY-----`n " + [System.Convert ]::ToBase64String($RSA.ExportRSAPrivateKey ()) + " `n -----END RSA PRIVATE KEY-----"
364
418
}
365
-
419
+
366
420
$HelmChartPath = Join-Path - Path $ChartExportPath - ChildPath ' azure-arc-k8sagents'
367
421
if (Test-Path Env:HELMCHART) {
368
422
$ChartPath = Get-ChildItem - Path Env:HELMCHART
369
423
} else {
370
424
$ChartPath = $HelmChartPath
371
425
}
372
426
427
+ # Region helm options
428
+ $options = " "
429
+ $proxyEnableState = $false
430
+ if (-not ([string ]::IsNullOrEmpty($HttpProxy ))) {
431
+ $HttpProxyStr = $HttpProxy.ToString ()
432
+ $HttpProxyStr = $HttpProxyStr -replace ' ,' , ' \,'
433
+ $HttpProxyStr = $HttpProxyStr -replace ' /' , ' \/'
434
+ $options += " --set global.httpProxy=$HttpProxyStr "
435
+ $proxyEnableState = $true
436
+ $Null = $PSBoundParameters.Remove (' HttpProxy' )
437
+ }
438
+ if (-not ([string ]::IsNullOrEmpty($HttpsProxy ))) {
439
+ $HttpsProxyStr = $HttpsProxy.ToString ()
440
+ $HttpsProxyStr = $HttpsProxyStr -replace ' ,' , ' \,'
441
+ $HttpsProxyStr = $HttpsProxyStr -replace ' /' , ' \/'
442
+ $options += " --set global.httpsProxy=$HttpsProxyStr "
443
+ $proxyEnableState = $true
444
+ $Null = $PSBoundParameters.Remove (' HttpsProxy' )
445
+ }
446
+ if (-not ([string ]::IsNullOrEmpty($NoProxy ))) {
447
+ $NoProxy = $NoProxy -replace ' ,' , ' \,'
448
+ $NoProxy = $NoProxy -replace ' /' , ' \/'
449
+ $options += " --set global.noProxy=$NoProxy "
450
+ $proxyEnableState = $true
451
+ $Null = $PSBoundParameters.Remove (' NoProxy' )
452
+ }
453
+ if ($proxyEnableState ) {
454
+ $options += " --set global.isProxyEnabled=true"
455
+ }
456
+ try {
457
+ if ((-not ([string ]::IsNullOrEmpty($ProxyCert ))) -and (Test-Path $ProxyCert )) {
458
+ $options += " --set-file global.proxyCert=$ProxyCert "
459
+ $options += " --set global.isCustomCert=true"
460
+ }
461
+ } catch {
462
+ Write-Error " Unable to find ProxyCert from file path"
463
+ throw
464
+ }
465
+ if ($DisableAutoUpgrade ) {
466
+ $options += " --set systemDefaultValues.azureArcAgents.autoUpdate=false"
467
+ $Null = $PSBoundParameters.Remove (' DisableAutoUpgrade' )
468
+ }
469
+ if (-not ([string ]::IsNullOrEmpty($ContainerLogPath ))) {
470
+ $options += " --set systemDefaultValues.fluent-bit.containerLogPath=$ContainerLogPath "
471
+ $Null = $PSBoundParameters.Remove (' ContainerLogPath' )
472
+ }
473
+ if (-not ([string ]::IsNullOrEmpty($KubeConfig ))) {
474
+ $options += " --kubeconfig $KubeConfig "
475
+ }
476
+ if (-not ([string ]::IsNullOrEmpty($KubeContext ))) {
477
+ $options += " --kube-context $KubeContext "
478
+ }
479
+ if (! $NoWait ) {
480
+ $options += " --wait --timeout $OnboardingTimeout "
481
+ $options += " s"
482
+ }
483
+ # Endregion
484
+ if ($PSBoundParameters.ContainsKey (' OnboardingTimeout' )) {
485
+ $PSBoundParameters.Remove (' OnboardingTimeout' )
486
+ }
487
+ if ((-not ([string ]::IsNullOrEmpty($Proxy ))) -and (-not $PSBoundParameters.ContainsKey (' ProxyCredential' ))) {
488
+ if (-not ([string ]::IsNullOrEmpty($Proxy.UserInfo ))) {
489
+ try {
490
+ $userInfo = $Proxy.UserInfo -Split ' :'
491
+ $pass = ConvertTo-SecureString $userInfo [1 ] - AsPlainText - Force
492
+ $ProxyCredential = New-Object System.Management.Automation.PSCredential ($userInfo [0 ] , $pass )
493
+ $PSBoundParameters.Add (' ProxyCredential' , $ProxyCredential )
494
+ } catch {
495
+ Write-Warning " Please set ProxyCredential or provide username and password in the Proxy parameter"
496
+ throw
497
+ }
498
+ } else {
499
+ Write-Warning " If the proxy is a private proxy, pass ProxyCredential parameter or provide username and password in the Proxy parameter"
500
+ }
501
+ }
502
+
373
503
$PSBoundParameters.Add (' AgentPublicKeyCertificate' , $AgentPublicKey )
374
504
$Response = Az.ConnectedKubernetes.internal\New-AzConnectedKubernetes @PSBoundParameters
375
505
376
- $TenantId = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider ]::Instance.Profile.DefaultContext.Tenant.Id
377
- helm upgrade -- install azure- arc $ChartPath -- set global.subscriptionId= $SubscriptionId -- set global.resourceGroupName= $ResourceGroupName -- set global.resourceName= $ClusterName -- set global.tenantId= $TenantId -- set global.location= $Location -- set global.onboardingPrivateKey= $AgentPrivateKey -- set systemDefaultValues.spnOnboarding= false -- set global.azureEnvironment= AZUREPUBLICCLOUD -- set systemDefaultValues.clusterconnect- agent.enabled= true -- set global.kubernetesDistro= $Distribution -- set global.kubernetesInfra= $Infrastructure -- kubeconfig $KubeConfig -- kube - context $KubeContext -- wait -- timeout 600s
506
+ $TenantId = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider ]::Instance.Profile.DefaultContext.Tenant.Id
507
+ helm upgrade -- install azure- arc $ChartPath -- namespace $ReleaseInstallNamespace -- create - namespace -- set global.subscriptionId= $SubscriptionId -- set global.resourceGroupName= $ResourceGroupName -- set global.resourceName= $ClusterName -- set global.tenantId= $TenantId -- set global.location= $Location -- set global.onboardingPrivateKey= $AgentPrivateKey -- set systemDefaultValues.spnOnboarding= false -- set global.azureEnvironment= AZUREPUBLICCLOUD -- set systemDefaultValues.clusterconnect- agent.enabled= true -- set global.kubernetesDistro= $Distribution -- set global.kubernetesInfra= $Infrastructure ( -split $options )
378
508
Return $Response
379
509
}
380
510
}
0 commit comments