-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
dd: 添加 --cloud-data 选项支持 NoCloud 自动配置 #551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
aecf9eb to
dd60a5a
Compare
Summary of ChangesHello @luhengsw, 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! 此拉取请求旨在增强 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
本次 PR 添加了 --cloud-data 选项,用于在 dd 镜像时自动配置 cloud-init NoCloud 数据源,这是一个非常有价值的功能,增强了云镜像部署的自动化能力。代码实现思路清晰,在 host 端处理文件收集,在 Alpine initrd 中完成配置,复用了现有逻辑,整体设计良好。
我发现了一些可以改进的地方:
- 一个关键的配置
confhome指向了个人开发分支,这在合并前需要修正。 - 在处理本地
--cloud-data目录时,文件复制命令在目录为空的情况下会提前报错,可以优化以提供更友好的错误提示。 - 脚本中有几处文件路径变量未加引号,虽然在当前上下文中可能不会出错,但为了代码的健壮性建议修复。
具体的修改建议请见代码行评论。总体来说,这是一个很棒的改进!
I am having trouble creating individual review comments. Click here to see my feedback.
reinstall.sh (6)
confhome URL 指向了个人的开发分支。在合并之前,请务必将其改回主仓库的 URL,以确保脚本的稳定性和安全性。
confhome=https://raw.githubusercontent.com/bin456789/reinstall/main
reinstall.sh (3754)
当 $cloud_data 是一个空目录时,cp "$cloud_data"/* 命令中的 glob 模式 * 将不会匹配任何文件。由于脚本设置了 set -e,这会导致 cp 命令因找不到文件而失败,从而中断整个脚本。建议使用 shopt -s nullglob 来优雅地处理空目录的情况,这样如果目录为空,cp 命令将不会执行,脚本会继续执行到后面的 user-data 文件校验逻辑,从而给出更明确的错误信息。
(shopt -s nullglob; cp "$cloud_data"/* $initrd_dir/configs/cloud-data/)
reinstall.sh (3758)
curl 命令的 -o 选项指定输出文件时,文件路径 $initrd_dir/configs/cloud-data/$f 没有被引号包围。虽然目前 $initrd_dir 的值 /reinstall-tmp/initrd 不包含空格,但为了代码的健壮性和未来的可维护性,建议为所有包含变量的文件路径添加引号。
curl -sSfL "$cloud_data/$f" -o "$initrd_dir/configs/cloud-data/$f" 2>/dev/null || true
trans.sh (3801)
在 setup_nocloud 函数中,多处使用了 $os_dir 变量来构建文件路径,但没有用引号包围。如果 $os_dir 路径中包含空格或特殊字符,这可能会导致命令执行失败。为了增强脚本的健壮性,建议将所有用作路径的变量都用双引号包围。此问题在本函数中多处存在。
mkdir -p "$os_dir/etc/cloud/cloud.cfg.d"
dd60a5a to
99526b7
Compare
|
测试结果 情况 1:目录有文件 ✅ 使用 nullglob:正常复制 情况 2:空目录 ❌ 使用 nullglob: ❌ 不用 nullglob: 发现的问题 Review 意见有误!它说: 但实际上:
唯一的区别是错误信息:
结论 使用 nullglob:
建议:去掉 nullglob,因为它没有实际好处,反而让错误信息更不清楚。 |
99526b7 to
210fc93
Compare
210fc93 to
8cab3b1
Compare
|
Addressed all review comments, ready for another look |
为
reinstall.sh dd --img添加--cloud-data选项,支持在 dd 镜像写入磁盘后自动配置 cloud-init NoCloud数据源,采用标准的cloud-init配置流水线(区别于--ci模式通过脚本直接改写网络等操作)
合并原因和目的
问题背景
当前使用
dd --img部署cloud-image的时候,无法便捷地注入 标准cloud-init 配置工作流解决方案价值
影响范围
--cloud-data时行为完全不变实现内容
1. reinstall.sh 修改(3处)
添加
--cloud-data选项解析cloud-data:$cloud_data变量在 host 端收集并打包配置文件
user-data、meta-data、network-config文件/configs/cloud-data/目录user-data文件2. trans.sh 修改(3处)
新增
setup_nocloud()函数实现 NoCloud 数据源配置:
/etc/cloud/cloud.cfg.d/99-datasource.cfg指定 NoCloud 数据源/var/lib/cloud/seed/nocloud/cloud-init.disabled禁用标记扩展
modify_os_on_disk()支持 nocloud 模式nocloud分支调用setup_nocloud()umount /os确保清理集成到 dd 工作流
dd_raw_with_extract后检查/configs/cloud-data是否存在modify_os_on_disk nocloud进行配置使用方法
配置目录/URL 需包含:
user-data(必需):cloud-init 用户配置meta-data(可选):实例元数据network-config(可选):网络配置配置示例
技术细节
modify_os_on_disk的挂载和遍历逻辑执行流程