Skip to content

Feature/update apptainer role#5

Merged
lbrick merged 3 commits intomainfrom
feature/update_apptainer_role
May 27, 2025
Merged

Feature/update apptainer role#5
lbrick merged 3 commits intomainfrom
feature/update_apptainer_role

Conversation

@lbrick
Copy link
Collaborator

@lbrick lbrick commented May 27, 2025

No description provided.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @lbrick, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

Hello team,

Gemini here, providing a summary of this pull request titled "Feature/update apptainer role". Based on the changes, the primary goal of this PR is to enhance the nesi.apptainer Ansible role by adding configuration for the user.max_user_namespaces kernel parameter. This parameter is crucial for allowing unprivileged users to create user namespaces, which is often required for running containers like Apptainer without root privileges.

The changes involve introducing a new default variable for the maximum number of user namespaces and adding a task to deploy a sysctl configuration file that sets this parameter using the defined variable.

Highlights

  • Configure user namespaces: The pull request adds functionality to configure the user.max_user_namespaces kernel parameter, which is essential for unprivileged container execution.
  • Add sysctl configuration: A new Ansible task and template are introduced to create a sysctl configuration file (/etc/sysctl.d/99-apptainer.conf) to persist the user.max_user_namespaces setting.
  • Introduce default variable: A new default variable max_user_namespaces is added to the role's defaults, allowing easy customization of the namespace limit.

Changelog

  • ansible/roles/nesi.apptainer/defaults/main.yml
    • Added the max_user_namespaces variable with a default value of 16384.
  • ansible/roles/nesi.apptainer/tasks/install.yml
    • Added a new task to install the 99-apptainer.conf sysctl configuration file using a template.
  • ansible/roles/nesi.apptainer/templates/99-apptainer.conf.j2
    • Added a new template file to set the user.max_user_namespaces sysctl parameter based on the max_user_namespaces variable.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Ansible runs the play,
Configures things today,
Namespaces now set,
No root user fret,
Containers find their way.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a configuration for max_user_namespaces for Apptainer by adding a default variable, a template for the sysctl configuration file, and a task to deploy this template. This is a good step towards enhancing Apptainer's functionality.

The main concern is that the new sysctl configuration is not actively applied after being written to disk, meaning the changes won't take effect until the next reboot or manual intervention. I've provided a suggestion to address this using Ansible's handler mechanism.

Summary of Findings

  • Sysctl configuration not applied: The task that writes the /etc/sysctl.d/99-apptainer.conf file does not trigger a mechanism to apply these settings (e.g., by running sysctl -p or sysctl --system). The settings will only take effect after a reboot or manual intervention. This was flagged as a high-severity issue.
  • Missing newlines at end of files: The following files are missing a newline character at the end: ansible/roles/nesi.apptainer/defaults/main.yml, ansible/roles/nesi.apptainer/tasks/install.yml, and ansible/roles/nesi.apptainer/templates/99-apptainer.conf.j2. While this is a minor stylistic issue (low severity) and not commented on directly due to review settings, it's good practice for POSIX text files to end with a newline.

Merge Readiness

This pull request introduces a valuable configuration for Apptainer. However, there is a high-severity issue regarding the application of the new sysctl settings that needs to be addressed. Once the suggested changes to notify a handler (which would apply the sysctl settings) are implemented, the PR will be in much better shape for merging. I am unable to approve pull requests directly, so please ensure further review and approval after addressing the feedback. Due to the high-severity issue, I recommend that these changes be made before merging.

Comment on lines +13 to +19
- name: Install 99-apptainer.conf to /etc/sysctl.d
template:
src: 99-apptainer.conf.j2
dest: /etc/sysctl.d/99-apptainer.conf
owner: root
group: root
mode: '0644' No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The new sysctl configuration file 99-apptainer.conf is correctly templated. However, for these settings to take effect immediately (without a system reboot), the sysctl command needs to be invoked to load the new configuration.

It's standard Ansible practice to use a handler for this. This ensures the command to apply settings is run only when the configuration file actually changes.

Could you add a notify directive to this task and then create a corresponding handler (typically in a handlers/main.yml file within this role)? The handler would execute a command like sysctl --system or, more specifically, sysctl -p /etc/sysctl.d/99-apptainer.conf.

For example, the handler might look like this (in ansible/roles/nesi.apptainer/handlers/main.yml):

# In handlers/main.yml
- name: Apply apptainer sysctl
  ansible.builtin.command: sysctl -p /etc/sysctl.d/99-apptainer.conf
  listen: Apply apptainer sysctl

Adding the notify directive to the current task will trigger this handler when the template changes.

- name: Install 99-apptainer.conf to /etc/sysctl.d
  ansible.builtin.template:
    src: 99-apptainer.conf.j2
    dest: /etc/sysctl.d/99-apptainer.conf
    owner: root
    group: root
    mode: '0644'
  notify: Apply apptainer sysctl

@lbrick lbrick merged commit ce16594 into main May 27, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant