How can I make `kubeconfig` optional for the kuber...
# πŸ€–ο½œask-kapa
f
@microscopic-river-74022 How can I make
kubeconfig
optional for the kubernetes provider with garden 0.14? When I set it to
kubeconfig: ${var.kubeconfig || null}
I get the following error:
Copy code
βœ– providers                 β†’ Failed processing resolve provider kubernetes (took 0.15 sec). This is what happened:

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Error validating provider configuration:

kubeconfig must be a string
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
βœ” pulumi                    β†’ Provider is ready
Failed resolving one or more providers:
- kubernetes
m
Please stand by @fresh-angle-76971 as I search the knowledge base. I normally take about 15 seconds or so. :wave:
---------------------- To make the
kubeconfig
field optional for the Kubernetes provider in Garden, you should use the optional template syntax by appending a
?
to the template string, like this:
Copy code
yaml
providers:
  - name: kubernetes
    kubeconfig: ${var.kubeconfig}?
This syntax tells Garden to only set the value if
var.kubeconfig
is defined; otherwise, it will omit the field, allowing Garden to fall back to the default behavior. This avoids the error you encountered (
kubeconfig must be a string
), which happens when you explicitly set the value to
null
instead of omitting it entirely. This approach is documented for Garden 0.14 and earlier versions, and is the recommended way to make provider fields optional in your configurationΒ [Features > Variables and Templating > Optional values](). Note: The logical OR fallback (
${var.kubeconfig || null}
) is not appropriate for this use case, because the field expects a string or to be omitted, not
null
. The
?
syntax is specifically designed for this scenario. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
message has been deleted
f
@microscopic-river-74022 The ? syntax does not work with 0.14:
m
Let me check the knowledge base for you again. One moment! :books:
---------------------- You are correct: in Garden 0.14, the optional template expression syntax using the
?
(e.g.,
${var.kubeconfig}?
) has been removed. The recommended approach is to use explicit fallback values with the logical OR operator, such as
${var.kubeconfig || null}
. However, as you observed, setting
kubeconfig: ${var.kubeconfig || null}
results in an error because the field expects a string, not
null
Β [Bonsai-0.13 Deprecations](). The knowledge sources do not provide a direct solution for making
kubeconfig
optional in Garden 0.14 when the variable is not set, without causing a type error. The documentation only states that the
?
syntax is deprecated and that you should use explicit fallback values, but in this case, using
null
as a fallback is not accepted by the provider configuration validation. Summary: There is no documented way in the provided sources to make
kubeconfig
optional in Garden 0.14 if the variable is not set, without causing a validation error. The removal of the
?
syntax and the type requirement for
kubeconfig
(must be a string) create a gap that is not addressed in the current documentationΒ [Bonsai-0.13 Deprecations](). If you need a workaround, you may need to ensure that
var.kubeconfig
is always set to a valid string or restructure your configuration logic outside of Garden, but the knowledge sources do not provide a built-in solution for this scenario in 0.14. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
message has been deleted
f
@microscopic-river-74022 can I somehow override the provider's
kubeconfig
field from a Helm
Deploy
action?
m
Let me check the knowledge base for you again. One moment! :books:
---------------------- I'm sorry, but the knowledge sources do not contain any information about overriding the provider's
kubeconfig
field from within a Helm
Deploy
action. The
kubeconfig
field is documented as a configuration key for the Kubernetes provider itself, not for individual actions like Helm deploys. There is no mention of per-action overrides for this field in the provided documentationΒ [Reference > Providers > kubernetes > Configuration Keys](). Based on the available documentation, it appears that
kubeconfig
must be set at the provider level and cannot be overridden from a Helm
Deploy
action. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
message has been deleted
f
For anyone else looking: you can set it to use
KUBECONFIG
env var if it only points to a single file:
kubeconfig: ${var.kubeconfig || local.env.KUBECONFIG}