Skip to content
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

[Network] az network private-endpoint-connection: Enable private link support for provider Microsoft.KubernetesConfiguration/privateLinkScopes #23172

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()