Skip to content
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
4 changes: 4 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ To release a new version, please select a new version number (usually plus 1 to
Pending
+++++++

18.0.0b8
+++++++
* Populate location of managed namespaces using managed cluster's location

18.0.0b7
+++++++
* Add option `--disable-http-proxy` to `az aks update`.
Expand Down
12 changes: 12 additions & 0 deletions src/aks-preview/azext_aks_preview/managednamespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from azure.cli.core.util import (
sdk_no_wait,
)
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.mgmt.containerservice import ContainerServiceClient

from azext_aks_preview._consts import (
CONST_NAMESPACE_NETWORK_POLICY_RULE_DENYALL,
Expand All @@ -27,11 +29,19 @@
from azext_aks_preview._client_factory import CUSTOM_MGMT_AKS_PREVIEW


def get_cluster_location(cmd, resource_group_name, cluster_name):
containerservice_client = get_mgmt_service_client(cmd.cli_ctx, ContainerServiceClient)
cluster = containerservice_client.managed_clusters.get(resource_group_name, cluster_name)
return cluster.location


def aks_managed_namespace_add(cmd, client, raw_parameters, headers, no_wait):
resource_group_name = raw_parameters.get("resource_group_name")
cluster_name = raw_parameters.get("cluster_name")
namespace_name = raw_parameters.get("name")

namespace_config = constructNamespace(cmd, raw_parameters, namespace_name)
namespace_config.location = get_cluster_location(cmd, resource_group_name, cluster_name)

return sdk_no_wait(
no_wait,
Expand Down Expand Up @@ -193,7 +203,9 @@ def aks_managed_namespace_update(cmd, client, raw_parameters, headers, existedNa
resource_group_name = raw_parameters.get("resource_group_name")
cluster_name = raw_parameters.get("cluster_name")
namespace_name = raw_parameters.get("name")

namespace_config = updateNamespace(cmd, raw_parameters, existedNamespace)
namespace_config.location = get_cluster_location(cmd, resource_group_name, cluster_name)

return sdk_no_wait(
no_wait,
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7227,9 +7227,9 @@ def test_aks_maintenanceconfiguration(
)

@AllowLargeResponse()
@AKSCustomResourceGroupPreparer(random_name_length=17, name_prefix='clitest', location='eastus2')
@AKSCustomResourceGroupPreparer(random_name_length=17, name_prefix='clitest', location='uksouth')
def test_aks_managed_namespace(self, resource_group, resource_group_location):
# reset the count so in replay mode the random names will start with 0
# reset the count so that in replay mode the random names will start with 0
self.test_resources_count = 0
# kwargs for string formatting
resource_name = self.create_random_name('cliakstest', 16)
Expand All @@ -7243,10 +7243,11 @@ def test_aks_managed_namespace(self, resource_group, resource_group_location):
'ssh_key_value': self.generate_ssh_keys(),
})

create_cmd = ' '.join([
'aks', 'create', '--resource-group={resource_group}', '--name={resource_name}', '--location={location}',
'--ssh-key-value={ssh_key_value}'
])
create_cmd = (
"aks create --resource-group={resource_group} --name={resource_name} --location={location} "
"--enable-aad --aad-admin-group-object-ids 00000000-0000-0000-0000-000000000001 "
"--ssh-key-value={ssh_key_value}"
)

self.cmd(create_cmd, checks=[
self.check('provisioningState', 'Succeeded'),
Expand Down Expand Up @@ -7314,6 +7315,8 @@ def test_aks_managed_namespace(self, resource_group, resource_group_location):
checks=[self.is_empty()],
)

time.sleep(2*60)

self.cmd(
"aks delete -g {resource_group} -n {resource_name} --yes --no-wait",
checks=[self.is_empty()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# --------------------------------------------------------------------------------------------

import unittest

from unittest.mock import patch, Mock
import azext_aks_preview.managednamespace as ns
from azext_aks_preview.__init__ import register_aks_preview_resource_type
from azure.cli.command_modules.acs.tests.latest.mocks import MockCLI, MockCmd
Expand All @@ -13,11 +13,26 @@
RequiredArgumentMissingError,
)

@patch("azext_aks_preview.managednamespace.get_mgmt_service_client")
class TestAddManagedNamespace(unittest.TestCase):
def test_add_managed_namespace_with_invalid_labels(self):
def setUp(self):
# Set up mock cluster client and location
self.mock_cluster = Mock()
self.mock_cluster.location = "eastus"

self.mock_managed_clusters = Mock()
self.mock_managed_clusters.get.return_value = self.mock_cluster

self.mock_client = Mock()
self.mock_client.managed_clusters = self.mock_managed_clusters

def test_add_managed_namespace_with_invalid_labels(self, mock_get_client):
register_aks_preview_resource_type()
cli_ctx = MockCLI()
cmd = MockCmd(cli_ctx)

mock_get_client.return_value = self.mock_client

raw_parameters = {
"resource_group_name": "test_rg",
"cluster_name": "test_cluster",
Expand All @@ -29,10 +44,13 @@ def test_add_managed_namespace_with_invalid_labels(self):
ns.aks_managed_namespace_add(cmd, None, raw_parameters, None, False)
self.assertEqual(str(cm.exception), err)

def test_add_managed_namespace_with_invalid_annotations(self):
def test_add_managed_namespace_with_invalid_annotations(self, mock_get_client):
register_aks_preview_resource_type()
cli_ctx = MockCLI()
cmd = MockCmd(cli_ctx)

mock_get_client.return_value = self.mock_client

raw_parameters = {
"resource_group_name": "test_rg",
"cluster_name": "test_cluster",
Expand All @@ -45,10 +63,13 @@ def test_add_managed_namespace_with_invalid_annotations(self):
ns.aks_managed_namespace_add(cmd, None, raw_parameters, None, False)
self.assertEqual(str(cm.exception), err)

def test_add_managed_namespace_with_missing_cpu_request(self):
def test_add_managed_namespace_with_missing_cpu_request(self, mock_get_client):
register_aks_preview_resource_type()
cli_ctx = MockCLI()
cmd = MockCmd(cli_ctx)

mock_get_client.return_value = self.mock_client

raw_parameters = {
"resource_group_name": "test_rg",
"cluster_name": "test_cluster",
Expand All @@ -60,10 +81,13 @@ def test_add_managed_namespace_with_missing_cpu_request(self):
ns.aks_managed_namespace_add(cmd, None, raw_parameters, None, False)
self.assertEqual(str(cm.exception), err)

def test_add_managed_namespace_with_invalid_ingress_policy(self):
def test_add_managed_namespace_with_invalid_ingress_policy(self, mock_get_client):
register_aks_preview_resource_type()
cli_ctx = MockCLI()
cmd = MockCmd(cli_ctx)

mock_get_client.return_value = self.mock_client

raw_parameters = {
"resource_group_name": "test_rg",
"cluster_name": "test_cluster",
Expand All @@ -79,10 +103,13 @@ def test_add_managed_namespace_with_invalid_ingress_policy(self):
ns.aks_managed_namespace_add(cmd, None, raw_parameters, None, False)
self.assertIn(err, str(cm.exception))

def test_add_managed_namespace_with_invalid_egress_policy(self):
def test_add_managed_namespace_with_invalid_egress_policy(self, mock_get_client):
register_aks_preview_resource_type()
cli_ctx = MockCLI()
cmd = MockCmd(cli_ctx)

mock_get_client.return_value = self.mock_client

raw_parameters = {
"resource_group_name": "test_rg",
"cluster_name": "test_cluster",
Expand All @@ -99,10 +126,13 @@ def test_add_managed_namespace_with_invalid_egress_policy(self):
ns.aks_managed_namespace_add(cmd, None, raw_parameters, None, False)
self.assertIn(err, str(cm.exception))

def test_add_managed_namespace_with_invalid_adoption_policy(self):
def test_add_managed_namespace_with_invalid_adoption_policy(self, mock_get_client):
register_aks_preview_resource_type()
cli_ctx = MockCLI()
cmd = MockCmd(cli_ctx)

mock_get_client.return_value = self.mock_client

raw_parameters = {
"resource_group_name": "test_rg",
"cluster_name": "test_cluster",
Expand All @@ -120,10 +150,13 @@ def test_add_managed_namespace_with_invalid_adoption_policy(self):
ns.aks_managed_namespace_add(cmd, None, raw_parameters, None, False)
self.assertIn(err, str(cm.exception))

def test_add_managed_namespace_with_invalid_delete_policy(self):
def test_add_managed_namespace_with_invalid_delete_policy(self, mock_get_client):
register_aks_preview_resource_type()
cli_ctx = MockCLI()
cmd = MockCmd(cli_ctx)

mock_get_client.return_value = self.mock_client

raw_parameters = {
"resource_group_name": "test_rg",
"cluster_name": "test_cluster",
Expand All @@ -145,11 +178,27 @@ def test_add_managed_namespace_with_invalid_delete_policy(self):
# aks_managed_namespace_add(cmd, client, raw_parameters, headers, no_wait):
# aks_managed_namespace_update(cmd, client, raw_parameters, headers, existedNamespace, no_wait)

@patch("azext_aks_preview.managednamespace.get_mgmt_service_client")
class TestUpdateManagedNamespace(unittest.TestCase):
def test_update_managed_namespace_with_invalid_ingress_policy(self):
def setUp(self):
# Set up mock cluster client and location
self.mock_cluster = Mock()
self.mock_cluster.location = "eastus"

self.mock_managed_clusters = Mock()
self.mock_managed_clusters.get.return_value = self.mock_cluster

self.mock_client = Mock()
self.mock_client.managed_clusters = self.mock_managed_clusters


def test_update_managed_namespace_with_invalid_ingress_policy(self, mock_get_client):
register_aks_preview_resource_type()
cli_ctx = MockCLI()
cmd = MockCmd(cli_ctx)

mock_get_client.return_value = self.mock_client

raw_parameters = {
"resource_group_name": "test_rg",
"cluster_name": "test_cluster",
Expand All @@ -165,10 +214,13 @@ def test_update_managed_namespace_with_invalid_ingress_policy(self):
ns.aks_managed_namespace_update(cmd, None, raw_parameters, None, None, False)
self.assertIn(err, str(cm.exception))

def test_update_managed_namespace_with_invalid_egress_policy(self):
def test_update_managed_namespace_with_invalid_egress_policy(self, mock_get_client):
register_aks_preview_resource_type()
cli_ctx = MockCLI()
cmd = MockCmd(cli_ctx)

mock_get_client.return_value = self.mock_client

raw_parameters = {
"resource_group_name": "test_rg",
"cluster_name": "test_cluster",
Expand All @@ -185,10 +237,13 @@ def test_update_managed_namespace_with_invalid_egress_policy(self):
ns.aks_managed_namespace_update(cmd, None, raw_parameters, None, None, False)
self.assertIn(err, str(cm.exception))

def test_update_managed_namespace_with_invalid_adoption_policy(self):
def test_update_managed_namespace_with_invalid_adoption_policy(self, mock_get_client):
register_aks_preview_resource_type()
cli_ctx = MockCLI()
cmd = MockCmd(cli_ctx)

mock_get_client.return_value = self.mock_client

raw_parameters = {
"resource_group_name": "test_rg",
"cluster_name": "test_cluster",
Expand All @@ -206,10 +261,13 @@ def test_update_managed_namespace_with_invalid_adoption_policy(self):
ns.aks_managed_namespace_update(cmd, None, raw_parameters, None, None, False)
self.assertIn(err, str(cm.exception))

def test_update_managed_namespace_with_invalid_delete_policy(self):
def test_update_managed_namespace_with_invalid_delete_policy(self, mock_get_client):
register_aks_preview_resource_type()
cli_ctx = MockCLI()
cmd = MockCmd(cli_ctx)

mock_get_client.return_value = self.mock_client

raw_parameters = {
"resource_group_name": "test_rg",
"cluster_name": "test_cluster",
Expand Down
2 changes: 1 addition & 1 deletion src/aks-preview/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from setuptools import setup, find_packages

VERSION = "18.0.0b7"
VERSION = "18.0.0b8"

CLASSIFIERS = [
"Development Status :: 4 - Beta",
Expand Down
Loading