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} az aks update: Add --network-plugin to support updating cluster networking settings #6936

Merged
merged 3 commits into from
Nov 7, 2023
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
1 change: 1 addition & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ To release a new version, please select a new version number (usually plus 1 to
Pending
+++++++
* Vendor new SDK and bump API version to 2023-09-02-preview.
* Add `--network-plugin` to the `az aks update` command.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhoxing-ms , @FumingZhang - should I just bump this to 0.5.168 or does that happen elsewhere?


0.5.168
+++++++
Expand Down
4 changes: 4 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,10 @@
type: string
short-summary: A CIDR notation IP range from which to assign pod IPs when kubenet is used.
long-summary: This range must not overlap with any Subnet IP ranges. For example, 172.244.0.0/16.
- name: --network-plugin
type: string
short-summary: The Kubernetes network plugin to use.
long-summary: Specify "azure" for routable pod IPs from VNET, "kubenet" for non-routable pod IPs with an overlay network, or "none" for no networking configured.
- name: --network-plugin-mode
type: string
short-summary: The network plugin mode to use.
Expand Down
1 change: 1 addition & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ def load_arguments(self, _):
c.argument('nat_gateway_idle_timeout', type=int, validator=validate_nat_gateway_idle_timeout)
c.argument('network_dataplane', arg_type=get_enum_type(network_dataplanes))
c.argument('network_policy')
c.argument('network_plugin', arg_type=get_enum_type(network_plugins))
c.argument('kube_proxy_config')
c.argument('auto_upgrade_channel', arg_type=get_enum_type(auto_upgrade_channels))
c.argument('node_os_upgrade_channel', arg_type=get_enum_type(node_os_upgrade_channels))
Expand Down
1 change: 1 addition & 0 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ def aks_update(
ssh_key_value=None,
load_balancer_managed_outbound_ipv6_count=None,
outbound_type=None,
network_plugin=None,
network_plugin_mode=None,
network_policy=None,
network_dataplane=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,9 @@ def _get_network_plugin(self, enable_validation: bool = False) -> Union[str, Non
# read the original value passed by the command
network_plugin = self.raw_param.get("network_plugin")
# try to read the property value corresponding to the parameter from the `mc` object
# but do not override if it was specified in the raw params since this property can be updated.
if (
not network_plugin and
self.mc and
self.mc.network_profile and
self.mc.network_profile.network_plugin is not None
Expand Down Expand Up @@ -3295,6 +3297,10 @@ def update_network_plugin_settings(self, mc: ManagedCluster) -> ManagedCluster:
"""
self._ensure_mc(mc)

network_plugin = self.context._get_network_plugin()
if network_plugin:
mc.network_profile.network_plugin = network_plugin

network_plugin_mode = self.context.get_network_plugin_mode()
if network_plugin_mode:
mc.network_profile.network_plugin_mode = network_plugin_mode
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4500,6 +4500,47 @@ def test_aks_azure_cni_overlay_migration(self, resource_group, resource_group_lo
self.cmd(
'aks delete -g {resource_group} -n {name} --yes --no-wait', checks=[self.is_empty()])

@AllowLargeResponse()
@AKSCustomResourceGroupPreparer(random_name_length=17, name_prefix='clitest', location='eastus', preserve_default_location=True)
def test_aks_azure_cni_overlay_migration_from_kubenet(self, resource_group, resource_group_location):
_, create_version = self._get_versions(resource_group_location)
aks_name = self.create_random_name('cliakstest', 16)
self.kwargs.update({
'resource_group': resource_group,
'name': aks_name,
'location': resource_group_location,
'k8s_version': create_version,
'ssh_key_value': self.generate_ssh_keys(),
})

# create
create_cmd = 'aks create --resource-group={resource_group} --name={name} --location={location} ' \
'--network-plugin kubenet --ssh-key-value={ssh_key_value} --kubernetes-version {k8s_version} ' \
'--service-cidr 172.56.0.0/16 --dns-service-ip 172.56.0.10 --pod-cidr 100.64.0.0/16 -c 1'
self.cmd(create_cmd, checks=[
self.check('provisioningState', 'Succeeded'),
self.check('networkProfile.networkPlugin', 'kubenet'),
self.check('networkProfile.networkPluginMode', None),
self.check('networkProfile.podCidr', '100.64.0.0/16'),
self.check('networkProfile.serviceCidr', '172.56.0.0/16'),
])

# update
update_cmd = 'aks update -g {resource_group} -n {name} --network-plugin azure --network-plugin-mode overlay ' \
'--aks-custom-headers AKSHTTPCustomFeatures=Microsoft.ContainerService/AzureOverlayPreview'

self.cmd(update_cmd, checks=[
self.check('provisioningState', 'Succeeded'),
self.check('networkProfile.networkPlugin', 'azure'),
self.check('networkProfile.networkPluginMode', 'overlay'),
self.check('networkProfile.podCidr', '100.64.0.0/16'),
self.check('networkProfile.serviceCidr', '172.56.0.0/16'),
])

# delete
self.cmd(
'aks delete -g {resource_group} -n {name} --yes --no-wait', checks=[self.is_empty()])

@AllowLargeResponse()
@AKSCustomResourceGroupPreparer(random_name_length=17, name_prefix='clitest', location='eastus', preserve_default_location=True)
def test_aks_migrate_cluster_to_cilium_dataplane(self, resource_group, resource_group_location):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5147,6 +5147,39 @@ def test_update_network_plugin_settings(self):

self.assertEqual(dec_mc_6, ground_truth_mc_6)

# test update network plugin for kubenet -> cni overlay migrations
dec_7 = AKSPreviewManagedClusterUpdateDecorator(
self.cmd,
self.client,
{
"network_plugin": "azure",
"network_plugin_mode": "overlay",
},
CUSTOM_MGMT_AKS_PREVIEW,
)
mc_7 = self.models.ManagedCluster(
location="test_location",
network_profile=self.models.ContainerServiceNetworkProfile(
network_plugin="kubenet",
),
)

dec_7.context.attach_mc(mc_7)
# fail on passing the wrong mc object
with self.assertRaises(CLIInternalError):
dec_7.update_network_plugin_settings(None)
dec_mc_7 = dec_7.update_network_plugin_settings(mc_7)

ground_truth_mc_7 = self.models.ManagedCluster(
location="test_location",
network_profile=self.models.ContainerServiceNetworkProfile(
network_plugin="azure",
network_plugin_mode="overlay",
),
)

self.assertEqual(dec_mc_7, ground_truth_mc_7)

def test_update_api_server_access_profile(self):
dec_1 = AKSPreviewManagedClusterUpdateDecorator(
self.cmd,
Expand Down