Repository navigation
Add 'Arc' keyword to --proxy-skip-range for Azure Arc private-link endpoints #61
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
Changes from all commits
8c66c5c
2371c3a
94439ef
6c4f3d0
571e68c
5324e65
a361557
6eadcf9
d3d5f87
cd629be
4f4c77c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Tareesh21 marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,17 @@ | |
| import os | ||
|
Tareesh21 marked this conversation as resolved.
|
||
| import sys | ||
| from typing import Dict, Optional | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
| from kubernetes.client.models import V1Node, V1NodeList, V1NodeSpec, V1ObjectMeta | ||
|
|
||
| sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../.."))) | ||
| from azext_connectedk8s.custom import get_kubernetes_distro, get_kubernetes_infra | ||
| from azext_connectedk8s.custom import ( | ||
| expand_proxy_skip_range_keywords, | ||
| get_kubernetes_distro, | ||
| get_kubernetes_infra, | ||
| ) | ||
|
|
||
|
|
||
| def create_node( | ||
|
|
@@ -86,3 +91,91 @@ def test_distro_invalid_metadata(): | |
| node = create_node(provider_id="aws://node1", labels=None, annotations=None) | ||
| api_response = V1NodeList(items=[node]) | ||
| assert get_kubernetes_distro(api_response) == "generic" | ||
|
|
||
|
|
||
| # --------------------- Tests for expand_proxy_skip_range_keywords --------------------- | ||
| def _proxy_cmd(active_directory="https://login.microsoftonline.com"): | ||
| cmd = MagicMock() | ||
| cmd.cli_ctx.cloud.endpoints.active_directory = active_directory | ||
| return cmd | ||
|
|
||
|
|
||
| ARC_PUBLIC = ( | ||
| ".his.arc.azure.com," | ||
| ".dp.kubernetesconfiguration.azure.com," | ||
| ".guestconfiguration.azure.com" | ||
| ) | ||
|
|
||
|
|
||
| def test_expand_arc_keyword_public_cloud(): | ||
| assert expand_proxy_skip_range_keywords(_proxy_cmd(), "Arc") == ARC_PUBLIC | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("keyword", ["Arc", "arc", "ARC", " aRc "]) | ||
| def test_expand_arc_keyword_is_case_and_space_insensitive(keyword): | ||
| assert expand_proxy_skip_range_keywords(_proxy_cmd(), keyword) == ARC_PUBLIC | ||
|
|
||
|
|
||
| def test_expand_arc_keyword_preserves_other_entries(): | ||
| out = expand_proxy_skip_range_keywords(_proxy_cmd(), "Arc,10.0.0.0/16,.svc") | ||
| assert out == ARC_PUBLIC + ",10.0.0.0/16,.svc" | ||
|
|
||
|
|
||
| def test_expand_arc_keyword_china_cloud(): | ||
| cmd = _proxy_cmd("https://login.chinacloudapi.cn") | ||
| out = expand_proxy_skip_range_keywords(cmd, "Arc") | ||
| assert out == ( | ||
| ".his.arc.azure.cn," | ||
| ".dp.kubernetesconfiguration.azure.cn," | ||
| ".guestconfiguration.azure.cn" | ||
| ) | ||
|
|
||
|
|
||
| def test_expand_arc_keyword_usgov_cloud(): | ||
|
Tareesh21 marked this conversation as resolved.
|
||
| cmd = _proxy_cmd("https://login.microsoftonline.us") | ||
| out = expand_proxy_skip_range_keywords(cmd, "Arc") | ||
|
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.
Author
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. Updated. 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. ok |
||
| assert out == ( | ||
| ".his.arc.azure.us," | ||
| ".dp.kubernetesconfiguration.azure.us," | ||
| ".guestconfiguration.azure.us" | ||
| ) | ||
|
|
||
|
|
||
| def test_expand_arc_keyword_ussec_cloud(): | ||
| cmd = _proxy_cmd("https://login.microsoftonline.microsoft.scloud") | ||
| out = expand_proxy_skip_range_keywords(cmd, "Arc") | ||
| assert out == ( | ||
| ".his.arc.azure.microsoft.scloud," | ||
| ".dp.kubernetesconfiguration.azure.microsoft.scloud," | ||
| ".guestconfiguration.azure.microsoft.scloud" | ||
| ) | ||
|
|
||
|
|
||
| def test_expand_arc_keyword_usnat_cloud(): | ||
| cmd = _proxy_cmd("https://login.microsoftonline.eaglex.ic.gov") | ||
| out = expand_proxy_skip_range_keywords(cmd, "Arc") | ||
| assert out == ( | ||
| ".his.arc.azure.eaglex.ic.gov," | ||
| ".dp.kubernetesconfiguration.azure.eaglex.ic.gov," | ||
| ".guestconfiguration.azure.eaglex.ic.gov" | ||
| ) | ||
|
|
||
|
|
||
| def test_expand_no_keyword_returns_unchanged(): | ||
| val = "10.0.0.0/16,.svc,localhost" | ||
| assert expand_proxy_skip_range_keywords(_proxy_cmd(), val) == val | ||
|
|
||
|
|
||
| def test_expand_empty_returns_unchanged(): | ||
| assert expand_proxy_skip_range_keywords(_proxy_cmd(), "") == "" | ||
|
|
||
|
|
||
| def test_expand_arc_keyword_deduplicates(): | ||
| out = expand_proxy_skip_range_keywords(_proxy_cmd(), "Arc,Arc") | ||
| assert out == ARC_PUBLIC | ||
|
|
||
|
|
||
| def test_expand_arc_keyword_dedups_case_insensitive_endpoint(): | ||
| # A user endpoint differing only in case is not duplicated in NO_PROXY. | ||
| out = expand_proxy_skip_range_keywords(_proxy_cmd(), "Arc, .his.ARC.azure.com") | ||
| assert out == ARC_PUBLIC | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,36 @@ Describe 'Proxy Scenario' { | |
| $n | Should -BeLessOrEqual $MAX_RETRY_ATTEMPTS | ||
| } | ||
|
|
||
| It 'Expands the Arc keyword in --proxy-skip-range to the Azure Arc private-link endpoints' { | ||
| az connectedk8s update -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --proxy-skip-range Arc | ||
|
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.
Author
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. Connect and update both call the same function. Since we've already added the update scenario with Arc, adding a connect scenario here would just duplicate the same logic. |
||
| $? | Should -BeTrue | ||
| Start-Sleep -Seconds 10 | ||
|
|
||
| # Loop and retry until the Arc keyword expands into the no-proxy list | ||
| $n = 0 | ||
| do | ||
| { | ||
| $output = az connectedk8s show -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup | ||
| $provisioningState = ($output | ConvertFrom-Json).provisioningState | ||
| Write-Host "Provisioning State: $provisioningState" | ||
| if ($provisioningState -eq $SUCCEEDED) { | ||
| $noProxy = helm get values -n azure-arc-release azure-arc -o yaml | grep noProxy | ||
| Write-Host "$noProxy" | ||
| if ($noProxy -match "\.his\.arc\.azure") { | ||
| break | ||
| } | ||
| } | ||
| Start-Sleep -Seconds 10 | ||
| $n += 1 | ||
| } while ($n -le $MAX_RETRY_ATTEMPTS) | ||
| $n | Should -BeLessOrEqual $MAX_RETRY_ATTEMPTS | ||
|
|
||
| $noProxy = helm get values -n azure-arc-release azure-arc -o yaml | grep noProxy | ||
| $noProxy | Should -Match "\.his\.arc\.azure" | ||
| $noProxy | Should -Match "\.dp\.kubernetesconfiguration\.azure" | ||
| $noProxy | Should -Match "\.guestconfiguration\.azure" | ||
| } | ||
|
|
||
| It 'Disable proxy' { | ||
| az connectedk8s update -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --disable-proxy | ||
| $? | Should -BeTrue | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.