Skip to content

[virtual-machine] Fix cloudInit and sshKeys - #1175

Merged
Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
cloud-init-fix
Jul 9, 2025
Merged

[virtual-machine] Fix cloudInit and sshKeys#1175
Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
cloud-init-fix

Conversation

@kvaps

@kvaps Andrei Kvapil (kvaps) commented Jul 9, 2025

Copy link
Copy Markdown
Member

What this PR does

fixes #1148

This PR does two things:

  1. Fixes the cloud-init shebang (cozystack/kubeapps@e1382f5)
    Dashboard comments were removed unintentionally, which also stripped out the cloud-init shebang. This fix puts it back.
  2. Improves cloudInit option handling
    The update refines how various cloudInit options are processed, whether or not sshKeys are provided.

Release note

[dashboard] Fix removing shebang for cloud init
[virtual-machine] Fix cloudInit and sshKeys processing

Summary by CodeRabbit

  • New Features

    • Cloud-init configuration now supports providing SSH keys even when explicit cloud-init data is not set, allowing for easier SSH access setup.
  • Refactor

    • Simplified and unified the logic for handling cloud-init and SSH key configuration in virtual machine templates, reducing complexity and improving maintainability.
  • Chores

    • Updated the default commit reference for Kubeapps components to a newer version in the dashboard build process.

@coderabbitai

coderabbitai Bot commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The cloud-init and SSH key handling logic in Helm templates for virtual-machine and vm-instance was refactored. Now, if either .Values.cloudInit or .Values.sshKeys is present, a secret and corresponding volume are generated, with fallback cloud-config YAML for SSH keys only. Dockerfiles were updated to reference a new kubeapps commit.

Changes

Files Change Summary
packages/apps/virtual-machine/templates/secret.yaml
packages/apps/vm-instance/templates/secret.yaml
Broadened condition for rendering cloud-init secret to include .Values.sshKeys; added fallback cloud-config YAML for SSH keys only.
packages/apps/virtual-machine/templates/vm.yaml
packages/apps/vm-instance/templates/vm.yaml
Simplified and unified logic for generating cloud-init disk and volume; now always references secret if either .Values.cloudInit or .Values.sshKeys is set.
packages/system/dashboard/images/dashboard/Dockerfile
packages/system/dashboard/images/kubeapps-apis/Dockerfile
Updated COMMIT_REF to a new kubeapps commit hash.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant HelmChart
    participant Kubernetes

    User->>HelmChart: Deploy VM with .Values.cloudInit and/or .Values.sshKeys
    HelmChart->>HelmChart: Check if .Values.cloudInit or .Values.sshKeys is present
    alt .Values.cloudInit present
        HelmChart->>Kubernetes: Create Secret with user-provided cloudInit
    else .Values.sshKeys present
        HelmChart->>Kubernetes: Create Secret with generated cloud-config (SSH keys)
    end
    HelmChart->>Kubernetes: Create VM referencing cloud-init Secret as volume
Loading

Assessment against linked issues

Objective Addressed Explanation
Correct handling of cloud-init shebang and YAML parsing for VMs (#1148)

Possibly related PRs

Suggested labels

enhancement, size:M, lgtm

Suggested reviewers

  • lllamnyp
  • klinch0

Poem

A bunny with templates, so clever and neat,
Merged cloud-init and SSH keys in a single feat.
Now secrets and volumes are tidy and right,
VMs spin up with configs—what a delight!
🐇✨

With hashes updated, the dashboard feels new,
This rabbit says, “Hooray for the crew!”


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kvaps Andrei Kvapil (kvaps) changed the title cloud init fix [virtual-machine] Fix cloudInit Jul 9, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
packages/apps/virtual-machine/templates/secret.yaml (1)

8-9: Trailing whitespace violates YAML-lint

The extra space after quote $v }} triggers the reported lint error.
Trim it to keep the chart CI-friendly.

-  key{{ $k }}: {{ quote $v }} 
+  key{{ $k }}: {{ quote $v }}
packages/apps/vm-instance/templates/secret.yaml (1)

8-9: Trim trailing spaces to satisfy YAML-lint

-  key{{ $k }}: {{ quote $v }} 
+  key{{ $k }}: {{ quote $v }}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 699d38d and ed37fc7.

📒 Files selected for processing (7)
  • packages/apps/virtual-machine/Chart.yaml (1 hunks)
  • packages/apps/virtual-machine/templates/secret.yaml (1 hunks)
  • packages/apps/virtual-machine/templates/vm.yaml (2 hunks)
  • packages/apps/vm-instance/templates/secret.yaml (1 hunks)
  • packages/apps/vm-instance/templates/vm.yaml (2 hunks)
  • packages/system/dashboard/images/dashboard/Dockerfile (1 hunks)
  • packages/system/dashboard/images/kubeapps-apis/Dockerfile (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
packages/apps/virtual-machine/templates/secret.yaml

[error] 26-26: trailing spaces

(trailing-spaces)

packages/apps/vm-instance/templates/secret.yaml

[error] 26-26: trailing spaces

(trailing-spaces)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (7)
packages/system/dashboard/images/dashboard/Dockerfile (1)

4-4: Commit hash bumped – please confirm the source still builds

Changing COMMIT_REF directly pins the build to a new commit. Before merging, double-check that

  1. the tarball for e1382f51c6db1bca0a8ecd454407c8e282fe0243 is still available/public, and
  2. no files referenced later in the Dockerfile (dashboard path, package.json, etc.) were moved or removed in that commit.

A quick docker build locally or in CI will catch surprises early.

packages/system/dashboard/images/kubeapps-apis/Dockerfile (1)

7-7: Sync’d hash is good, but validate build + generated binaries

The COMMIT_REF now matches the dashboard image, keeping both stages consistent—nice.
Please run or ensure CI runs:

docker build -f packages/system/dashboard/images/kubeapps-apis/Dockerfile .

to verify proto linting and Go compilation still succeed with this commit.

packages/apps/virtual-machine/Chart.yaml (1)

20-26: Version bump looks fine

Patch-level increment is appropriate for these template-only changes.
No further action required.

packages/apps/virtual-machine/templates/vm.yaml (2)

95-100: Condition refactor LGTM

Unified or .Values.cloudInit .Values.sshKeys keeps disk & volume definitions in sync with the new secret logic.


125-130: Volume name matches disk, secret reference correct

The volume correctly points to <fullname>-cloud-init; aligns with the updated secret template.

packages/apps/vm-instance/templates/vm.yaml (2)

71-75: Disk condition update consistent with secret changes

No issues spotted; mirrors virtual-machine chart behaviour.


98-103: Volume reference looks good

Volume → secret linkage matches generated secret name; everything lines up.

Comment thread packages/apps/virtual-machine/templates/secret.yaml
Comment thread packages/apps/vm-instance/templates/secret.yaml
@kvaps Andrei Kvapil (kvaps) changed the title [virtual-machine] Fix cloudInit [virtual-machine] Fix cloudInit and sshKeys Jul 9, 2025
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
packages/apps/vm-instance/templates/secret.yaml (1)

6-6: Chart name mismatch – will render to the wrong Secret name

include "virtual-machine.fullname" is invoked inside the vm-instance chart.
Unless your helpers define virtual-machine.fullname globally, Helm will error out (template not found).
Even if it exists, you’ll end up with two different charts emitting identically named Secrets, causing collisions in the same namespace.

-  name: {{ include "virtual-machine.fullname" $ }}-ssh-keys
+  name: {{ include "vm-instance.fullname" $ }}-ssh-keys

Replicate the same fix for the cloud-init Secret further below.

🧹 Nitpick comments (3)
packages/apps/virtual-machine/templates/secret.yaml (2)

24-27: Remove trailing whitespace – YAML lint is currently failing

The bullet lines in the SSH-key fallback block keep a single trailing space that trips YAML lint ([error] 26-26: trailing spaces).
This is invisible in Git but breaks CI in lint–strict pipelines.

-      - {{ quote . }} 
+      - {{ quote . }}

20-28: Indentation of fallback cloud-config is brittle

When .Values.cloudInit is absent, the inline #cloud-config section relies on hard-coded spaces in the template file.
Helm users frequently indent templates differently; if anyone re-formats this file, the four leading spaces can shift and the rendered YAML will break.

A safer pattern is to render the whole block via nindent 4, just like the custom cloudInit path:

-    #cloud-config
-    ssh_authorized_keys:
-      {{- range .Values.sshKeys }}
-      - {{ quote . }}
-      {{- end }}
+{{-   printf "#cloud-config\nssh_authorized_keys:\n%s" (join .Values.sshKeys "\n") | nindent 4 }}

Any equivalent approach that keeps the four-space indent programmatically will do.

packages/apps/vm-instance/templates/secret.yaml (1)

24-27: Trailing whitespace – identical YAML lint failure here

Same as in the virtual-machine template: strip the space after quote . to silence YAML lint.

-      - {{ quote . }} 
+      - {{ quote . }}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ed37fc7 and c831f53.

📒 Files selected for processing (6)
  • packages/apps/virtual-machine/templates/secret.yaml (1 hunks)
  • packages/apps/virtual-machine/templates/vm.yaml (2 hunks)
  • packages/apps/vm-instance/templates/secret.yaml (1 hunks)
  • packages/apps/vm-instance/templates/vm.yaml (2 hunks)
  • packages/system/dashboard/images/dashboard/Dockerfile (1 hunks)
  • packages/system/dashboard/images/kubeapps-apis/Dockerfile (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/system/dashboard/images/kubeapps-apis/Dockerfile
  • packages/apps/vm-instance/templates/vm.yaml
  • packages/system/dashboard/images/dashboard/Dockerfile
  • packages/apps/virtual-machine/templates/vm.yaml
🧰 Additional context used
🪛 YAMLlint (1.37.1)
packages/apps/virtual-machine/templates/secret.yaml

[error] 26-26: trailing spaces

(trailing-spaces)

packages/apps/vm-instance/templates/secret.yaml

[error] 26-26: trailing spaces

(trailing-spaces)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build

@kvaps
Andrei Kvapil (kvaps) merged commit 411a465 into main Jul 9, 2025
18 checks passed
@kvaps
Andrei Kvapil (kvaps) deleted the cloud-init-fix branch July 9, 2025 08:21
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.

Cloudinit's shebang incorrectly parsed as a comment in yaml spec for VMs

2 participants