Skip to content

Commit

Permalink
remove version suffix from extension slice (#2782)
Browse files Browse the repository at this point in the history
* remove version suffix from extension slice

* address comments
  • Loading branch information
nagworld9 authored Mar 13, 2023
1 parent 355dd09 commit b584057
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion azurelinuxagent/common/cgroupapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,12 @@ def _is_systemd_failure(scope_name, stderr):
return unit_not_found in stderr or scope_name not in stderr

@staticmethod
def get_extension_slice_name(extension_name):
def get_extension_slice_name(extension_name, old_slice=False):
# The old slice makes it difficult for user to override the limits because they need to place drop-in files on every upgrade if extension slice is different for each version.
# old slice includes <HandlerName>.<ExtensionName>-<HandlerVersion>
# new slice without version <HandlerName>.<ExtensionName>
if not old_slice:
extension_name = extension_name.rsplit("-", 1)[0]
# Since '-' is used as a separator in systemd unit names, we replace it with '_' to prevent side-effects.
return EXTENSION_SLICE_PREFIX + "-" + extension_name.replace('-', '_') + ".slice"

Expand Down
10 changes: 9 additions & 1 deletion azurelinuxagent/common/cgroupconfigurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ def __create_all_files(files_to_create):

def is_extension_resource_limits_setup_completed(self, extension_name, cpu_quota=None):
unit_file_install_path = systemd.get_unit_file_install_path()
old_extension_slice_path = os.path.join(unit_file_install_path, SystemdCgroupsApi.get_extension_slice_name(extension_name, old_slice=True))
# clean up the old slice from the disk
if os.path.exists(old_extension_slice_path):
CGroupConfigurator._Impl.__cleanup_unit_file(old_extension_slice_path)

extension_slice_path = os.path.join(unit_file_install_path,
SystemdCgroupsApi.get_extension_slice_name(extension_name))
cpu_quota = str(
Expand Down Expand Up @@ -921,7 +926,10 @@ def setup_extension_slice(self, extension_name, cpu_quota):
SystemdCgroupsApi.get_extension_slice_name(extension_name))
try:
cpu_quota = str(cpu_quota) + "%" if cpu_quota is not None else "" # setting an empty value resets to the default (infinity)
_log_cgroup_info("Ensuring the {0}'s CPUQuota is {1}", extension_name, cpu_quota)
if cpu_quota == "":
_log_cgroup_info("CPUQuota not set for {0}", extension_name)
else:
_log_cgroup_info("Ensuring the {0}'s CPUQuota is {1}", extension_name, cpu_quota)
slice_contents = _EXTENSION_SLICE_CONTENTS.format(extension_name=extension_name,
cpu_quota=cpu_quota)
CGroupConfigurator._Impl.__create_unit_file(extension_slice_path, slice_contents)
Expand Down

0 comments on commit b584057

Please sign in to comment.