kube: standardize on a `local top = self` convention
A convention is introduced to specify `local top = self` declaration at the top of an app/service/component's jsonnet, representing the top-level object. Reasoning is as following:
- `top` is more universal/unambiguous than `app`
- `top` is usually shorter than $NAME
- a conventional `top` instead of $NAME (coupled with other conventions introduced) makes app jsonnets wonderfully copy-paste'able, aiding in learning and quickly building
Change-Id: I7ece83ce7e97021ad98a6abb3500fb9839936811
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1805
Reviewed-by: q3k <q3k@hackerspace.pl>
diff --git a/app/matrix/lib/media-repo.libsonnet b/app/matrix/lib/media-repo.libsonnet
index 275be24..0c61094 100644
--- a/app/matrix/lib/media-repo.libsonnet
+++ b/app/matrix/lib/media-repo.libsonnet
@@ -1,8 +1,8 @@
local kube = import "../../../kube/kube.libsonnet";
{
- local app = self,
- local cfg = app.cfg,
+ local top = self,
+ local cfg = top.cfg,
cfg:: {
image: error "cfg.image needs to be set",
@@ -27,7 +27,7 @@
},
ns:: error "ns needs to be a kube.Namespace object",
- local ns = app.ns,
+ local ns = top.ns,
config:: {
repo: {
@@ -63,7 +63,7 @@
configSecret: ns.Contain(kube.Secret("media-repo-config")) {
data_: {
- "config.yaml": std.manifestJsonEx(app.config, ""),
+ "config.yaml": std.manifestJsonEx(top.config, ""),
},
},
@@ -73,7 +73,7 @@
template+: {
spec+: {
volumes_: {
- config: kube.SecretVolume(app.configSecret),
+ config: kube.SecretVolume(top.configSecret),
tempdir: kube.EmptyDirVolume(),
},
containers_: {
@@ -144,7 +144,7 @@
"/app/matrix/media-repo-proxy",
"-downstream_host", downstreamHost,
"-upstream_host", upstreamHost,
- "-upstream", app.internalSvc.host_colon_port,
+ "-upstream", top.internalSvc.host_colon_port,
"-listen", ":8080",
],
ports_: {
@@ -159,10 +159,10 @@
} else {},
internalSvc: ns.Contain(kube.Service("media-repo-internal")) {
- target:: app.deployment,
+ target:: top.deployment,
},
svc: if std.length(needProxying) > 0 then ns.Contain(kube.Service("media-repo")) {
- target:: app.proxies.deployment,
- } else app.internalSvc,
+ target:: top.proxies.deployment,
+ } else top.internalSvc,
}