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
6 changes: 6 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@

CONST_OUTBOUND_TYPE_LOAD_BALANCER = "loadBalancer"
CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING = "userDefinedRouting"

CONST_SCALE_SET_PRIORITY_REGULAR = "Regular"
CONST_SCALE_SET_PRIORITY_SPOT = "Spot"

CONST_SPOT_EVICTION_POLICY_DELETE = "Delete"
CONST_SPOT_EVICTION_POLICY_DEALLOCATE = "Deallocate"
9 changes: 9 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,15 @@
- name: --mode
type: string
short-summary: The mode for a node pool which defines a node pool's primary function. If set as "System", AKS prefers system pods scheduling to node pools with mode `System`. Learn more at https://aka.ms/aks/nodepool/mode.
- name: --priority
type: string
short-summary: The priority of the node pool.
- name: --eviction-policy
type: string
short-summary: The eviction policy of the Spot node pool. It can only be set when --priority is Spot.
- name: --spot-max-price
type: float
short-summary: It can only be set when --priority is Spot. Specify the maximum price you are willing to pay in US Dollars. Possible values are any decimal value greater than zero or -1 which indicates default price to be up-to on-demand. It can only include up to 5 decimal places.
"""

helps['aks nodepool delete'] = """
Expand Down
8 changes: 7 additions & 1 deletion src/azure-cli/azure/cli/command_modules/acs/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
validate_cluster_autoscaler_profile, validate_create_parameters, validate_kubectl_version, validate_kubelogin_version, validate_k8s_version, validate_linux_host_name,
validate_list_of_integers, validate_ssh_key, validate_nodes_count,
validate_nodepool_name, validate_vm_set_type, validate_load_balancer_sku, validate_load_balancer_outbound_ips,
validate_priority, validate_eviction_policy, validate_spot_max_price,
validate_load_balancer_outbound_ip_prefixes, validate_taints, validate_ip_ranges, validate_acr, validate_nodepool_tags,
validate_load_balancer_outbound_ports, validate_load_balancer_idle_timeout, validate_vnet_subnet_id, validate_nodepool_labels)
from ._consts import CONST_OUTBOUND_TYPE_LOAD_BALANCER, CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING
from ._consts import CONST_OUTBOUND_TYPE_LOAD_BALANCER, CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING, \
CONST_SCALE_SET_PRIORITY_REGULAR, CONST_SCALE_SET_PRIORITY_SPOT, \
CONST_SPOT_EVICTION_POLICY_DELETE, CONST_SPOT_EVICTION_POLICY_DEALLOCATE

orchestrator_types = ["Custom", "DCOS", "Kubernetes", "Swarm", "DockerCE"]

Expand Down Expand Up @@ -282,6 +285,9 @@ def load_arguments(self, _):
c.argument('os_type', type=str)
c.argument('enable_cluster_autoscaler', options_list=["--enable-cluster-autoscaler", "-e"], action='store_true')
c.argument('node_taints', type=str, validator=validate_taints)
c.argument('priority', arg_type=get_enum_type([CONST_SCALE_SET_PRIORITY_REGULAR, CONST_SCALE_SET_PRIORITY_SPOT]), validator=validate_priority)
c.argument('eviction_policy', arg_type=get_enum_type([CONST_SPOT_EVICTION_POLICY_DELETE, CONST_SPOT_EVICTION_POLICY_DEALLOCATE]), validator=validate_eviction_policy)
c.argument('spot_max_price', type=float, validator=validate_spot_max_price)
c.argument('tags', tags_type)
c.argument('labels', nargs='*', validator=validate_nodepool_labels)
c.argument('mode', get_enum_type(nodepool_mode_type))
Expand Down
34 changes: 34 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import os.path
import re
from math import isnan, isclose
from ipaddress import ip_network

# pylint: disable=no-name-in-module,import-error
Expand Down Expand Up @@ -256,6 +257,39 @@ def validate_taints(namespace):
raise CLIError('Invalid node taint: %s' % taint)


def validate_priority(namespace):
"""Validates the node pool priority string."""
if namespace.priority is not None:
if namespace.priority == '':
return
if namespace.priority != "Spot" and \
namespace.priority != "Regular":
raise CLIError("--priority can only be Spot or Regular")


def validate_eviction_policy(namespace):
"""Validates the node pool priority string."""
if namespace.eviction_policy is not None:
if namespace.eviction_policy == '':
return
if namespace.eviction_policy != "Delete" and \
namespace.eviction_policy != "Deallocate":
raise CLIError("--eviction-policy can only be Delete or Deallocate")


def validate_spot_max_price(namespace):
"""Validates the spot node pool max price."""
if not isnan(namespace.spot_max_price):
if namespace.priority != "Spot":
raise CLIError("--spot_max_price can only be set when --priority is Spot")
if len(str(namespace.spot_max_price).split(".")) > 1 and len(str(namespace.spot_max_price).split(".")[1]) > 5:
raise CLIError("--spot_max_price can only include up to 5 decimal places")
if namespace.spot_max_price <= 0 and not isclose(namespace.spot_max_price, -1.0, rel_tol=1e-06):
raise CLIError(
"--spot_max_price can only be any decimal value greater than zero, or -1 which indicates "
"default price to be up-to on-demand")


def validate_acr(namespace):
if namespace.attach_acr and namespace.detach_acr:
raise CLIError('Cannot specify "--attach-acr" and "--detach-acr" at the same time.')
Expand Down
13 changes: 13 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import time
import uuid
import webbrowser
from math import isnan
from six.moves.urllib.request import urlopen # pylint: disable=import-error
from six.moves.urllib.error import URLError # pylint: disable=import-error

Expand Down Expand Up @@ -96,6 +97,8 @@
from ._loadbalancer import (set_load_balancer_sku, is_load_balancer_profile_provided,
update_load_balancer_profile, create_load_balancer_profile)

from ._consts import CONST_SCALE_SET_PRIORITY_REGULAR, CONST_SCALE_SET_PRIORITY_SPOT, CONST_SPOT_EVICTION_POLICY_DELETE

logger = get_logger(__name__)


Expand Down Expand Up @@ -2880,6 +2883,9 @@ def aks_agentpool_add(cmd, client, resource_group_name, cluster_name, nodepool_n
max_count=None,
enable_cluster_autoscaler=False,
node_taints=None,
priority=CONST_SCALE_SET_PRIORITY_REGULAR,
eviction_policy=CONST_SPOT_EVICTION_POLICY_DELETE,
spot_max_price=float('nan'),
tags=None,
labels=None,
mode="User",
Expand Down Expand Up @@ -2919,11 +2925,18 @@ def aks_agentpool_add(cmd, client, resource_group_name, cluster_name, nodepool_n
max_pods=int(max_pods) if max_pods else None,
orchestrator_version=kubernetes_version,
availability_zones=zones,
scale_set_priority=priority,
enable_node_public_ip=enable_node_public_ip,
node_taints=taints_array,
mode=mode
)

if priority == CONST_SCALE_SET_PRIORITY_SPOT:
agent_pool.scale_set_eviction_policy = eviction_policy
if isnan(spot_max_price):
spot_max_price = -1
agent_pool.spot_max_price = spot_max_price

_check_cluster_autoscaler_flag(enable_cluster_autoscaler, min_count, max_count, node_count, agent_pool)

if node_osdisk_size:
Expand Down
Loading