Skip to content

Commit

Permalink
mutable Fips cli flags added
Browse files Browse the repository at this point in the history
  • Loading branch information
pineapplethevoyager committed Jun 27, 2024
1 parent f3ce427 commit a758ef2
Show file tree
Hide file tree
Showing 11 changed files with 3,890 additions and 1,569 deletions.
4 changes: 4 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ To release a new version, please select a new version number (usually plus 1 to

Pending
+++++++

5.0.0b2
++++++++
* Add support for mutable fips in agentpool update. (enable/disable flags)
* Vendor new SDK and bump API version to 2024-04-02-preview.

5.0.0b1
Expand Down
6 changes: 6 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2004,6 +2004,12 @@
- name: --if-none-match
type: string
short-summary: Set to '*' to allow a new node pool to be created, but to prevent updating an existing node pool. Other values will be ignored.
- name: --enable-fips-image
type: bool
short-summary: Switch to use FIPS-enabled OS on agent nodes.
- name: --disable-fips-image
type: bool
short-summary: Switch to use non-FIPS-enabled OS on agent nodes.
examples:
- name: Reconcile the nodepool back to its current state.
text: az aks nodepool update -g MyResourceGroup -n nodepool1 --cluster-name MyManagedCluster
Expand Down
10 changes: 10 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,16 @@ def load_arguments(self, _):
)
c.argument("if_match")
c.argument("if_none_match")
c.argument(
"enable_fips_image",
is_preview=True,
action="store_true"
)
c.argument(
"disable_fips_image",
is_preview=True,
action="store_true"
)

with self.argument_context("aks nodepool upgrade") as c:
c.argument("max_surge", validator=validate_max_surge)
Expand Down
51 changes: 51 additions & 0 deletions src/aks-preview/azext_aks_preview/agentpool_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,40 @@ def get_vm_sizes(self) -> List[str]:
else:
vm_sizes = [self.get_node_vm_size()]
return vm_sizes

# Overrides azure-cli command to allow changes after create
def get_enable_fips_image(self) -> bool:
"""Obtain the value of enable_fips_image, default value is False.
:return: bool
"""
# how to allow enable but preserve existing logic

# read the original value passed by the command
enable_fips_image = self.raw_param.get("enable_fips_image", False)
# In create mode, try and read the property value corresponding to the parameter from the `agentpool` object
if self.decorator_mode == DecoratorMode.CREATE:
if ( # should i check if enable is not true?
self.agentpool and
hasattr(self.agentpool, "enable_fips") and # backward compatibility
self.agentpool.enable_fips is not None
):
enable_fips_image = self.agentpool.enable_fips

# Verify both flags have not been set
if enable_fips_image and self.get_disable_fips_image():
raise MutuallyExclusiveArgumentError(
'Cannot specify "--enable-fips-image" and "--disable-fips-image" at the same time'
)

return enable_fips_image

def get_disable_fips_image(self) -> bool:
"""Obtain the value of disable_fips_image.
:return: bool
"""
# read the original value passed by the command
return self.raw_param.get("disable_fips_image")

class AKSPreviewAgentPoolAddDecorator(AKSAgentPoolAddDecorator):
def __init__(
Expand Down Expand Up @@ -1091,6 +1124,21 @@ def update_vtpm(self, agentpool: AgentPool) -> AgentPool:
agentpool.security_profile.enable_vtpm = False

return agentpool

def update_fips_image(self, agentpool: AgentPool) -> AgentPool:
"""Update fips image property for the AgentPool object.
:return: the AgentPool object
"""
self._ensure_agentpool(agentpool)

# Updates enable_fips property allowing switching of fips mode
if self.context.get_enable_fips_image():
agentpool.enable_fips = True

if self.context.get_disable_fips_image():
agentpool.enable_fips = False

return agentpool

def update_agentpool_profile_preview(self, agentpools: List[AgentPool] = None) -> AgentPool:
"""The overall controller used to update the preview AgentPool profile.
Expand Down Expand Up @@ -1121,6 +1169,9 @@ def update_agentpool_profile_preview(self, agentpools: List[AgentPool] = None) -
# update os sku
agentpool = self.update_os_sku(agentpool)

# update fips image
agentpool = self.update_fips_image(agentpool)

# update ssh access
agentpool = self.update_ssh_access(agentpool)

Expand Down
2 changes: 2 additions & 0 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,8 @@ def aks_agentpool_update(
disable_vtpm=False,
if_match=None,
if_none_match=None,
enable_fips_image=False,
disable_fips_image=False,
):
# DO NOT MOVE: get all the original parameters and save them as a dictionary
raw_parameters = locals()
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit a758ef2

Please sign in to comment.