Skip to content

Commit 98809a0

Browse files
author
Kanan Mehta
committed
feat: add disable_artifact_streaming arg
1 parent 87f822d commit 98809a0

9 files changed

Lines changed: 157 additions & 3 deletions

File tree

src/aks-preview/HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ To release a new version, please select a new version number (usually plus 1 to
1111

1212
Pending
1313
+++++++
14+
* `az aks nodepool update`: Add `--disable-artifact-streaming` to disable artifact streaming.
1415

1516
19.0.0b27
1617
+++++++

src/aks-preview/azext_aks_preview/_help.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2400,6 +2400,9 @@
24002400
- name: --enable-artifact-streaming
24012401
type: bool
24022402
short-summary: Enable artifact streaming for VirtualMachineScaleSets managed by a node pool, to speed up the cold-start of containers on a node through on-demand image loading. To use this feature, container images must also enable artifact streaming on ACR. If not specified, the default is false.
2403+
- name: --disable-artifact-streaming
2404+
type: bool
2405+
short-summary: Disable artifact streaming for VirtualMachineScaleSets managed by a node pool.
24032406
- name: --os-sku
24042407
type: string
24052408
short-summary: The os-sku of the agent node pool.

src/aks-preview/azext_aks_preview/_params.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,6 +2135,12 @@ def load_arguments(self, _):
21352135
validator=validate_artifact_streaming,
21362136
is_preview=True,
21372137
)
2138+
c.argument(
2139+
"disable_artifact_streaming",
2140+
action="store_true",
2141+
validator=validate_artifact_streaming,
2142+
is_preview=True,
2143+
)
21382144
c.argument(
21392145
"os_sku",
21402146
arg_type=get_enum_type(node_os_skus_update),

src/aks-preview/azext_aks_preview/_validators.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,10 +954,20 @@ def validate_asm_egress_name(namespace):
954954

955955

956956
def validate_artifact_streaming(namespace):
957-
"""Validates that artifact streaming enablement can only be used on Linux."""
958-
if namespace.enable_artifact_streaming:
959-
if hasattr(namespace, 'os_type') and str(namespace.os_type).lower() == "windows":
957+
"""Validates artifact streaming flags for mutual exclusivity and OS support."""
958+
enable_artifact_streaming = getattr(namespace, "enable_artifact_streaming", False)
959+
disable_artifact_streaming = getattr(namespace, "disable_artifact_streaming", False)
960+
961+
if enable_artifact_streaming and disable_artifact_streaming:
962+
raise MutuallyExclusiveArgumentError(
963+
"Cannot specify both --enable-artifact-streaming and --disable-artifact-streaming at the same time."
964+
)
965+
966+
if hasattr(namespace, "os_type") and str(namespace.os_type).lower() == "windows":
967+
if enable_artifact_streaming:
960968
raise ArgumentUsageError('--enable-artifact-streaming can only be set for Linux nodepools')
969+
if disable_artifact_streaming:
970+
raise ArgumentUsageError('--disable-artifact-streaming can only be set for Linux nodepools')
961971

962972

963973
def validate_custom_endpoints(namespace):

src/aks-preview/azext_aks_preview/agentpool_decorator.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,20 @@ def get_enable_artifact_streaming(self) -> bool:
585585
self.agentpool.artifact_streaming_profile.enabled is not None
586586
):
587587
enable_artifact_streaming = self.agentpool.artifact_streaming_profile.enabled
588+
589+
if enable_artifact_streaming and self.get_disable_artifact_streaming():
590+
raise MutuallyExclusiveArgumentError(
591+
'Cannot specify "--enable-artifact-streaming" and "--disable-artifact-streaming" at the same time'
592+
)
588593
return enable_artifact_streaming
589594

