@@ -54,12 +54,55 @@ function New-AzConnectedKubernetes {
5454 # The ID of the target subscription.
5555 ${SubscriptionId} ,
5656
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+
57100 [Parameter (HelpMessage = " Path to the kube config file" )]
58101 [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category (' Body' )]
59102 [System.String ]
60103 # Path to the kube config file
61104 ${KubeConfig} ,
62-
105+
63106 [Parameter (HelpMessage = " Kubconfig context from current machine" )]
64107 [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category (' Body' )]
65108 [System.String ]
@@ -172,14 +215,14 @@ function New-AzConnectedKubernetes {
172215 [Parameter (DontShow)]
173216 [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category (' Runtime' )]
174217 [System.Uri ]
175- # The URI for the proxy server to use
218+ # The URI of the proxy server for host os to use
176219 ${Proxy} ,
177220
178221 [Parameter (DontShow)]
179222 [ValidateNotNull ()]
180223 [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category (' Runtime' )]
181224 [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
183226 ${ProxyCredential} ,
184227
185228 [Parameter (DontShow)]
@@ -224,7 +267,7 @@ function New-AzConnectedKubernetes {
224267 if ($PSBoundParameters.ContainsKey (' KubeContext' )) {
225268 $Null = $PSBoundParameters.Remove (' KubeContext' )
226269 }
227- if (($KubeContext -eq $null ) -or ($KubeContext -eq ' ' )) {
270+ if (($null -eq $KubeContext ) -or ($KubeContext -eq ' ' )) {
228271 $KubeContext = kubectl config current- context
229272 }
230273
@@ -260,9 +303,10 @@ function New-AzConnectedKubernetes {
260303 # EndRegion
261304
262305 # Region get release namespace
306+ Set-Variable ReleaseInstallNamespace - option Constant - value " azure-arc-release"
263307 $ReleaseNamespace = $null
264308 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
266310 } catch {
267311 Write-Error " Fail to find the namespace for azure-arc."
268312 }
@@ -302,6 +346,15 @@ function New-AzConnectedKubernetes {
302346 } else {
303347 $ReleaseTrain = ' stable'
304348 }
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+ }
305358 $ChartLocationUrl = " https://${Location} .dp.kubernetesconfiguration.azure.com/azure-arc-k8sagents/GetLatestHelmPackagePath?api-version=2019-11-01-preview&releaseTrain=${ReleaseTrain} "
306359
307360 $Uri = [System.Uri ]::New($ChartLocationUrl )
@@ -315,7 +368,7 @@ function New-AzConnectedKubernetes {
315368 $HeaderParameter = @ {
316369 " Authorization" = " Bearer $AccessToken "
317370 }
318- $Response = Invoke-WebRequest - Uri $Uri - Headers $HeaderParameter - Method Post
371+ $Response = Invoke-WebRequest - Uri $Uri - Headers $HeaderParameter - Method Post - UseBasicParsing
319372 if ($Response.StatusCode -eq 200 ) {
320373 $RegisteryPath = ($Response.Content | ConvertFrom-Json ).repositoryPath
321374 } else {
@@ -354,27 +407,104 @@ function New-AzConnectedKubernetes {
354407 . " $PSScriptRoot /../utils/RSAHelper.ps1"
355408 $AgentPublicKey = ExportRSAPublicKeyBase64($RSA )
356409 $AgentPrivateKey = ExportRSAPrivateKeyBase64($RSA )
410+ $AgentPrivateKey = " -----BEGIN RSA PRIVATE KEY-----`n " + $AgentPrivateKey + " `n -----END RSA PRIVATE KEY-----"
357411 } catch {
358412 Write-Error " Unable to generate RSA keys"
359413 throw
360414 }
361415 } else {
362416 $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-----"
364418 }
365-
419+
366420 $HelmChartPath = Join-Path - Path $ChartExportPath - ChildPath ' azure-arc-k8sagents'
367421 if (Test-Path Env:HELMCHART) {
368422 $ChartPath = Get-ChildItem - Path Env:HELMCHART
369423 } else {
370424 $ChartPath = $HelmChartPath
371425 }
372426
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+
373503 $PSBoundParameters.Add (' AgentPublicKeyCertificate' , $AgentPublicKey )
374504 $Response = Az.ConnectedKubernetes.internal\New-AzConnectedKubernetes @PSBoundParameters
375505
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 )
378508 Return $Response
379509 }
380510}
0 commit comments