Skip to content

Commit 5d5e76f

Browse files
committed
Merge branch 'main' into release-v1.10.8
2 parents 31a776a + 4e96375 commit 5d5e76f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+10854
-146
lines changed

src/aks-preview/HISTORY.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ Pending
1313
+++++++
1414
* Add support for `ManagedSystem` Agent Pool Mode.
1515

16+
18.0.0b19
17+
+++++++
18+
- Add `--localdns-config` to `az aks nodepool add` and to `az aks nodepool update` to support configuring a local DNS profile for agent pools.
19+
20+
1621
18.0.0b18
1722
+++++++
1823
* Add validation error when neither --location or --cluster and --resource-group-name are specified for az extension type list or az extension type version list
@@ -1907,4 +1912,4 @@ Pending
19071912
+++++
19081913

19091914
* new feature `enable-cluster-autoscaler`
1910-
* default agentType is VMSS
1915+
* default agentType is VMSS

src/aks-preview/azext_aks_preview/_help.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,6 +2048,9 @@
20482048
- name: --undrainable-node-behavior
20492049
type: string
20502050
short-summary: Define the behavior for undrainable nodes during upgrade. The value should be "Cordon" or "Schedule". The default value is "Schedule".
2051+
- name: --localdns-config
2052+
type: string
2053+
short-summary: Set the localDNS Profile for a nodepool with a JSON config file.
20512054
examples:
20522055
- name: Create a nodepool in an existing AKS cluster with ephemeral os enabled.
20532056
text: az aks nodepool add -g MyResourceGroup -n nodepool1 --cluster-name MyManagedCluster --node-osdisk-type Ephemeral --node-osdisk-size 48
@@ -2223,6 +2226,9 @@
22232226
- name: --undrainable-node-behavior
22242227
type: string
22252228
short-summary: Define the behavior for undrainable nodes during upgrade. The value should be "Cordon" or "Schedule". The default value is "Schedule".
2229+
- name: --localdns-config
2230+
type: string
2231+
short-summary: Set the localDNS Profile for a nodepool with a JSON config file.
22262232
examples:
22272233
- name: Reconcile the nodepool back to its current state.
22282234
text: az aks nodepool update -g MyResourceGroup -n nodepool1 --cluster-name MyManagedCluster

src/aks-preview/azext_aks_preview/_params.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,11 @@ def load_arguments(self, _):
17721772
)
17731773
# virtual machines
17741774
c.argument("vm_sizes", is_preview=True)
1775+
# local DNS
1776+
c.argument(
1777+
'localdns_config',
1778+
help='Path to a JSON file to configure the local DNS profile for a new nodepool.'
1779+
)
17751780

17761781
with self.argument_context("aks nodepool update") as c:
17771782
c.argument(
@@ -1864,6 +1869,11 @@ def load_arguments(self, _):
18641869
"disable_fips_image",
18651870
action="store_true"
18661871
)
1872+
# local DNS
1873+
c.argument(
1874+
'localdns_config',
1875+
help='Path to a JSON file to configure the local DNS profile for an existing nodepool.',
1876+
)
18671877

18681878
with self.argument_context("aks nodepool upgrade") as c:
18691879
c.argument("max_surge", validator=validate_max_surge)

src/aks-preview/azext_aks_preview/agentpool_decorator.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import base64
77
import os
8+
from azure.cli.core.util import get_file_json
89
from types import SimpleNamespace
910
from typing import Dict, TypeVar, Union, List
1011

@@ -810,6 +811,30 @@ def get_disable_fips_image(self) -> bool:
810811
# read the original value passed by the command
811812
return self.raw_param.get("disable_fips_image")
812813

814+
def get_localdns_config(self):
815+
return self.raw_param.get("localdns_config")
816+
817+
def get_localdns_profile(self):
818+
"""
819+
Returns the local DNS profile dict if set, or None.
820+
Only supports loading from --localdns-config (JSON file).
821+
Assumes the input is always a string filename.
822+
"""
823+
config = self.get_localdns_config()
824+
if config:
825+
if not isinstance(config, str) or not os.path.isfile(config):
826+
raise InvalidArgumentValueError(
827+
f"{config} is not a valid file, or not accessible."
828+
)
829+
profile = get_file_json(config)
830+
if not isinstance(profile, dict):
831+
raise InvalidArgumentValueError(
832+
f"Error reading local DNS config from {config}. "
833+
"Please provide a valid JSON file."
834+
)
835+
return profile
836+
return None
837+
813838

814839
class AKSPreviewAgentPoolAddDecorator(AKSAgentPoolAddDecorator):
815840
def __init__(
@@ -1099,6 +1124,50 @@ def set_up_managed_system_mode(self, agentpool: AgentPool) -> AgentPool:
10991124

11001125
return agentpool
11011126

1127+
def set_up_localdns_profile(self, agentpool: AgentPool) -> AgentPool:
1128+
"""Set up local DNS profile for the AgentPool object if provided via --localdns-config."""
1129+
self._ensure_agentpool(agentpool)
1130+
localdns_profile = self.context.get_localdns_profile()
1131+
if localdns_profile is not None:
1132+
kube_dns_overrides = {}
1133+
vnet_dns_overrides = {}
1134+
1135+
def build_override(override_dict):
1136+
camel_to_snake_case = {
1137+
"queryLogging": "query_logging",
1138+
"protocol": "protocol",
1139+
"forwardDestination": "forward_destination",
1140+
"forwardPolicy": "forward_policy",
1141+
"maxConcurrent": "max_concurrent",
1142+
"cacheDurationInSeconds": "cache_duration_in_seconds",
1143+
"serveStaleDurationInSeconds": "serve_stale_duration_in_seconds",
1144+
"serveStale": "serve_stale",
1145+
}
1146+
valid_keys = set(camel_to_snake_case.values())
1147+
filtered = {}
1148+
for k, v in override_dict.items():
1149+
if k in camel_to_snake_case:
1150+
filtered[camel_to_snake_case[k]] = v
1151+
elif k in valid_keys:
1152+
filtered[k] = v
1153+
return self.models.LocalDNSOverride(**filtered)
1154+
1155+
# Build kubeDNSOverrides and vnetDNSOverrides from the localdns_profile
1156+
kube_overrides = localdns_profile.get("kubeDNSOverrides")
1157+
for key, value in kube_overrides.items():
1158+
kube_dns_overrides[key] = build_override(value)
1159+
1160+
vnet_overrides = localdns_profile.get("vnetDNSOverrides")
1161+
for key, value in vnet_overrides.items():
1162+
vnet_dns_overrides[key] = build_override(value)
1163+
1164+
agentpool.local_dns_profile = self.models.LocalDNSProfile(
1165+
mode=localdns_profile.get("mode"),
1166+
kube_dns_overrides=kube_dns_overrides,
1167+
vnet_dns_overrides=vnet_dns_overrides,
1168+
)
1169+
return agentpool
1170+
11021171
def construct_agentpool_profile_preview(self) -> AgentPool:
11031172
"""The overall controller used to construct the preview AgentPool profile.
11041173
@@ -1151,6 +1220,8 @@ def construct_agentpool_profile_preview(self) -> AgentPool:
11511220
agentpool = self.set_up_agentpool_gateway_profile(agentpool)
11521221
# set up virtual machines profile
11531222
agentpool = self.set_up_virtual_machines_profile(agentpool)
1223+
# set up local DNS profile
1224+
agentpool = self.set_up_localdns_profile(agentpool)
11541225
# DO NOT MOVE: keep this at the bottom, restore defaults
11551226
agentpool = self._restore_defaults_in_agentpool(agentpool)
11561227
return agentpool
@@ -1343,6 +1414,50 @@ def update_fips_image(self, agentpool: AgentPool) -> AgentPool:
13431414

13441415
return agentpool
13451416

1417+
def update_localdns_profile(self, agentpool: AgentPool) -> AgentPool:
1418+
"""Update local DNS profile for the AgentPool object if provided via --localdns-config."""
1419+
self._ensure_agentpool(agentpool)
1420+
localdns_profile = self.context.get_localdns_profile()
1421+
if localdns_profile is not None:
1422+
kube_dns_overrides = {}
1423+
vnet_dns_overrides = {}
1424+
1425+
def build_override(override_dict):
1426+
camel_to_snake_case = {
1427+
"queryLogging": "query_logging",
1428+
"protocol": "protocol",
1429+
"forwardDestination": "forward_destination",
1430+
"forwardPolicy": "forward_policy",
1431+
"maxConcurrent": "max_concurrent",
1432+
"cacheDurationInSeconds": "cache_duration_in_seconds",
1433+
"serveStaleDurationInSeconds": "serve_stale_duration_in_seconds",
1434+
"serveStale": "serve_stale",
1435+
}
1436+
valid_keys = set(camel_to_snake_case.values())
1437+
filtered = {}
1438+
for k, v in override_dict.items():
1439+
if k in camel_to_snake_case:
1440+
filtered[camel_to_snake_case[k]] = v
1441+
elif k in valid_keys:
1442+
filtered[k] = v
1443+
return self.models.LocalDNSOverride(**filtered)
1444+
1445+
# Build kubeDNSOverrides and vnetDNSOverrides from the localdns_profile
1446+
kube_overrides = localdns_profile.get("kubeDNSOverrides")
1447+
for key, value in kube_overrides.items():
1448+
kube_dns_overrides[key] = build_override(value)
1449+
1450+
vnet_overrides = localdns_profile.get("vnetDNSOverrides")
1451+
for key, value in vnet_overrides.items():
1452+
vnet_dns_overrides[key] = build_override(value)
1453+
1454+
agentpool.local_dns_profile = self.models.LocalDNSProfile(
1455+
mode=localdns_profile.get("mode"),
1456+
kube_dns_overrides=kube_dns_overrides,
1457+
vnet_dns_overrides=vnet_dns_overrides,
1458+
)
1459+
return agentpool
1460+
13461461
def update_agentpool_profile_preview(self, agentpools: List[AgentPool] = None) -> AgentPool:
13471462
"""The overall controller used to update the preview AgentPool profile.
13481463
@@ -1387,6 +1502,9 @@ def update_agentpool_profile_preview(self, agentpools: List[AgentPool] = None) -
13871502
# update ssh access
13881503
agentpool = self.update_ssh_access(agentpool)
13891504

1505+
# update local DNS profile
1506+
agentpool = self.update_localdns_profile(agentpool)
1507+
13901508
return agentpool
13911509

13921510
def update_upgrade_settings(self, agentpool: AgentPool) -> AgentPool:

src/aks-preview/azext_aks_preview/custom.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,8 @@ def aks_agentpool_add(
14191419
gateway_prefix_size=None,
14201420
# virtualmachines
14211421
vm_sizes=None,
1422+
# local DNS
1423+
localdns_config=None,
14221424
):
14231425
# DO NOT MOVE: get all the original parameters and save them as a dictionary
14241426
raw_parameters = locals()
@@ -1486,6 +1488,8 @@ def aks_agentpool_update(
14861488
if_none_match=None,
14871489
enable_fips_image=False,
14881490
disable_fips_image=False,
1491+
# local DNS
1492+
localdns_config=None,
14891493
):
14901494
# DO NOT MOVE: get all the original parameters and save them as a dictionary
14911495
raw_parameters = locals()
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"mode": "Required",
3+
"kubeDNSOverrides": {
4+
".": {
5+
"cacheDurationInSeconds": 3600,
6+
"forwardDestination": "ClusterCoreDNS",
7+
"forwardPolicy": "Sequential",
8+
"maxConcurrent": 1000,
9+
"protocol": "PreferUDP",
10+
"queryLogging": "Error",
11+
"serveStale": "Verify",
12+
"serveStaleDurationInSeconds": 3600
13+
},
14+
"cluster.local": {
15+
"cacheDurationInSeconds": 3600,
16+
"forwardDestination": "ClusterCoreDNS",
17+
"forwardPolicy": "Sequential",
18+
"maxConcurrent": 1000,
19+
"protocol": "ForceTCP",
20+
"queryLogging": "Error",
21+
"serveStale": "Immediate",
22+
"serveStaleDurationInSeconds": 3600
23+
}
24+
},
25+
"vnetDNSOverrides": {
26+
".": {
27+
"cacheDurationInSeconds": 3600,
28+
"forwardDestination": "VnetDNS",
29+
"forwardPolicy": "Sequential",
30+
"maxConcurrent": 1000,
31+
"protocol": "PreferUDP",
32+
"queryLogging": "Error",
33+
"serveStale": "Verify",
34+
"serveStaleDurationInSeconds": 3600
35+
},
36+
"cluster.local": {
37+
"cacheDurationInSeconds": 3600,
38+
"forwardDestination": "ClusterCoreDNS",
39+
"forwardPolicy": "Sequential",
40+
"maxConcurrent": 1000,
41+
"protocol": "ForceTCP",
42+
"queryLogging": "Error",
43+
"serveStale": "Immediate",
44+
"serveStaleDurationInSeconds": 3600
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)