Add support for symlink in package command#120
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: knktc The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @knktc! It looks like this is your first PR to kubesphere/ksbuilder 🎉 |
Summary of ChangesHello @knktc, 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 pull request resolves a critical issue in the Highlights
Using Gemini Code AssistThe 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 by creating a comment using either
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 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
|
There was a problem hiding this comment.
Code Review
This PR fixes an issue where symbolic links were not handled correctly by the package command. By using the copy.Deep option, symlinks are now dereferenced, and their content is copied, which resolves the issue of Helm being unable to load charts from the temporary directory. The change is correct and well-focused. I've added one suggestion to improve code clarity by following a common Go idiom.
| OnSymlink: func(src string) copy.SymlinkAction { | ||
| return copy.Deep | ||
| }, |
There was a problem hiding this comment.
For better code clarity and to adhere to Go idioms, it's recommended to use the blank identifier _ for the unused src parameter. This makes it explicit that the parameter is intentionally ignored and can help avoid potential linter warnings.
| OnSymlink: func(src string) copy.SymlinkAction { | |
| return copy.Deep | |
| }, | |
| OnSymlink: func(_ string) copy.SymlinkAction { | |
| return copy.Deep | |
| }, |
References
- In Go, it is idiomatic to use the blank identifier
_for function parameters that are not used. This explicitly communicates that the parameter is being ignored and can prevent compiler/linter warnings about unused variables.
There was a problem hiding this comment.
Pull request overview
This PR fixes symlink handling in the package command by configuring the copy operation to follow symlinks and copy their target content instead of copying the symlinks themselves. This ensures Helm can properly load charts when extensions contain symbolic links in the charts directory.
Changes:
- Modified the copy.Copy() call to include an Options parameter with an OnSymlink callback that returns copy.Deep, instructing the copy library to follow symlinks and copy the actual file content
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| defer os.RemoveAll(tempDir) // nolint | ||
|
|
||
| if err = copy.Copy(p, tempDir); err != nil { | ||
| // Copy with FollowSymLink option to resolve symlinks |
There was a problem hiding this comment.
The comment mentions "FollowSymLink option" but the actual implementation uses the OnSymlink callback with copy.Deep action. Consider updating the comment to be more accurate, for example: "Configure copy to follow symlinks and copy their target content"
| // Copy with FollowSymLink option to resolve symlinks | |
| // Configure copy to follow symlinks and copy their target content |
| if err = copy.Copy(p, tempDir); err != nil { | ||
| // Copy with FollowSymLink option to resolve symlinks | ||
| opt := copy.Options{ | ||
| OnSymlink: func(src string) copy.SymlinkAction { |
There was a problem hiding this comment.
The src parameter in the OnSymlink callback is unused. Consider using an underscore instead to indicate this is intentional: func(_ string) copy.SymlinkAction
| OnSymlink: func(src string) copy.SymlinkAction { | |
| OnSymlink: func(_ string) copy.SymlinkAction { |
|
This PR has multiple commits, and the default merge method is: squash. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
use repository instead, close |
What this PR does / why we need it:
English:
This PR fixes the symlink handling issue in the package command. When packaging extensions that contain symbolic links in the charts directory, the original implementation would copy the symlinks themselves rather than their target contents. This caused Helm's loader.LoadDir() to fail when trying to resolve these symlinks in the temporary directory, as the original paths were no longer accessible.
The fix adds the OnSymlink option to the copy.Copy() function, configuring it to follow symlinks and copy the actual content (using copy.Deep). This ensures that all files are properly resolved and accessible when Helm loads the chart.
中文:
此 PR 修复了 package 命令中的软链接处理问题。当打包包含软链接的扩展(在 charts 目录中)时,原始实现会复制软链接本身而不是它们指向的目标内容。这导致 Helm 的 loader.LoadDir() 在尝试解析临时目录中的软链接时失败,因为原始路径已经不可访问。
修复方法是为 copy.Copy() 函数添加 OnSymlink 选项,配置其跟随软链接并复制实际内容(使用 copy.Deep)。这确保了 Helm 加载 chart 时所有文件都能被正确解析和访问。
Does this PR introduced a user-facing change?