Why am I getting `Could not find key kubeconfig un...
# 🤖|ask-kapa
f
@microscopic-river-74022 Why am I getting
Could not find key kubeconfig under var
error when running
garden validate
for the following project config?
Copy code
apiVersion: garden.io/v2
kind: Project
name: pulumi
environments:
  - name: init
  - name: dev

providers:
  - name: pulumi
    version: null  # use whatever is in path
    useNewPulumiVarfileSchema: true
  - name: kubernetes
    buildMode: cluster-buildkit
    kubeconfig: ${var.kubeconfig}?  # use $KUBECONFIG if deployment doesn't set this explicitly
It should work according to docs, it's actually the example listed there: https://docs.garden.io/features/variables-and-templating#optional-values
m
Please stand by @fresh-angle-76971 as I search the knowledge base. I normally take about 15 seconds or so. :wave:
---------------------- Your configuration is correct according to the documentation: using
${var.kubeconfig}?
in the
kubeconfig
field should make the value optional, so Garden should not throw an error if the variable is not set. This is explicitly documented and even shown as an example in the official docs:
Copy code
yaml
kind: Project
providers:
  - name: kubernetes
    kubeconfig: ${var.kubeconfig}?
This is useful when you don't want to provide any value unless one is explicitly set, effectively falling back to whichever the default is for the field in question [Features > Variables and Templating > Optional values](). If you are still getting the error
Could not find key kubeconfig under var
when running
garden validate
, this suggests one of the following: - You may be using a version of Garden that does not support the optional template syntax (
?
). Make sure you are using a version that includes this feature, as documented. - There could be a bug or regression in the version you are using. - The error may be coming from a different part of your configuration or a different provider/module that expects
var.kubeconfig
to be set. What you can do: 1. Double-check your Garden version and ensure it matches the documentation you are referencing. 2. Try running with a minimal config (just the example from the docs) to isolate the issue. 3. If the problem persists and you are on a supported version, consider reporting it as a bug, since the documented behavior is that the optional value should not cause a validation error if unset.
The knowledge sources confirm your usage is correct and do not mention any additional requirements or caveats for this feature [Features > Variables and Templating > Optional values](). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
message has been deleted
f
@microscopic-river-74022 I'm running garden 0.14.6. What versions should support that syntax?
m
Let me check the knowledge base for you again. One moment! :books:
---------------------- Based on the knowledge sources, the optional template expression syntax using a question mark (e.g.,
${var.kubeconfig}?
) is being removed in Garden 0.14. The documentation for Garden 0.14 (Cedar) and the deprecation guides state that you should use explicit fallback values instead, such as
${var.kubeconfig || null}
. The
?
syntax is supported in Garden 0.13 (Bonsai) and earlier, but not in 0.14 and later: > The optional template expression syntax will be removed in Garden 0.14. Use explicit fallback values instead, e.g.
${var.foo || null}
 [Bonsai-0.13 > Guides > Deprecations and updating to Cedar > Template Language](). So, since you are running Garden 0.14.6, the
${var.kubeconfig}?
syntax is not supported. You should update your configuration to use the new fallback syntax:
Copy code
yaml
kubeconfig: ${var.kubeconfig || null}
This will ensure compatibility with Garden 0.14 and later. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
message has been deleted
Let me check the knowledge base for you again. One moment! :books:
f
@microscopic-river-74022 the optional syntax is still listed in the edge and latest release docs. Can I contribute to those somehow or report a bug if I can't?
m
---------------------- Yes, you can contribute to the Garden documentation or report issues if you notice inconsistencies like the optional template syntax still being listed in the edge and latest release docs. The documentation explains that contributions are welcome and provides clear steps for making your first contribution. You need to: 1. Clone the Garden GitHub repository. 2. Make your changes in a branch. 3. Commit your changes following the Conventional Commits specification. 4. Run
npm run build
before pushing to update the Table of Contents. 5. Open a pull request and request a review from the maintainers. You can find more details and guidelines in the docs, including how the documentation is structured and where to make changes. If you prefer, you can also report a bug or inconsistency by opening an issue in the Garden GitHub repository [Edge-release > Contributing to the Docs](). For more information on how to contribute or report issues, see the relevant section in the documentation: [How our docs are structured](). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
message has been deleted