Skip to content

[cozy-lib] Fix: handling resources=nil - #1607

Merged
Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
cozy-lib-nil-resources
Nov 7, 2025
Merged

[cozy-lib] Fix: handling resources=nil#1607
Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
cozy-lib-nil-resources

Conversation

@kvaps

@kvaps Andrei Kvapil (kvaps) commented Nov 6, 2025

Copy link
Copy Markdown
Member

Signed-off-by: Andrei Kvapil kvapss@gmail.com

What this PR does

Fixes issue:

error: template: tcp-balancer/templates/deployment.yaml:37:23: executing "tcp-balancer/templates/deployment.yaml" at <include "cozy-lib.resources.defaultingSanitize" (list .Values.resourcesP
reset .Values.resources $)>: error calling include: template: tcp-balancer/charts/cozy-lib/templates/_resources.tpl:157:20: executing "cozy-lib.resources.defaultingSanitize" at <deepCopy $re
sources>: error calling deepCopy: reflect: call of reflect.Value.Type on zero Value

Release note

[cozy-lib] Fix: handling resources=nil

Summary by CodeRabbit

  • Bug Fixes
    • Ensured resource merging behaves predictably when resources are missing by introducing a guarded default, improving reliability and preventing errors during resource composition.

@dosubot dosubot Bot added the size/XS This PR changes 0-9 lines, ignoring generated files label Nov 6, 2025
@coderabbitai

coderabbitai Bot commented Nov 6, 2025

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

Changed resource merging in packages/library/cozy-lib/templates/_resources.tpl to compute mergedMap from a guarded default: deepCopy({}) | mergeOverwrite(presetMap) when resources is missing, ensuring a well-defined merged map in both sanitize and defaulting paths. No public signatures changed.

Changes

Cohort / File(s) Summary
Resource Merge Guarding
packages/library/cozy-lib/templates/_resources.tpl
Use a guarded default for merged resources: compute mergedMap from `deepCopy(resources)

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Template as _resources.tpl
    participant Merge as Merge Logic

    Caller->>Template: invoke resource processing
    alt resources present
        Template->>Merge: deepCopy(resources)
        Merge->>Merge: mergeOverwrite(presetMap)
        Merge-->>Template: mergedMap (from resources+presets)
    else resources absent
        Template->>Merge: deepCopy({})
        Merge->>Merge: mergeOverwrite(presetMap)
        Merge-->>Template: mergedMap (from presets only)
    end
    Template-->>Caller: sanitized resources
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Single-file change with a small, defensive conditional.
  • Verify templating syntax correctness and that the empty-dict default behaves as intended in both sanitize and defaulting flows.
  • Check downstream consumers for assumptions about presence/shape of mergedMap.

Suggested reviewers

  • klinch0

🐰 A gentle hop through template art,
guards stitched in place, a safer start.
If resources skip their cue,
presets step in to carry through.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title '[cozy-lib] Fix: handling resources=nil' clearly and specifically identifies the main change: fixing handling of nil resources in the cozy-lib library.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

📜 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 f2a17cb and 00328c8.

📒 Files selected for processing (1)
  • packages/library/cozy-lib/templates/_resources.tpl (1 hunks)

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@kvaps Andrei Kvapil (kvaps) added the backport Should change be backported on previous release label Nov 6, 2025
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello Andrei Kvapil (@kvaps), 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 addresses a specific bug within the cozy-lib library related to resource management templates. It implements a crucial check to ensure that resource maps are correctly processed even when the input resources parameter is not provided, thereby enhancing the stability and reliability of resource configuration within the system.

Highlights

  • Resource Handling Fix: The pull request introduces a fix to correctly handle scenarios where the resources variable passed to the _resources.tpl template is nil, preventing potential errors during resource map merging.
  • Robust Template Logic: A conditional check has been added to ensure that the $mergedMap is properly initialized with $presetMap when $resources is nil, making the template more robust.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment Gemini (@gemini-code-assist) Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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 (@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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot Bot added the kind/bug Categorizes issue or PR as related to a bug label Nov 6, 2025

@gemini-code-assist gemini-code-assist 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.

Code Review

The pull request effectively addresses the issue of handling nil resources in the cozy-lib.resources.defaultingSanitize template. By explicitly checking if $resources is nil before attempting to deepCopy and mergeOverwrite, the change prevents potential errors and ensures that the $presetMap is correctly used as the base when no specific resources are provided. This is a good and necessary fix for robustness.

Comment thread packages/library/cozy-lib/templates/_resources.tpl Outdated
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Co-authored-by: Timofei Larkin <lllamnyp@gmail.com>
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Nov 7, 2025
@kvaps
Andrei Kvapil (kvaps) merged commit a64ba18 into main Nov 7, 2025
5 of 6 checks passed
@kvaps
Andrei Kvapil (kvaps) deleted the cozy-lib-nil-resources branch November 7, 2025 10:03
@github-actions

github-actions Bot commented Nov 7, 2025

Copy link
Copy Markdown

Successfully created backport PR for release-0.37:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Should change be backported on previous release kind/bug Categorizes issue or PR as related to a bug lgtm This PR has been approved by a maintainer size/XS This PR changes 0-9 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants