Skip to content

Conversation

mkyc
Copy link

@mkyc mkyc commented Apr 30, 2025

Description

as much as I like PR #212 I think it doesn't solve more general problem which is "there is so many options people need to provide secrets".

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev - nope, I do not see anything about helm charts there
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected - I didn't. I believe simple container verifying that there is some secret present when I add secret, tests kubernetes, not this helm chart. Saying that I did manually executed helm template -n test-01 openfga . with example configuration uncommented and I got expected result:
---
# Source: openfga/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
...
            - name: OPENFGA_METRICS_ADDR
              value: "0.0.0.0:2112"
            - name: OPENFGA_DATASTORE_USERNAME
              valueFrom:
                configMapKeyRef:
                  name: openfga-openfga
                  key: username
            - name: OPENFGA_DATASTORE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: openfga-openfga
                  key: password
            - name: OPENFGA_DATASTORE_URI
              value: "postgresql://openfga-openfga-postgresql:5432/openfga?sslmode=disable"
            - name: OPENFGA_LOG_LEVEL
              value: "debug"
            
          readinessProbe:
...

Summary by CodeRabbit

  • New Features

    • Added support for specifying additional environment variables using a new configuration option.
    • Users can now define extra environment variables with Helm templating for both the main application and database migration containers.
  • Documentation

    • Included example configurations for adding environment variables via the new option in the values file.

@mkyc mkyc requested review from a team as code owners April 30, 2025 17:53
Copy link

linux-foundation-easycla bot commented Apr 30, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: mkyc / name: Mateusz Kyc (bd1049c)

Copy link
Contributor

@jeremy-albuixech jeremy-albuixech left a comment

Choose a reason for hiding this comment

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

I believe this serves the same purpose as the extraEnvVars property no?

For the other PR mentioned, the benefit is mostly around a secret value being kept hidden from the users, which is a good practice.

I am personally not a fan of the extra<Thing> properties as they tend to potentially abstract too many variables away, I'd rather have something properly defined in the schema to reduce the chances of users errors.

If you have some specific use case that makes this a good addition to the extraEnvVars could you add it to the description so that we can take it into account?

For instance if you are blocked on a deployment because you're missing something that this would fix, maybe we can figure out if this is indeed needed or if we have another way to accomplish it?

@mkyc
Copy link
Author

mkyc commented May 16, 2025

I believe this serves the same purpose as the extraEnvVars property no?

Yes, but extraEnvVars don't use tpl so it's just for plaintext things. I don't mind my PR being closed but extraEnvVars should support more options. I didn't want to change extraEnvVars because I believe that would be breaking change and that has to be introduced with care, and I do not have time for it 😉

For the other PR mentioned, the benefit is mostly around a secret value being kept hidden from the users, which is a good practice.

I need exactly what other PR provides: OPENFGA_AUTHN_PRESHARED_KEYS from external secret, so as long as #212 is merged and released I'm happy. I've noticed it's all green there so I hope it's released soon 👍

@mkyc
Copy link
Author

mkyc commented Jul 16, 2025

BTW, I still believe this PR is better solution. This PR uses:

{{- tpl . $ | nindent 12 }}

while extraEnvVars uses:

{{- toYaml . | nindent 12 }}

difference is that with extraEnvVars I cannot do what is possible with extraEnv:

extraEnv: |
   - name: OPENFGA_AUTHN_PRESHARED_KEYS
     valueFrom:
       secretKeyRef:
         name: {{ .Release.Name }}-authn
         key: preshared_keys

currently with #212 merged I'm forced to use keys (as defined here which is possible, but is not very flexible.

@mkyc mkyc force-pushed the elastic-env-var-provisioning branch from 013cd83 to bd1049c Compare July 16, 2025 12:19
Copy link

coderabbitai bot commented Jul 16, 2025

Walkthrough

The changes introduce a new extraEnv configuration option to the OpenFGA Helm chart, allowing users to inject additional environment variables into both the main application container and the migrate-database init container. This is implemented using Helm's templating capabilities, and corresponding schema and documentation updates were made.

Changes

File(s) Change Summary
charts/openfga/templates/deployment.yaml Added support for injecting environment variables via extraEnv using Helm tpl templating in both the main and init containers.
charts/openfga/values.schema.json Added the extraEnv property to the schema, allowing templated environment variables as a string.
charts/openfga/values.yaml Introduced the extraEnv configuration with documentation and commented examples.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Helm
    participant Kubernetes
    participant OpenFGA Deployment

    User->>Helm: Set extraEnv in values.yaml
    Helm->>Helm: Process deployment.yaml template with tpl(extraEnv)
    Helm->>Kubernetes: Deploy OpenFGA with extra environment variables
    Kubernetes->>OpenFGA Deployment: Start containers with injected env vars
Loading

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.

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: 1

🧹 Nitpick comments (2)
charts/openfga/values.yaml (1)

372-389: Clarify & harden the new extraEnv interface

extraEnv is defined as a free-form string that is tpl-rendered and inlined verbatim. While flexible, it:

  1. Places the burden of producing valid YAML (correct indentation, list syntax, etc.) on end-users—one malformed space will break the render.
  2. Can silently create duplicate name: keys when combined with extraEnvVars, causing the Deployment to be rejected by the Kubernetes API (spec.template.spec.containers[*].env.name: Duplicate value).

Consider one or more of the following refinements:

- extraEnv: ""
+ # extraEnvTpl: ""            # keep the name self-describing
+ # extraEnvVarsTpl: []        # mirror existing array option but evaluated via tpl

or introduce simple validation logic (e.g., a requiredUniqueEnv boolean that errors on duplicates), and highlight these caveats in the chart’s README.

charts/openfga/values.schema.json (1)

1149-1153: Schema could convey “YAML blob” intent

Declaring the field as just type: "string" gives consumers (e.g., editors with JSON-schema support) zero hints about the expected payload.
You can take advantage of the optional contentMediaType to signal that the string holds YAML:

{
  "type": "string",
  "description": "Extra environment variables … (evaluated with Helm tpl)",
  "contentMediaType": "text/x-yaml",
  "default": ""
}

Small win for editor UX; no effect on chart runtime.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1dd8207 and bd1049c.

📒 Files selected for processing (3)
  • charts/openfga/templates/deployment.yaml (2 hunks)
  • charts/openfga/values.schema.json (1 hunks)
  • charts/openfga/values.yaml (1 hunks)

Comment on lines 70 to 76
{{- with .Values.extraEnvVars }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.extraEnv }}
{{- tpl . $ | nindent 12 }}
{{- end }}
resources:
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

extraEnv injection works, but duplicate-name collision is still possible

The two blocks correctly use tpl + nindent, 👍.
However, nothing prevents a user from declaring the same env name in:

  • extraEnvVars
  • extraEnv (init container)
  • extraEnv (main container)

Kubernetes will reject the resulting manifest. A defensive guard can avoid surprising failures:

{{- $seen := dict -}}
{{- range $idx, $env := append .Values.extraEnvVars (tpl .Values.extraEnv $ | fromYaml) }}
{{- if hasKey $seen $env.name }}
{{- fail (printf "duplicate env var '%s' detected in extraEnv/extraEnvVars" $env.name) }}
{{- end }}
{{- $_ := set $seen $env.name true }}
{{- end }}

Even a simple Helm required/fail with hasKey suffices.

Also applies to: 390-393

🤖 Prompt for AI Agents
In charts/openfga/templates/deployment.yaml around lines 70 to 76, there is a
risk of duplicate environment variable names between extraEnvVars and extraEnv
blocks, which causes Kubernetes manifest rejection. To fix this, add a guard
using a dictionary to track seen environment variable names before rendering
them. Iterate over the combined list of extraEnvVars and the parsed extraEnv,
check if a name already exists in the dictionary, and if so, use the fail
function to stop rendering with a clear duplicate name error. Apply the same
duplicate check logic also around lines 390 to 393 where similar environment
variables are injected.

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