default values for external variables

647 views
Skip to first unread message

Yugui

unread,
Sep 10, 2015, 9:04:40 PM9/10/15
to Jsonnet
Sometimes I want to define a default value of an external variable.
However, std.extVar returns an error if it is not given and there looks to be no way to recover from the error.
Is there any way to give default values to external variables and let the variables fallback to the default values when no explicit value given?

If I can define a value which is optionally configurable by end-user, it would be useful to write something like configurations for kubernetes.
e.g. I can define a default number of replicated pods in kubernetes but also keep it configurable from command line without modifying .jsonnet file.

Dave Cunningham

unread,
Sep 10, 2015, 9:37:42 PM9/10/15
to Yugui, Jsonnet
What I'm worried about is the potential for configs to silently fail if external variables are not specified (or typo-d).  Currently this cannot happen because if the evaluation of the config depends on an ext var that is not given, it will always halt execution.  So that is a cue that you have forgotten to specify it.  Having default values would break that behavior by silently using the default value, which may cause very subtle problems in the thing being configured.

Have you considered extending the jsonnet file with another one that overrides the number of replicated pods?  This works pretty well for specifying the differences between dev / prod environments for example.  You can use a hidden field $.foo in the master copy and then override foo in the jsonnet file that imports and extends it.  If you want it to have a default, you define it with a value in the master copy.  If you want to force people to specify then use error "You must specify foo" as the default value.

I don't use external variables that much as it's nice to have a "closed" config and not have to search in my bash history to find the right invocation :)

--
You received this message because you are subscribed to the Google Groups "Jsonnet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonnet+u...@googlegroups.com.
To post to this group, send email to jso...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsonnet/CAB%3DrkjyqEuFo_grdJLHg1pGOXCEGsNK%3DXqSvXH%2BZ%3DBVcag_mQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages