-
Notifications
You must be signed in to change notification settings - Fork 0
Initial UTs. #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: xz/arc-gateway
Are you sure you want to change the base?
Initial UTs. #1
Changes from all commits
44f842a
9aab153
46e6876
ff3eb68
40d6589
ec731db
30706d9
60464a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,21 +12,16 @@ function Invoke-ConfigDPHealthCheck { | |
| $apiVersion = "2024-07-01-preview" | ||
| $chartLocationUrlSegment = "azure-arc-k8sagents/healthCheck?api-version=$apiVersion" | ||
| $chartLocationUrl = "$configDPEndpoint/$chartLocationUrlSegment" | ||
| $uriParameters = @{} | ||
| $uriParameters = [ordered]@{} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why ordered? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to be able to test and without "ordered" you cannot be sure what order the resulting URI string will have the parameters in. |
||
| $headers = @{} | ||
| # Check if key AZURE_ACCESS_TOKEN exists in environment variables | ||
| if ($env:AZURE_ACCESS_TOKEN) { | ||
| $headers = @{"Authorization"="Bearer $($env['AZURE_ACCESS_TOKEN'])"} | ||
| } | ||
|
|
||
| # Sending request with retries | ||
| # $r = Invoke-RestMethodWithRetries -method 'post' -url $chartLocationUrl -headers $headers -faultType $consts.Get_HelmRegistery_Path_Fault_Type -summary 'Error while performing DP health check' -uriParameters $uriParameters -resource $resource | ||
| Invoke-RestMethodWithUriParameters -Method 'post' -Uri $chartLocationUrl -Headers $headers -UriParameters $uriParameters -MaximumRetryCount 5 -RetryIntervalSec 3 -StatusCodeVariable statusCode | ||
| if ($statusCode -eq 200) { | ||
| Write-Output "Health check for DP is successful." | ||
| return $true | ||
| } | ||
| else { | ||
| if ($statusCode -ne 200) { | ||
papadeltasierra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| throw "Error while performing DP health check, StatusCode: ${statusCode}" | ||
| } | ||
| } | ||
|
|
@@ -53,23 +48,28 @@ function Get-ConfigDPEndpoint { | |
| # $ReleaseTrain = $result.ReleaseTrain | ||
| # } | ||
|
|
||
| # It is currently not clear what information might appear here in the future | ||
| # so the check of "arcConfigEndpoint" is left is a best guess!". | ||
| # Get the values or endpoints required for retrieving the Helm registry URL. | ||
| if ($cloudMetadata.dataplaneEndpoints -and $cloudMetadata.dataplaneEndpoints.arcConfigEndpoint) { | ||
| $ConfigDpEndpoint = $armMetadata.dataplaneEndpoints.arcConfigEndpoint | ||
| if ($null -ne $cloudMetadata.ArcConfigEndpoint) { | ||
| $ConfigDpEndpoint = $cloudMetadata.ArcConfigEndpoint | ||
| } | ||
| else { | ||
| Write-Debug "'arcConfigEndpoint' doesn't exist under 'dataplaneEndpoints' in the ARM metadata." | ||
| Write-Debug "'ArcConfigEndpoint' doesn't exist in the ARM cloud metadata." | ||
| } | ||
|
|
||
| # Get the default config dataplane endpoint. | ||
| if (-not $ConfigDpEndpoint) { | ||
| if ($null -eq $ConfigDpEndpoint) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Invoke-ScriptAnalyzer prefers this way around. Not totally sure why but I do know in "C" that this was preferred incase you mistyped |
||
| $ConfigDpEndpoint = Get-ConfigDpDefaultEndpoint -Location $Location -CloudMetadata $cloudMetadata | ||
| } | ||
| $ADResourceId = Get-AZCloudMetadataResourceId -CloudMetadata $cloudMetadata | ||
| # !!PDS: This appears to be unused. | ||
| # $ADResourceId = Get-AZCloudMetadataResourceId -CloudMetadata $cloudMetadata | ||
| $ADResourceId = $null | ||
|
|
||
| return @{ ConfigDpEndpoint = $ConfigDpEndpoint; ReleaseTrain = $ReleaseTrain; ADResourceId = $ADResourceId } | ||
| } | ||
|
|
||
| # !!PDS: What? Looks like there is a function to do this? Perhaps because we did not hide it? | ||
| function Get-ConfigDpDefaultEndpoint { | ||
| param ( | ||
| [Parameter(Mandatory=$true)] | ||
|
|
@@ -78,10 +78,13 @@ function Get-ConfigDpDefaultEndpoint { | |
| [PSCustomObject]$cloudMetadata | ||
| ) | ||
|
|
||
| # Search the $armMetadata hash for the entry where the "name" parameter matches | ||
| # $cloud and then find the login endpoint, from which we can discern the | ||
| # appropriate "cloud based domain ending". | ||
| $cloudBasedDomain = ($cloudMetadata.authentication.loginEndpoint -split "\.")[2] | ||
| # The DP endpoint uses the same final URL portion as the AAD authority. But | ||
| # we also need to trim the trailing "/". | ||
| $cloudBasedDomain = ($cloudMetadata.ActiveDirectoryAuthority -split "\.")[2] | ||
|
|
||
| # Remove optional trailing "/" from $cloudBasedDomain | ||
| $cloudBasedDomain = $cloudBasedDomain.TrimEnd('/') | ||
|
|
||
| $configDpEndpoint = "https://${location}.dp.kubernetesconfiguration.azure.${cloudBasedDomain}" | ||
| return $configDpEndpoint | ||
| } | ||
|
|
@@ -91,7 +94,7 @@ function Invoke-RestMethodWithUriParameters { | |
| [String]$method, | ||
| [String]$uri, | ||
| [Hashtable]$headers, | ||
| [Hashtable]$uriParameters, | ||
| [System.Collections.Specialized.OrderedDictionary]$uriParameters, | ||
| [String]$requestBody, | ||
| [Int]$maximumRetryCount, | ||
| [Int]$retryIntervalSec, | ||
|
|
@@ -100,21 +103,33 @@ function Invoke-RestMethodWithUriParameters { | |
|
|
||
| # Add URI parameters to end of URL if there are any. | ||
| $uriParametersArray = @() | ||
| foreach ($Key in $hash.Keys) { | ||
| $uriParametersArray.Add("$($Key)=$($UriParameters[$Key])") | ||
| $uriParametersString = $uriParametersArray -join '&' | ||
| $uri = "$url?$uriParametersString" | ||
| if ($uriParameters.count -gt 0) { | ||
| # Create an array by joining hash index and value using '=' | ||
| $uriParametersArray = $uriParameters.GetEnumerator() | ForEach-Object { "$($_.Key)=$($_.Value)" } | ||
| $uriParametersString = $uriParametersArray -join "&" | ||
| $uri = $uri + "?" + $uriParametersString | ||
| # Write-Error "URI: >$uri<" | ||
| } | ||
|
|
||
| # if ($uriParameters.count -gt 0) { | ||
| # # Create an array by joining hash index and value using '=' and join them using '&' | ||
| # $uriParametersArray = $uriParameters.GetEnumerator() | ForEach-Object { "$($_.Key)=$($_.Value)" } | ForEach-Object { $_ -join '=' } | ForEach-Object { $_ -join '&' } | ||
| # } | ||
| Write-Debug "Issue REST request to ${uri} with method ${method} and headers ${headers} and body ${requestBody}" | ||
| $rsp = Invoke-RestMethod -Method $method -Uri $uri -Headers $headers -Body $requestBody -ContentType "application/json" -MaximumRetryCount $maximumRetryCount -RetryIntervalSec $retryintervalSec -StatusCodeVariable statusCode | ||
| $rsp = Invoke-RestMethod ` | ||
| -Method $method ` | ||
| -Uri $uri ` | ||
| -Headers $headers ` | ||
| -Body $requestBody ` | ||
| -ContentType "application/json" ` | ||
| -MaximumRetryCount $maximumRetryCount ` | ||
| -RetryIntervalSec $retryintervalSec ` | ||
| -StatusCodeVariable statusCode ` | ||
| -Verbose:($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent -eq $true) ` | ||
| -Debug:($PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent -eq $true) | ||
|
|
||
| Write-Debug "Response: $($rsp | ConvertTo-Json -Depth 10)" | ||
|
|
||
| Set-Variable -Name "${statusCodeVariable}" -Value $statusCode -Scope script | ||
| if ($statusCode -ne 200) { | ||
| throw "health check failed, StatusCode: ${statusCode}." | ||
| } | ||
| return $rsp | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why removing this block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it is replaced by the code below.