Skip to content

Add support for generating kube.yaml and quadlet/kube files for llama… #1457

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

Merged
merged 1 commit into from
Jun 3, 2025

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Jun 1, 2025

…-stack

Summary by Sourcery

Enable the serve command to produce Kubernetes YAML and quadlet unit files via --generate flags when using the llama-stack API, refactor file generation into shared helpers, and update documentation and tests to cover the new functionality.

New Features:

  • Add CLI support for --generate=kube to output Kubernetes YAML files for llama-stack
  • Add CLI support for --generate=quadlet/kube to output quadlet unit files that reference generated YAML

Bug Fixes:

  • Fix label formatting in model service output to "Llama Stack RESTAPI"

Enhancements:

  • Extract common file-generation logic into new genfile and kube helper functions
  • Enhance file.py to preserve comment sections when writing unit files
  • Refactor quadlet.py and kube.py to leverage shared helper functions

Documentation:

  • Extend serve command documentation with examples for generating kube and quadlet files

Tests:

  • Add system tests covering Kubernetes YAML generation for llama-stack

Copy link
Contributor

sourcery-ai bot commented Jun 1, 2025

Reviewer's Guide

This PR extends the serve command to support generating Kubernetes YAML and quadlet unit files when using the llama-stack API, refactors common generation logic into reusable helpers, and updates tests and documentation accordingly.

Sequence Diagram for Kube YAML Generation via --generate=kube

sequenceDiagram
    actor User
    participant CLI as "ramalama serve"
    participant StackServe as "Stack.serve()"
    participant KubeGenfile as "kube.genfile()"
    participant PlainFileObj as "PlainFile Object"
    participant Filesystem

    User->>CLI: ramalama serve --generate=kube ...
    CLI->>StackServe: Invoke with args
    StackServe->>KubeGenfile: genfile(name, yamlContent)
    activate KubeGenfile
    KubeGenfile->>PlainFileObj: new PlainFile(name.yaml)
    KubeGenfile->>PlainFileObj: .content = yamlContent
    PlainFileObj->>Filesystem: write(name.yaml)
    KubeGenfile-->>StackServe: Return PlainFile
    deactivate KubeGenfile
    StackServe-->>CLI: 
    CLI-->>User: Output: "Generating Kubernetes YAML file: name.yaml"
Loading

Sequence Diagram for Kube YAML and Quadlet File Generation via --generate=quadlet/kube

sequenceDiagram
    actor User
    participant CLI as "ramalama serve"
    participant StackServe as "Stack.serve()"
    participant KubeGenfile as "kube.genfile()"
    participant QuadletKube as "quadlet.kube()"
    participant PlainFileObj as "PlainFile Object"
    participant UnitFileObj as "UnitFile Object"
    participant Filesystem

    User->>CLI: ramalama serve --generate=quadlet/kube ...
    CLI->>StackServe: Invoke with args

    StackServe->>KubeGenfile: genfile(name, yamlContent)
    activate KubeGenfile
    KubeGenfile->>PlainFileObj: new PlainFile(name.yaml)
    KubeGenfile->>PlainFileObj: .content = yamlContent
    PlainFileObj->>Filesystem: write(name.yaml)
    KubeGenfile-->>StackServe: Return PlainFile
    deactivate KubeGenfile

    StackServe->>QuadletKube: kube(name, description)
    activate QuadletKube
    QuadletKube->>UnitFileObj: new UnitFile(name.kube)
    QuadletKube->>UnitFileObj: Add Kube, Unit, Install sections
    UnitFileObj->>Filesystem: write(name.kube)
    QuadletKube-->>StackServe: Return UnitFile
    deactivate QuadletKube

    StackServe-->>CLI: 
    CLI-->>User: Output: Generation messages
Loading

File-Level Changes

Change Details Files
Support --generate=kube and --generate=quadlet/kube in llama-stack serve
  • Add branches in serve() to detect generate.gen_type ‘kube’ or ‘quadlet/kube’
  • Invoke kube.genfile() to write the .yaml file to the output directory
  • When generating quadlets, also call quadlet.kube(), add service comments, and write the .kube file
ramalama/stack.py
Extract YAML and quadlet generators into helper functions
  • Introduce genfile(name, content) in kube.py and delegate content creation
  • Refactor quadlet.py to replace inline kube logic with a kube(name, description) helper
  • Simplify quadlet.kube() to call the new kube() function
ramalama/kube.py
ramalama/quadlet.py
Enhance file abstraction to support comment sections
  • Change File.add() signature to accept an optional value
  • In File.write(), output comment lines before other sections and skip 'comment' in section loop
ramalama/file.py
Update CLI tests to cover llama-stack generation
  • Re-indent and standardize existing dry-run serve bats tests
  • Add new Bats test that verifies Kubernetes YAML generation for llama-stack API
test/system/040-serve.bats
Extend man page docs with generation examples
  • Add YAML and quadlet generation sections under --generate in ramalama-serve.1.md
  • Include full sample manifest snippets for both kube and quadlet/kube usage
docs/ramalama-serve.1.md
Minor output message fix in compute_serving_port
  • Correct printed label from 'LlamaStack RESTAPI' to 'Llama Stack RESTAPI'
ramalama/model.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @rhatdan - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

ramalama/file.py Outdated
@@ -63,7 +63,12 @@ def write(self, dirpath: str):
self._write(f)

def _write(self, f):
for section in self.sections["comment"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Guard against missing 'comment' section before iterating

Accessing self.sections['comment'] directly may raise a KeyError if the section is missing. Use self.sections.get('comment', {}) to avoid this.

@rhatdan rhatdan force-pushed the llama-stack branch 2 times, most recently from 934f9fb to 22e488e Compare June 2, 2025 09:42
@rhatdan
Copy link
Member Author

rhatdan commented Jun 3, 2025

@ericcurtin PTAL

@bmahabirbu
Copy link
Collaborator

Looks good to me but the serve.bats file spacing seems to have changed

@rhatdan rhatdan merged commit 6d7cfa8 into containers:main Jun 3, 2025
15 checks passed
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.

2 participants