2020 SLURM ,
2121 STORAGE_TYPES_SUPPORTING_LIVE_UPDATES ,
2222)
23+ from pcluster .utils import get_dictionary_diff , parse_json_string
2324
2425
2526class UpdatePolicy :
@@ -510,6 +511,38 @@ def get_pool_name_from_change_paths(change):
510511 return ""
511512
512513
514+ # ExtraChefAttributes update policy helpers
515+ # Define which paths within ExtraChefAttributes JSON are updatable (dot-notation)
516+ # IMPORTANT: We assume this set to contain the path to leaf fields.
517+ EXTRA_CHEF_ATTRIBUTES_UPDATABLE_PATHS : set [str ] = {
518+ "cluster.slurm.reconfigure_timeout" ,
519+ }
520+
521+
522+ def _get_non_updatable_changes (old_value : str , new_value : str ) -> list [str ]:
523+ """Parse and compare two ExtraChefAttributes JSON strings, returning paths that are not updatable."""
524+ old_attrs = parse_json_string (old_value , raise_on_error = False , default = {}) if old_value else {}
525+ new_attrs = parse_json_string (new_value , raise_on_error = False , default = {}) if new_value else {}
526+
527+ return [p for p in get_dictionary_diff (old_attrs , new_attrs ) if p not in EXTRA_CHEF_ATTRIBUTES_UPDATABLE_PATHS ]
528+
529+
530+ def condition_checker_extra_chef_attributes (change , _ ) -> bool :
531+ """
532+ Check if ExtraChefAttributes changes are allowed.
533+
534+ Only changes to paths defined in EXTRA_CHEF_ATTRIBUTES_UPDATABLE_PATHS are allowed.
535+ """
536+ return len (_get_non_updatable_changes (change .old_value , change .new_value )) == 0
537+
538+
539+ def fail_reason_extra_chef_attributes (change , _ ) -> str :
540+ """Generate fail reason for ExtraChefAttributes update."""
541+ non_updatable_changes = _get_non_updatable_changes (change .old_value , change .new_value )
542+ paths_str = ", " .join (sorted (non_updatable_changes ))
543+ return f"The following ExtraChefAttributes fields cannot be updated: { paths_str } "
544+
545+
513546# Common fail_reason messages
514547UpdatePolicy .FAIL_REASONS = {
515548 "ebs_volume_resize" : "Updating the file system after a resize operation requires commands specific to your "
@@ -526,6 +559,7 @@ def get_pool_name_from_change_paths(change):
526559 "compute_or_login_nodes_running" : lambda change , patch : (
527560 "The update is not supported when compute or login nodes are running"
528561 ),
562+ "extra_chef_attributes_update" : fail_reason_extra_chef_attributes ,
529563}
530564
531565# Common action_needed messages
@@ -548,6 +582,9 @@ def get_pool_name_from_change_paths(change):
548582 "Stop the login nodes by setting Count parameter to 0 "
549583 "and update the cluster with the pcluster update-cluster command"
550584 ),
585+ "extra_chef_attributes_update" : lambda change , patch : (
586+ "Revert the non-updatable ExtraChefAttributes fields to their original values."
587+ ),
551588}
552589
553590# Base policies
@@ -567,6 +604,15 @@ def get_pool_name_from_change_paths(change):
567604 name = "SUPPORTED" , level = 0 , fail_reason = "-" , condition_checker = (lambda change , patch : True )
568605)
569606
607+ # Update policy for ExtraChefAttributes - allows updates to specific fields only
608+ UpdatePolicy .EXTRA_CHEF_ATTRIBUTES = UpdatePolicy (
609+ name = "EXTRA_CHEF_ATTRIBUTES" ,
610+ level = 5 ,
611+ fail_reason = UpdatePolicy .FAIL_REASONS ["extra_chef_attributes_update" ],
612+ action_needed = UpdatePolicy .ACTIONS_NEEDED ["extra_chef_attributes_update" ],
613+ condition_checker = condition_checker_extra_chef_attributes ,
614+ )
615+
570616# Checks resize of max_vcpus in Batch Compute Environment
571617UpdatePolicy .AWSBATCH_CE_MAX_RESIZE = UpdatePolicy (
572618 name = "AWSBATCH_CE_MAX_RESIZE" ,
0 commit comments