Skip to content
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

feat: Vendir schema support #427

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

feat: Vendir schema support #427

wants to merge 4 commits into from

Conversation

kbudde
Copy link
Member

@kbudde kbudde commented Mar 15, 2025

Adds prototypes/_vendir to the search list for rendering the vendir config for prototypes.
This allows adding a schema and a default generator.

Additionally I updated the default example and assets to show how this feature can be used.

It's an opt in feature. The old way, with base and data in prototype/vendir still works.

Summary by CodeRabbit

  • New Features

    • Introduced an enhanced configuration approach that supports managing multiple prototypes, including those sourced from Git repositories and Helm charts.
    • Added schema validations to ensure configurations meet defined requirements.
  • Bug Fixes

    • Removed outdated configuration files and options for a streamlined setup.
  • Refactor

    • Transitioned from a singular application configuration to a flexible, multi-prototype structure.

Copy link

coderabbitai bot commented Mar 15, 2025

Walkthrough

New YAML configuration and schema files introduce a flexible, prototype-based approach for vendir dependency management. The changes restructure configurations from a singular application definition to an array of prototypes with detailed validations and attributes. A new helper function, pathForKind, has been added to dynamically generate directory paths based on resource type. Several legacy vendir configuration files have been removed, and the Go sync logic is updated to conditionally include a specific directory in the vendir rendering process.

Changes

File(s) Change Summary
examples/default/prototypes/_vendir/base.ytt.yaml
internal/myks/assets/prototypes/_vendir/base.ytt.yaml
Added new vendir configuration files that define a Config resource with a helper function pathForKind for dynamically generating directory paths and conditionally including Git/Helm configurations.
examples/default/prototypes/_vendir/data-schema.ytt.yaml
internal/myks/assets/prototypes/_vendir/data-schema.ytt.yaml
Introduced new YAML schemas for defining prototype structures with fields (name, kind, repo, url, lazy, version, newRootPath, includePaths) and associated validations.
examples/default/prototypes/argocd/vendir/base.ytt.yaml
examples/default/prototypes/goldpinger/vendir/base.yaml
examples/default/prototypes/httpbingo/vendir/base.ytt.yaml
internal/myks/assets/prototypes/argocd/vendir/base.ytt.yaml
internal/myks/assets/prototypes/httpbingo/vendir/base.ytt.yaml
Removed legacy vendir base configuration files that defined singular application configurations for various prototypes.
examples/default/prototypes/argocd/vendir/vendir-data.ytt.yaml
examples/default/prototypes/goldpinger/vendir/vendir-data.ytt.yaml
examples/default/prototypes/httpbingo/vendir/vendir-data.ytt.yaml
internal/myks/assets/prototypes/argocd/vendir/vendir-data.ytt.yaml
internal/myks/assets/prototypes/httpbingo/vendir/vendir-data.ytt.yaml
Restructured the data schema from an application key to a prototypes array, thereby supporting multiple prototype definitions with enriched attributes.
internal/myks/sync_vendir.go Updated the renderVendirConfig method to define a baseDir based on the prototypes directory, checking its existence and appending it to the list of YTT files if present.

Sequence Diagram(s)

sequenceDiagram
    participant S as Syncer
    participant FS as FileSystem
    participant YTT as YTTFiles Collector
    
    S->>FS: Check if baseDir exists (PrototypesDir/_vendir)
    FS-->>S: Return existence status or error
    alt baseDir exists
        S->>YTT: Append baseDir to YTT files list
    else Error
        S->>S: Return error
    end
Loading
sequenceDiagram
    participant Caller as Template Processor
    participant PF as pathForKind Function
    participant Data as Prototype Data Source
    
    Caller->>PF: Invoke pathForKind(kind, name)
    alt kind equals "helm"
        PF-->>Caller: Return helm-specific path
    else 
        PF-->>Caller: Return generic path based on name
    end
Loading

Poem

I'm a bunny with a coding flair,
Hopping through YAML with a joyful air.
New paths grow like carrots in rows,
Prototypes lined up as the configuration flows.
With each leap, my code dances bright,
Celebrating changes day and night!
🐰💻 Hop on, and let the codes unite!

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 747695a and 783232e.

📒 Files selected for processing (4)
  • examples/default/prototypes/_vendir/base.ytt.yaml (1 hunks)
  • examples/default/prototypes/_vendir/data-schema.ytt.yaml (1 hunks)
  • internal/myks/assets/prototypes/_vendir/base.ytt.yaml (1 hunks)
  • internal/myks/assets/prototypes/_vendir/data-schema.ytt.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • examples/default/prototypes/_vendir/base.ytt.yaml
  • internal/myks/assets/prototypes/_vendir/base.ytt.yaml
  • internal/myks/assets/prototypes/_vendir/data-schema.ytt.yaml
  • examples/default/prototypes/_vendir/data-schema.ytt.yaml
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test / test
  • GitHub Check: Analyze (go)

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (7)
examples/default/prototypes/_vendir/base.ytt.yaml (1)

11-35: Flexible vendir configuration template with minor formatting issues

The template effectively iterates through prototypes and generates appropriate vendir configurations based on repository type. The conditional inclusion of fields like lazy, newRootPath, and includePaths provides good flexibility.

Two minor formatting issues to fix:

  1. Line 19: Indentation - adjust from 4 spaces to 2 spaces for better YAML consistency
  2. Line 35: Add a newline character at the end of file
   contents:
-    - path: .
+  - path: .
     #@ if/end src.repo == "git":

And add a newline at the end of the file.

🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 19-19: wrong indentation: expected 2 but found 4

(indentation)


[error] 35-35: no new line character at the end of file

(new-line-at-end-of-file)

internal/myks/assets/prototypes/_vendir/base.ytt.yaml (2)

19-19: YAML indentation warning from YAMLlint.
YAMLlint reports a wrong indentation at this line: expected 2 spaces but found 4. Please verify and adjust the indentation for the list item under contents to ensure that the rendered YAML conforms to YAML standards.

🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 19-19: wrong indentation: expected 2 but found 4

(indentation)


35-35: Missing newline at the end of file.
Please add a newline at the end of the file to adhere to YAML best practices and avoid tooling warnings.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 35-35: no new line character at the end of file

(new-line-at-end-of-file)

internal/myks/assets/prototypes/_vendir/data-schema.ytt.yaml (1)

11-12: Typographical error in schema title.
The schema title "Protoytpe kind" appears to be misspelled. It should be corrected to "Prototype kind" to maintain clarity and professionalism in the documentation.

examples/default/prototypes/_vendir/data-schema.ytt.yaml (3)

6-10: Prototypes List and Name Field:
The key prototypes is appropriately established as a list container for vendored applications. The name field includes a minimum-length validation (min_len=1), ensuring each entry will have a meaningful identifier. Consider providing a sample default value (or an example comment) to guide users, though leaving it blank may be intentional for user input.


11-14: Typographical Correction in Kind Field:
The title on line 11 contains a typographical error ("Protoytpe kind"). Please update it to "Prototype kind" for clarity and professionalism.


26-29: Version Field Requirements:
The version field includes a validation to enforce a non-empty string. Consider including a sample version (for example, "1.0.0") in the documentation or in a comment to guide users on the expected format.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between af69318 and 747695a.

📒 Files selected for processing (15)
  • examples/default/prototypes/_vendir/base.ytt.yaml (1 hunks)
  • examples/default/prototypes/_vendir/data-schema.ytt.yaml (1 hunks)
  • examples/default/prototypes/argocd/vendir/base.ytt.yaml (0 hunks)
  • examples/default/prototypes/argocd/vendir/vendir-data.ytt.yaml (1 hunks)
  • examples/default/prototypes/goldpinger/vendir/base.yaml (0 hunks)
  • examples/default/prototypes/goldpinger/vendir/vendir-data.ytt.yaml (1 hunks)
  • examples/default/prototypes/httpbingo/vendir/base.ytt.yaml (0 hunks)
  • examples/default/prototypes/httpbingo/vendir/vendir-data.ytt.yaml (1 hunks)
  • internal/myks/assets/prototypes/_vendir/base.ytt.yaml (1 hunks)
  • internal/myks/assets/prototypes/_vendir/data-schema.ytt.yaml (1 hunks)
  • internal/myks/assets/prototypes/argocd/vendir/base.ytt.yaml (0 hunks)
  • internal/myks/assets/prototypes/argocd/vendir/vendir-data.ytt.yaml (1 hunks)
  • internal/myks/assets/prototypes/httpbingo/vendir/base.ytt.yaml (0 hunks)
  • internal/myks/assets/prototypes/httpbingo/vendir/vendir-data.ytt.yaml (1 hunks)
  • internal/myks/sync_vendir.go (1 hunks)
💤 Files with no reviewable changes (5)
  • internal/myks/assets/prototypes/argocd/vendir/base.ytt.yaml
  • examples/default/prototypes/goldpinger/vendir/base.yaml
  • internal/myks/assets/prototypes/httpbingo/vendir/base.ytt.yaml
  • examples/default/prototypes/httpbingo/vendir/base.ytt.yaml
  • examples/default/prototypes/argocd/vendir/base.ytt.yaml
🧰 Additional context used
🪛 YAMLlint (1.35.1)
examples/default/prototypes/_vendir/base.ytt.yaml

[warning] 19-19: wrong indentation: expected 2 but found 4

(indentation)


[error] 35-35: no new line character at the end of file

(new-line-at-end-of-file)

internal/myks/assets/prototypes/_vendir/base.ytt.yaml

[warning] 19-19: wrong indentation: expected 2 but found 4

(indentation)


[error] 35-35: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (16)
internal/myks/sync_vendir.go (1)

64-69: LGTM: Properly implemented directory search for _vendir

The implementation correctly adds the new _vendir directory to the vendir configuration search path, aligning with the PR's objective. The code follows good practices by:

  1. Checking for directory existence with proper error handling
  2. Following the established pattern of building the yttFiles slice
internal/myks/assets/prototypes/httpbingo/vendir/vendir-data.ytt.yaml (1)

1-9: Schema structure updated to use prototypes array

The change from an application object to a prototypes array correctly implements the new schema structure, providing better support for multiple prototype configurations.

examples/default/prototypes/_vendir/base.ytt.yaml (1)

3-9: Well-designed helper function for path generation

The pathForKind function elegantly determines the appropriate path based on the resource kind, which simplifies the configuration structure and improves maintainability.

examples/default/prototypes/httpbingo/vendir/vendir-data.ytt.yaml (1)

1-9: Schema structure updated to match new prototypes array format

The change from an application object to a prototypes array correctly implements the new schema structure, providing consistency with the other configuration files in this PR.

internal/myks/assets/prototypes/_vendir/base.ytt.yaml (2)

3-9: Clear implementation of pathForKind function.
The function cleanly distinguishes between helm resources (which are routed under "charts/") and other resource types. The logic is straightforward and easy to follow.


16-20: Dynamic directory generation with conditional resource blocks.
The loop correctly iterates over protos and generates directory entries, conditionally including Git or Helm chart configurations based on the value of src.repo. Please verify that the inline conditional syntax (#@ if/end ...) renders as expected in ytt.

🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 19-19: wrong indentation: expected 2 but found 4

(indentation)

internal/myks/assets/prototypes/argocd/vendir/vendir-data.ytt.yaml (1)

1-11: Argo CD prototype configuration is well-structured.
The new structure under prototypes correctly defines all required attributes (name, kind, repo, URL, version, includePaths, newRootPath) for the Argo CD vendir configuration. This update aligns with the enhanced vendir schema design.

internal/myks/assets/prototypes/_vendir/data-schema.ytt.yaml (1)

1-37: Comprehensive vendir application schema defined.
The schema thoroughly validates and documents each field required for vendored applications. This detailed specification (including validations such as min_len and one_of constraints) will help enforce consistency across configurations.

examples/default/prototypes/argocd/vendir/vendir-data.ytt.yaml (1)

1-11: Argo CD vendir data configuration updated successfully.
The file now leverages the new #@data/values declaration with the prototypes key, reflecting the intended restructuring. All required prototype attributes are present and correctly defined.

examples/default/prototypes/goldpinger/vendir/vendir-data.ytt.yaml (1)

1-16: Goldpinger vendir data configuration is updated and well-organized.
The configuration now supports multiple prototypes. The first prototype (goldpinger) is defined with helm and helmChart settings, while the newly introduced prototype (grafana-dashboards) follows a ytt configuration pattern. This modular structure aligns perfectly with the PR objectives of supporting a flexible vendir schema.

examples/default/prototypes/_vendir/data-schema.ytt.yaml (6)

1-5: Schema Metadata and Overlay Definition:
The metadata annotations (e.g., #@data/values-schema, title, and description) along with the overlay setting are correctly defined. They clearly document the purpose of the file and set the foundation for schema validation.


15-18: Repository Type Field Definition:
The repo field is well-defined with clear validation restricting the value to either "git" or "helmChart". The description effectively explains its purpose.


19-22: URL Field Validation:
The url field is mandated to be a non-empty string, with a proper description covering both git repositories and helm charts. This clear validation ensures that every entry will contain a valid source URL.


23-25: Lazy Vendoring Field:
The boolean field lazy is correctly configured with a default value of true, aligning with the intention of on-demand vendoring.


30-32: New Root Path Specification:
The newRootPath field is clearly described and correctly positioned for defining the root directory within a git repository. The empty string default is acceptable if the field is meant to be user-configurable.


33-36: Include Paths Field Setup:
The includePaths field is implemented as a list with a default entry of includes.yaml. This setup ensures that the necessary include file is referenced by default, which aligns with the intended vendir configuration.

@kbudde kbudde changed the title Vendir schema support feat: Vendir schema support Mar 16, 2025
Copy link
Member

@Zebradil Zebradil left a comment

Choose a reason for hiding this comment

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

Very nice!

I was thinking about something like this for my big project just last week. I thought to implement a library function and some simplified schema for vendir sources in the envs/env-data.vendir.yaml or similar.

I like your approach more. However, I think we should change the schema a little bit. Since #422, vendir is invoked with the main ytt schema (giving you access to the current environment and application data values), so the schema in _vendir should extend the main one.

Here is one option:

#! This configuration is applied to the current prototype
#! and can be set in any data/values file.
prototype:
  #! Nest sources under the vendir key to be able to add
  #! more vendir configuration in the future. (questionable)
  vendir:
    sources:
      - #! source definition

This looks a little too nested. Here is another option:

prototype:
  sources:
    - #! source definition
  vendir: {} #! if we need to configure vendir at some point, can be omitted for now.

The prototype key can be also shortened to just proto.

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