Skip to content

Commit

Permalink
[Network] az network private-endpoint-connection: Enable private li…
Browse files Browse the repository at this point in the history
…nk support for provider `Microsoft.KubernetesConfiguration/privateLinkScopes` (#23172)
  • Loading branch information
anagg929 authored Jul 12, 2022
1 parent f7133cb commit 63f9c99
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def register_providers():
_register_one_provider('Microsoft.Databricks/workspaces', '2021-04-01-preview', True)
_register_one_provider('Microsoft.RecoveryServices/vaults', '2021-07-01', True)
_register_one_provider('Microsoft.Kusto/clusters', '2021-08-27', True)
_register_one_provider("Microsoft.KubernetesConfiguration/privateLinkScopes", '2022-04-02-preview', True)


def _register_one_provider(provider, api_version, support_list_or_not, resource_get_api_version=None, support_connection_operation=True): # pylint: disable=line-too-long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3240,6 +3240,88 @@ def test_private_endpoint_pls(self):
)
self.cmd('network private-endpoint-connection delete -g {rg} --resource-name {pls} -n {request1} --type {type} --yes')

class NetworkKubernetesConfigurationPrivateLinkScopesTest(ScenarioTest):
@live_only()
@ResourceGroupPreparer(name_prefix='cli_test_kubernetesconfiguration_pe', random_name_length=40)
def test_kubernetesconfiguration_private_endpoint(self, resource_group):
self.kwargs.update({
'vnet': self.create_random_name('cli-vnet-', 24),
'scopename': self.create_random_name('clitestscopename', 24),
'subnet': self.create_random_name('cli-subnet-', 24),
'private_endpoint': self.create_random_name('cli-pe-', 24),
'private_endpoint2': self.create_random_name('cli-pe-', 24),
'private_endpoint_connection': self.create_random_name('cli-pec-', 24),
'private_endpoint_connection2': self.create_random_name('cli-pec-', 24),
'location': 'eastus2euap',
'approve_desc': 'ApprovedByTest',
'reject_desc': 'RejectedByTest',
'rg': resource_group,
'sub': self.get_subscription_id(),
'body': '{\\"location\\":\\"eastus2euap\\",\\"properties\\":{\\"clusterResourceId\\":\\"non-existing-resource\\"\\}\\}'
})


# Test create Private Link Scope create
self.cmd('az rest --method "PUT" \
--url "https://management.azure.com/subscriptions/{sub}/resourcegroups/{rg}/providers/Microsoft.KubernetesConfiguration/privateLinkScopes/{scopename}?api-version=2022-04-02-preview" \
--body "{body}"')

# Prepare network
self.cmd('network vnet create -n {vnet} -g {rg} -l {location} --subnet-name {subnet}',
checks=self.check('length(newVNet.subnets)', 1))
self.cmd('network vnet subnet update -n {subnet} --vnet-name {vnet} -g {rg} '
'--disable-private-endpoint-network-policies true',
checks=self.check('privateEndpointNetworkPolicies', 'Disabled'))

# Test private link resource list
pr = self.cmd('network private-link-resource list --name {scope} -g {rg} --type microsoft.KubernetesConfiguration/privateLinkScopes', checks=[
self.check('length(@)', 1)
]).get_output_in_json()

# Add an endpoint that gets auto approved
self.kwargs['group_id'] = pr[0]['groupId']
self.kwargs['scope_id'] = '/subscriptions/{sub}/resourcegroups/{rg}/providers/Microsoft.KubernetesConfiguration/privateLinkScopes/{scopename}'

result = self.cmd('network private-endpoint create -g {rg} -n {private_endpoint} --vnet-name {vnet} --subnet {subnet} --private-connection-resource-id {scope_id} '
'--connection-name {private_endpoint_connection} --group-id {group_id}').get_output_in_json()
self.assertTrue(self.kwargs['private_endpoint_connection'].lower() in result['name'].lower())

# Add an endpoint and approve it
result = self.cmd('network private-endpoint create -g {rg} -n {private_endpoint2} --vnet-name {vnet} --subnet {subnet} --private-connection-resource-id {scope_id} '
'--connection-name {private_endpoint_connection2} --group-id {group_id} --manual-request').get_output_in_json()
self.assertTrue(self.kwargs['private_endpoint_connection2'].lower() in result['name'].lower())

self.cmd('network private-endpoint-connection approve -g {rg} -n {private_endpoint_connection2} --resource-name {scope} --type Microsoft.KubernetesConfiguration/privateLinkScopes --description {approve_desc}',
checks=[
self.check('properties.privateLinkServiceConnectionState.status', 'Approved'),
self.check('properties.privateLinkServiceConnectionState.description', '{approve_desc}')
])

# Reject previous approved endpoint
self.cmd('network private-endpoint-connection reject -g {rg} -n {private_endpoint_connection2} --resource-name {scope} --type Microsoft.KubernetesConfiguration/privateLinkScopes --description {reject_desc}',
checks= [
self.check('properties.privateLinkServiceConnectionState.status', 'Rejected'),
self.check('properties.privateLinkServiceConnectionState.description', '{reject_desc}')
])

# List endpoints
self.cmd('network private-endpoint-connection list -g {rg} --name {scope} --type Microsoft.KubernetesConfiguration/privateLinkScopes', checks=[
self.check('length(@)', '2')
])
# Remove endpoints
self.cmd('network private-endpoint-connection delete -g {rg} --resource-name {scope} -n {private_endpoint_connection2} --type Microsoft.KubernetesConfiguration/privateLinkScopes -y')
time.sleep(30)
self.cmd('network private-endpoint-connection list -g {rg} --name {scope} --type Microsoft.KubernetesConfiguration/privateLinkScopes', checks=[
self.check('length(@)', '1')
])
# Show endpoint
self.cmd('az network private-endpoint-connection show -g {rg} --type Microsoft.KubernetesConfiguration/privateLinkScopes --resource-name {scope} -n {private_endpoint_connection}', checks=[
self.check('properties.privateLinkServiceConnectionState.status', 'Approved'),
self.check('properties.privateLinkServiceConnectionState.description', 'Auto-Approved')
])
self.cmd('network private-endpoint-connection delete -g {rg} --resource-name {scope} -n {private_endpoint_connection} --type Microsoft.KubernetesConfiguration/privateLinkScopes -y')



if __name__ == '__main__':
unittest.main()

0 comments on commit 63f9c99

Please sign in to comment.