Skip to content

Conversation

mayooot
Copy link

@mayooot mayooot commented Aug 18, 2025

What type of PR is this?

Add one of the following kinds:

/kind cleanup
/kind feature

What this PR does / why we need it:
Add additional check for initContainers in webhook

@hami-robot
Copy link
Contributor

hami-robot bot commented Aug 18, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mayooot
Once this PR has been reviewed and has the lgtm label, please assign wawa0210 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

@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.

Summary of Changes

Hello @mayooot, 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!

This PR extends the webhook logic to include initContainers when performing resource and scheduler assignment checks. Previously, these checks were only applied to standard containers. This ensures a more comprehensive validation process for pods.

Highlights

  • Webhook Logic Enhancement: The webhook's validation process has been updated to iterate over both standard containers and initContainers when checking resources and scheduler assignments.
  • Logging Improvement: An existing informational log message has been modified to provide clearer context, indicating that resource and scheduler assignment checks are being performed.
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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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.

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
Contributor

@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 extends the webhook's resource checking to include initContainers. The implementation has a critical bug that will cause a panic due to an out-of-bounds index access when iterating over the containers. I've provided a fix that correctly and safely iterates over both regular and init containers while ensuring that any mutations are applied to the original pod specification.

Copy link

codecov bot commented Aug 18, 2025

Codecov Report

❌ Patch coverage is 52.94118% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/scheduler/webhook.go 52.94% 5 Missing and 3 partials ⚠️
Flag Coverage Δ
unittests 65.35% <52.94%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/scheduler/webhook.go 52.17% <52.94%> (+2.17%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@archlitchi
Copy link
Member

Is this work for initContainer? have you tested on your environment?

@mayooot mayooot force-pushed the feat/check-initContainers branch from 0be56b2 to 57a634f Compare August 19, 2025 06:16
@hami-robot hami-robot bot added size/L and removed size/XS labels Aug 19, 2025
@mayooot
Copy link
Author

mayooot commented Aug 19, 2025

/gemini review

Copy link
Contributor

@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 adds a check for initContainers in the admission webhook, mirroring the existing logic for regular containers. My review focuses on improving code maintainability by refactoring duplicated logic and addressing a variable shadowing issue in the new test case. These changes will make the code cleaner and less prone to errors.

@mayooot
Copy link
Author

mayooot commented Aug 19, 2025

Is this work for initContainer? have you tested on your environment?

I'll test this case in my k3s once I have prepared the HAMi development environment.
I have already developed a unit case, and it can passes successfully. Could you take a look?

@mayooot mayooot force-pushed the feat/check-initContainers branch from 13c0db6 to 4fbbc5f Compare August 19, 2025 11:37
@archlitchi
Copy link
Member

CC @Shouren

@wawa0210
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


cc @s

@Shouren
Copy link
Collaborator

Shouren commented Aug 22, 2025

CC @Shouren

@mayooot @archlitchi Let me test it later.

@Shouren
Copy link
Collaborator

Shouren commented Sep 3, 2025

CC @Shouren

@mayooot @archlitchi Let me test it later.

@mayooot @archlitchi I have tested this PR in my environment with two cases:

  • Only Initcontainer requests GPU resources
  • Initcontainer and container request GPU resources simultaneously

Both cases failed.

After checking the code, i found that Resourcereqs func in pkg/device/device.godoes not take initContainer into account. So modification in this PR does not make HAMi works with initContainers of a Pod.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants