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

{AKS} Fix #23468: az aks nodepool wait crashes with error "'Namespace' object has no attribute 'nodepool_name'" #5219

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

0.5.93
++++++

* Fix for "'Namespace' object has no attribute 'nodepool_name' error" in command `az aks nodepool wait`, see issue `\#23468 <https://github.com/Azure/azure-cli/issues/23468>`_.

0.5.92
++++++

Expand Down
3 changes: 3 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
validate_acr,
validate_addon,
validate_addons,
validate_agent_pool_name,
validate_apiserver_subnet_id,
validate_assign_identity,
validate_assign_kubelet_identity,
Expand Down Expand Up @@ -423,6 +424,8 @@ def load_arguments(self, _):

with self.argument_context('aks nodepool') as c:
c.argument('cluster_name', help='The cluster name.')
# the following argument is declared for the wait command
c.argument('agent_pool_name', options_list=['--nodepool-name', '--agent-pool-name'], validator=validate_agent_pool_name, help='The node pool name.')

for sub_command in ['add', 'update', 'upgrade', 'scale', 'show', 'list', 'delete']:
with self.argument_context('aks nodepool ' + sub_command) as c:
Expand Down
21 changes: 15 additions & 6 deletions src/aks-preview/azext_aks_preview/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,23 @@ def validate_ip_ranges(namespace):
"--api-server-authorized-ip-ranges should be a list of IPv4 addresses or CIDRs")


def _validate_nodepool_name(nodepool_name):
"""Validates a nodepool name to be at most 12 characters, alphanumeric only."""
if nodepool_name != "":
if len(nodepool_name) > 12:
raise InvalidArgumentValueError('--nodepool-name can contain at most 12 characters')
if not nodepool_name.isalnum():
raise InvalidArgumentValueError('--nodepool-name should contain only alphanumeric characters')


def validate_nodepool_name(namespace):
"""Validates a nodepool name to be at most 12 characters, alphanumeric only."""
if namespace.nodepool_name != "":
if len(namespace.nodepool_name) > 12:
raise CLIError('--nodepool-name can contain atmost 12 characters')
if not namespace.nodepool_name.isalnum():
raise CLIError(
'--nodepool-name should only contain alphanumeric characters')
_validate_nodepool_name(namespace.nodepool_name)


def validate_agent_pool_name(namespace):
"""Validates a nodepool name to be at most 12 characters, alphanumeric only."""
_validate_nodepool_name(namespace.agent_pool_name)


def validate_vm_set_type(namespace):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
import unittest
from types import SimpleNamespace

from azure.cli.core.util import CLIError
from azure.cli.core.azclierror import InvalidArgumentValueError
import azext_aks_preview._validators as validators
Expand Down Expand Up @@ -408,5 +410,71 @@ def test_valid_azure_keyvault_kms_key_vault_resource_id(self):
validators.validate_azure_keyvault_kms_key_vault_resource_id(namespace)


class TestValidateNodepoolName(unittest.TestCase):
def test_invalid_nodepool_name_too_long(self):
namespace = SimpleNamespace(
**{
"nodepool_name": "tooLongNodepoolName",
}
)
with self.assertRaises(InvalidArgumentValueError):
validators.validate_nodepool_name(
namespace
)

def test_invalid_agent_pool_name_too_long(self):
namespace = SimpleNamespace(
**{
"agent_pool_name": "tooLongNodepoolName",
}
)
with self.assertRaises(InvalidArgumentValueError):
validators.validate_agent_pool_name(
namespace
)

def test_invalid_nodepool_name_not_alnum(self):
namespace = SimpleNamespace(
**{
"nodepool_name": "invalid-np*",
}
)
with self.assertRaises(InvalidArgumentValueError):
validators.validate_nodepool_name(
namespace
)

def test_invalid_agent_pool_name_not_alnum(self):
namespace = SimpleNamespace(
**{
"agent_pool_name": "invalid-np*",
}
)
with self.assertRaises(InvalidArgumentValueError):
validators.validate_agent_pool_name(
namespace
)

def test_valid_nodepool_name(self):
namespace = SimpleNamespace(
**{
"nodepool_name": "np100",
}
)
validators.validate_nodepool_name(
namespace
)

def test_valid_agent_pool_name(self):
namespace = SimpleNamespace(
**{
"agent_pool_name": "np100",
}
)
validators.validate_agent_pool_name(
namespace
)


if __name__ == "__main__":
unittest.main()
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 = "0.5.92"
VERSION = "0.5.93"
CLASSIFIERS = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
Expand Down