595+
def get_disable_artifact_streaming(self) -> bool:
596+
"""Obtain the value of disable_artifact_streaming.
597+
:return: bool
598+
"""
599+
600+
return self.raw_param.get("disable_artifact_streaming")
601+
590602
def get_pod_ip_allocation_mode(self: bool = False) -> Union[str, None]:
591603
"""Get the value of pod_ip_allocation_mode.
592604
:return: str or None
@@ -1686,6 +1698,11 @@ def update_artifact_streaming(self, agentpool: AgentPool) -> AgentPool:
16861698
if agentpool.artifact_streaming_profile is None:
16871699
agentpool.artifact_streaming_profile = self.models.AgentPoolArtifactStreamingProfile() # pylint: disable=no-member
16881700
agentpool.artifact_streaming_profile.enabled = True
1701+
1702+
if self.context.get_disable_artifact_streaming():
1703+
if agentpool.artifact_streaming_profile is None:
1704+
agentpool.artifact_streaming_profile = self.models.AgentPoolArtifactStreamingProfile() # pylint: disable=no-member
1705+
agentpool.artifact_streaming_profile.enabled = False
16891706
return agentpool
16901707

16911708
def update_os_sku(self, agentpool: AgentPool) -> AgentPool:

src/aks-preview/azext_aks_preview/custom.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,7 @@ def aks_agentpool_update(
19771977
allowed_host_ports=None,
19781978
asg_ids=None,
19791979
enable_artifact_streaming=False,
1980+
disable_artifact_streaming=False,
19801981
os_sku=None,
19811982
ssh_access=None,
19821983
yes=False,

src/aks-preview/azext_aks_preview/tests/latest/test_agentpool_decorator.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,24 @@ def common_get_enable_artifact_streaming(self):
257257
ctx_2.attach_agentpool(agentpool_2)
258258
self.assertEqual(ctx_2.get_enable_artifact_streaming(), None)
259259

260+
def common_get_disable_artifact_streaming(self):
261+
# default
262+
ctx_1 = AKSPreviewAgentPoolContext(
263+
self.cmd,
264+
AKSAgentPoolParamDict({"disable_artifact_streaming": True}),
265+
self.models,
266+
DecoratorMode.UPDATE,
267+
self.agentpool_decorator_mode,
268+
)
269+
self.assertEqual(ctx_1.get_disable_artifact_streaming(), True)
270+
agentpool_1 = self.create_initialized_agentpool_instance(
271+
artifact_streaming_profile=self.models.AgentPoolArtifactStreamingProfile(
272+
enabled=True
273+
)
274+
)
275+
ctx_1.attach_agentpool(agentpool_1)
276+
self.assertEqual(ctx_1.get_disable_artifact_streaming(), True)
277+
260278
def common_get_pod_ip_allocation_mode(self):
261279
# default
262280
ctx_1 = AKSPreviewAgentPoolContext(
@@ -1037,6 +1055,9 @@ def test_get_workload_runtime(self):
10371055
def test_get_enable_artifact_streaming(self):
10381056
self.common_get_enable_artifact_streaming()
10391057

1058+
def test_get_disable_artifact_streaming(self):
1059+
self.common_get_disable_artifact_streaming()
1060+
10401061
def test_get_pod_ip_allocation_mode(self):
10411062
self.common_get_pod_ip_allocation_mode()
10421063

@@ -1140,6 +1161,9 @@ def test_get_os_sku(self):
11401161
def test_get_enable_artifact_streaming(self):
11411162
self.common_get_enable_artifact_streaming()
11421163

1164+
def test_get_disable_artifact_streaming(self):
1165+
self.common_get_disable_artifact_streaming()
1166+
11431167
def test_get_enable_secure_boot(self):
11441168
self.common_get_enable_secure_boot()
11451169

@@ -2349,6 +2373,42 @@ def common_update_artifact_streaming(self):
23492373
)
23502374
self.assertEqual(dec_agentpool_2, grond_truth_agentpool_2)
23512375

2376+
dec_3 = AKSPreviewAgentPoolUpdateDecorator(
2377+
self.cmd,
2378+
self.client,
2379+
{"disable_artifact_streaming": True},
2380+
self.resource_type,
2381+
self.agentpool_decorator_mode,
2382+
)
2383+
# fail on passing the wrong agentpool object
2384+
with self.assertRaises(CLIInternalError):
2385+
dec_3.update_artifact_streaming(None)
2386+
agentpool_3 = self.create_initialized_agentpool_instance(
2387+
artifact_streaming_profile=self.models.AgentPoolArtifactStreamingProfile(
2388+
enabled=True
2389+
)
2390+
)
2391+
dec_3.context.attach_agentpool(agentpool_3)
2392+
dec_agentpool_3 = dec_3.update_artifact_streaming(agentpool_3)
2393+
grond_truth_agentpool_3 = self.create_initialized_agentpool_instance(
2394+
artifact_streaming_profile=self.models.AgentPoolArtifactStreamingProfile(
2395+
enabled=False
2396+
)
2397+
)
2398+
self.assertEqual(dec_agentpool_3, grond_truth_agentpool_3)
2399+
2400+
# Should error if both set
2401+
dec_4 = AKSPreviewAgentPoolUpdateDecorator(
2402+
self.cmd,
2403+
self.client,
2404+
{"enable_artifact_streaming": True, "disable_artifact_streaming": True},
2405+
self.resource_type,
2406+
self.agentpool_decorator_mode,
2407+
)
2408+
dec_4.context.attach_agentpool(agentpool_3)
2409+
with self.assertRaises(MutuallyExclusiveArgumentError):
2410+
dec_4.update_artifact_streaming(agentpool_3)
2411+
23522412
def common_update_secure_boot(self):
23532413
dec_1 = AKSPreviewAgentPoolUpdateDecorator(
23542414
self.cmd,

src/aks-preview/azext_aks_preview/tests/latest/test_validators.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ def __init__(self, os_type, disable_windows_outbound_nat):
149149
self.disable_windows_outbound_nat = disable_windows_outbound_nat
150150

151151

152+
class ArtifactStreamingNamespace:
153+
def __init__(self, os_type, enable_artifact_streaming=False, disable_artifact_streaming=False):
154+
self.os_type = os_type
155+
self.enable_artifact_streaming = enable_artifact_streaming
156+
self.disable_artifact_streaming = disable_artifact_streaming
157+
158+
152159
class TestMaxSurge(unittest.TestCase):
153160
def test_valid_cases(self):
154161
valid = ["5", "33%", "1", "100%"]
@@ -385,6 +392,52 @@ def test_fail_if_os_type_invalid(self):
385392
)
386393

387394

395+
class TestArtifactStreaming(unittest.TestCase):
396+
def test_valid_linux_enable(self):
397+
validators.validate_artifact_streaming(
398+
ArtifactStreamingNamespace("Linux", enable_artifact_streaming=True)
399+
)
400+
401+
def test_valid_linux_disable(self):
402+
validators.validate_artifact_streaming(
403+
ArtifactStreamingNamespace("Linux", disable_artifact_streaming=True)
404+
)
405+
406+
def test_fail_if_enable_and_disable_are_set(self):
407+
with self.assertRaises(MutuallyExclusiveArgumentError) as cm:
408+
validators.validate_artifact_streaming(
409+
ArtifactStreamingNamespace(
410+
"Linux",
411+
enable_artifact_streaming=True,
412+
disable_artifact_streaming=True,
413+
)
414+
)
415+
self.assertEqual(
416+
str(cm.exception),
417+
"Cannot specify both --enable-artifact-streaming and --disable-artifact-streaming at the same time.",
418+
)
419+
420+
def test_fail_if_enable_for_windows(self):
421+
with self.assertRaises(ArgumentUsageError) as cm:
422+
validators.validate_artifact_streaming(
423+
ArtifactStreamingNamespace("Windows", enable_artifact_streaming=True)
424+
)
425+
self.assertEqual(
426+
str(cm.exception),
427+
"--enable-artifact-streaming can only be set for Linux nodepools",
428+
)
429+
430+
def test_fail_if_disable_for_windows(self):
431+
with self.assertRaises(ArgumentUsageError) as cm:
432+
validators.validate_artifact_streaming(
433+
ArtifactStreamingNamespace("Windows", disable_artifact_streaming=True)
434+
)
435+
self.assertEqual(
436+
str(cm.exception),
437+
"--disable-artifact-streaming can only be set for Linux nodepools",
438+
)
439+
440+
388441
class ValidateAddonsNamespace:
389442
def __init__(self, addons):
390443
self.addons = addons

src/aks-preview/linter_exclusions.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,9 @@ aks nodepool update:
446446
enable_artifact_streaming:
447447
rule_exclusions:
448448
- option_length_too_long
449+
disable_artifact_streaming:
450+
rule_exclusions:
451+
- option_length_too_long
449452
enable_secure_boot:
450453
rule_exclusions:
451454
- option_length_too_long

0 commit comments

Comments
 (0)