Commit 733a846a authored by Sigmund Augdal's avatar Sigmund Augdal

Don't hardcode namespace and memcache service names

parent 34a38dcf
......@@ -4,4 +4,5 @@ COPY lua /usr/local/share/lua/5.1/
COPY nginx /etc/nginx/
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
ENV memcache=memcache
CMD ["/usr/sbin/nginx"]
#! /bin/sh
export dollar='$'
export namespace="$(cat /run/secrets/kubernetes.io/serviceaccount/namespace)"
cat /etc/nginx/site.conf|envsubst>/etc/nginx/sites-enabled/default
exec "$@"
......@@ -70,6 +70,12 @@ function memcGetMultiple(hosta, hostb, port, key)
return res["attributes"]
end
function memcache_server(index)
local domain = '.' .. ngx.var.namespace .. '.svc.cluster.local'
local memcache_service = ngx.var.memcache
return memcache_service .. '-.' .. memcache_service .. domain
end
function userData()
if not ngx.var.http_cookie then
......@@ -81,7 +87,7 @@ function userData()
return
end
return memcGetMultiple("memcache-0.memcache.scratch.svc.cluster.local", "memcache-1.memcache.scratch.svc.cluster.local", 11211, cookie_value)
return memcGetMultiple(memcache_server(0), memcache_server(1), 11211, cookie_value)
end
function setFeideHeaders(feide_data)
......
......@@ -5,6 +5,8 @@ server {
location / {
proxy_pass http://localhost:${upstream_port};
set ${dollar}feide_mode '${feide_mode}';
set ${dollar}namespace '${namespace}';
set ${dollar}memcache '${memcache}';
rewrite_by_lua_file /usr/local/share/lua/5.1/feide.lua;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment