3 ms·
yep, mixing lexical and dynamic scope was the hell indeed. A convention I use with jsonnet is to use locals to "anchor" some important objects in the lexical s
by ithkuil 4y ago
yep, mixing lexical and dynamic scope was the hell indeed.
A convention I use with jsonnet is to use locals to "anchor" some important objects in the lexical scope.
My rule is to name the locals with exactly the same name as the field whose object they refer to. Example:
{
deployment: {
local deployment = self,
spec+: {
replicas: 3,
template+: { spec+: {
local spec = self,
containers: [
{
name: 'foo',
env: [
{ name: 'REP', value: std.toString(deployment.spec.replicas) },
{ name: 'SA', value: spec.serviceAccountName },
],
},
],
serviceAccountName: 'foo',
} },
},
},
}
Adding these locals gives the right amount of friction to avoid using this all the time, while at the same time having a predictable naming for the locals. The jsonnet LSP tool can easily resolve that local since it's only a lexical thing