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
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.155
+++++++
* Add `--enable-cost-analysis` and `--disable-cost-analysis` to the `az aks update` command.
* Add `--enable-cost-analysis` to the `az aks create` command.

0.5.154
+++++++
* Vendor new SDK and bump API version to 2023-07-02-preview.
Expand Down
9 changes: 9 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,9 @@
- name: --nodepool-taints
type: string
short-summary: The node taints for all node pools in this cluster.
- name: --enable-cost-analysis
type: bool
short-summary: Enable exporting Kubernetes Namespace and Deployment details to the Cost Analysis views in the Azure portal. For more information see aka.ms/aks/docs/cost-analysis.
examples:
- name: Create a Kubernetes cluster with an existing SSH public key.
text: az aks create -g MyResourceGroup -n MyManagedCluster --ssh-key-value /path/to/publickey
Expand Down Expand Up @@ -1066,6 +1069,12 @@
- name: --enable-network-observability
type: bool
short-summary: Enable network observability on a cluster.
- name: --enable-cost-analysis
type: bool
short-summary: Enable exporting Kubernetes Namespace and Deployment details to the Cost Analysis views in the Azure portal. For more information see aka.ms/aks/docs/cost-analysis.
- name: --disable-cost-analysis
type: bool
short-summary: Disable exporting Kubernetes Namespace and Deployment details to the Cost Analysis views in the Azure portal.
examples:
- name: Reconcile the cluster back to its current state.
text: az aks update -g MyResourceGroup -n MyManagedCluster
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 @@ -449,6 +449,7 @@ def load_arguments(self, _):
c.argument('ksm_metric_annotations_allow_list')
c.argument('grafana_resource_id', validator=validate_grafanaresourceid)
c.argument('enable_windows_recording_rules', action='store_true')
c.argument('enable_cost_analysis', is_preview=True, action='store_true')

with self.argument_context('aks update') as c:
# managed cluster paramerters
Expand Down Expand Up @@ -573,6 +574,8 @@ def load_arguments(self, _):
c.argument('guardrails_version', help='The guardrails version', is_preview=True)
c.argument('guardrails_excluded_ns', is_preview=True)
c.argument('enable_network_observability', action='store_true', is_preview=True, help="enable network observability for cluster")
c.argument('enable_cost_analysis', is_preview=True, action='store_true')
c.argument('disable_cost_analysis', is_preview=True, action='store_true')

with self.argument_context('aks upgrade') as c:
c.argument('kubernetes_version', completer=get_k8s_upgrades_completion_list)
Expand Down
5 changes: 5 additions & 0 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ def aks_create(
ksm_metric_annotations_allow_list=None,
grafana_resource_id=None,
enable_windows_recording_rules=False,
# metrics profile
enable_cost_analysis=False,
):
# DO NOT MOVE: get all the original parameters and save them as a dictionary
raw_parameters = locals()
Expand Down Expand Up @@ -755,6 +757,9 @@ def aks_update(
guardrails_version=None,
guardrails_excluded_ns=None,
enable_network_observability=None,
# metrics profile
enable_cost_analysis=False,
disable_cost_analysis=False,
):
# DO NOT MOVE: get all the original parameters and save them as a dictionary
raw_parameters = locals()
Expand Down
96 changes: 96 additions & 0 deletions src/aks-preview/azext_aks_preview/managed_cluster_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,41 @@ def get_nodepool_taints(self) -> Union[List[str], None]:
"""
return self.agentpool_context.get_node_taints()

def _get_enable_cost_analysis(self, enable_validation: bool = False) -> bool:
"""Internal function to obtain the value of enable_cost_analysis.

When enabled, if both enable_cost_analysis and disable_cost_analysis are
specified, raise a MutuallyExclusiveArgumentError.

:return: bool
"""
enable_cost_analysis = self.raw_param.get("enable_cost_analysis")

# This parameter does not need dynamic completion.
if enable_validation:
if enable_cost_analysis and self.get_disable_cost_analysis():
raise MutuallyExclusiveArgumentError(
"Cannot specify --enable-cost-analysis and --disable-cost-analysis at the same time."
)

return enable_cost_analysis

def get_enable_cost_analysis(self) -> bool:
"""Obtain the value of enable_cost_analysis.

:return: bool
"""
return self._get_enable_cost_analysis(enable_validation=True)

def get_disable_cost_analysis(self) -> bool:
"""Obtain the value of disable_cost_analysis.

:return: bool
"""
# Note: No need to check for mutually exclusive parameter with enable-cost-analysis here
# because it's already checked in _get_enable_cost_analysis
return self.raw_param.get("disable_cost_analysis")


class AKSPreviewManagedClusterCreateDecorator(AKSManagedClusterCreateDecorator):
def __init__(
Expand Down Expand Up @@ -2714,6 +2749,29 @@ def set_up_sku(self, mc: ManagedCluster) -> ManagedCluster:
)
return mc

def set_up_cost_analysis(self, mc: ManagedCluster) -> ManagedCluster:
self._ensure_mc(mc)

if self.context.get_enable_cost_analysis():
if mc.metrics_profile is None:
mc.metrics_profile = self.models.ManagedClusterMetricsProfile()
if mc.metrics_profile.cost_analysis is None:
mc.metrics_profile.cost_analysis = self.models.ManagedClusterCostAnalysis()

# set enabled
mc.metrics_profile.cost_analysis.enabled = True

# Default is disabled so no need to worry about that here

return mc

def set_up_metrics_profile(self, mc: ManagedCluster) -> ManagedCluster:
self._ensure_mc(mc)

mc = self.set_up_cost_analysis(mc)

return mc

def construct_mc_profile_preview(self, bypass_restore_defaults: bool = False) -> ManagedCluster:
"""The overall controller used to construct the default ManagedCluster profile.

Expand Down Expand Up @@ -2757,6 +2815,8 @@ def construct_mc_profile_preview(self, bypass_restore_defaults: bool = False) ->
mc = self.set_up_azure_service_mesh_profile(mc)
# set up azure monitor profile
mc = self.set_up_azure_monitor_profile(mc)
# set up metrics profile
mc = self.set_up_metrics_profile(mc)

# DO NOT MOVE: keep this at the bottom, restore defaults
mc = self._restore_defaults_in_mc(mc)
Expand Down Expand Up @@ -3601,6 +3661,40 @@ def update_nodepool_taints_mc(self, mc: ManagedCluster) -> ManagedCluster:
agent_profile.node_taints = nodepool_taints
return mc

def update_cost_analysis(self, mc: ManagedCluster) -> ManagedCluster:
self._ensure_mc(mc)

if self.context.get_enable_cost_analysis():
if mc.metrics_profile is None:
mc.metrics_profile = self.models.ManagedClusterMetricsProfile()
if mc.metrics_profile.cost_analysis is None:
mc.metrics_profile.cost_analysis = self.models.ManagedClusterCostAnalysis()

# set enabled
mc.metrics_profile.cost_analysis.enabled = True

if self.context.get_disable_cost_analysis():
if mc.metrics_profile is None:
mc.metrics_profile = self.models.ManagedClusterMetricsProfile()
if mc.metrics_profile.cost_analysis is None:
mc.metrics_profile.cost_analysis = self.models.ManagedClusterCostAnalysis()

# set disabled
mc.metrics_profile.cost_analysis.enabled = False

return mc

def update_metrics_profile(self, mc: ManagedCluster) -> ManagedCluster:
"""Updates the metricsProfile field of the managed cluster

:return: the ManagedCluster object
"""
self._ensure_mc(mc)

mc = self.update_cost_analysis(mc)

return mc

def update_mc_profile_preview(self) -> ManagedCluster:
"""The overall controller used to update the preview ManagedCluster profile.

Expand Down Expand Up @@ -3656,5 +3750,7 @@ def update_mc_profile_preview(self) -> ManagedCluster:
mc = self.update_nodepool_taints_mc(mc)
# update network_observability in network_profile
mc = self.update_enable_network_observability_in_network_profile(mc)
# update metrics profile
mc = self.update_metrics_profile(mc)

return mc
Loading