Commit 1e4941c4 authored by Geoff Simmons's avatar Geoff Simmons

Use Pod names to generate VCL backend name symbols.

This makes backend names more readily recognizable in VCL sources,
and as used in tools such as varnishlog and varnishstat. If the
Pod ns/name is not available, fall back to the previous scheme of
generating names from the Endpoint network addresses.
parent 0f3933b7
...@@ -6,7 +6,7 @@ client c1 -connect "${localhost} ${localport}" { ...@@ -6,7 +6,7 @@ client c1 -connect "${localhost} ${localport}" {
txreq -url /coffee -hdr "Host: cafe.example.com" txreq -url /coffee -hdr "Host: cafe.example.com"
rxresp rxresp
expect resp.status == 200 expect resp.status == 200
expect resp.http.Backend ~ {^vk8s_default_2f_coffee-svc_\d+_\d+_\d+_\d+$} expect resp.http.Backend ~ {^vk8s_default_coffee-[a-z0-9]+-[a-z0-9]+_80$}
expect resp.http.Hello == "world" expect resp.http.Hello == "world"
expect resp.body ~ "(?m)^Server name: coffee-[a-z0-9]+-[a-z0-9]+$" expect resp.body ~ "(?m)^Server name: coffee-[a-z0-9]+-[a-z0-9]+$"
} -run } -run
...@@ -99,16 +99,22 @@ var teaSvcShuf = Service{ ...@@ -99,16 +99,22 @@ var teaSvcShuf = Service{
Name: "tea-svc", Name: "tea-svc",
Addresses: []Address{ Addresses: []Address{
{ {
IP: "192.0.2.3", PodNamespace: "default",
Port: 80, PodName: "tea-5798f99dc5-5wj8n",
IP: "192.0.2.3",
Port: 80,
}, },
{ {
IP: "192.0.2.1", PodNamespace: "default",
Port: 80, PodName: "tea-5798f99dc5-5wj8n",
IP: "192.0.2.1",
Port: 80,
}, },
{ {
IP: "192.0.2.2", PodNamespace: "default",
Port: 80, PodName: "tea-5798f99dc5-hn27l",
IP: "192.0.2.2",
Port: 80,
}, },
}, },
} }
...@@ -117,12 +123,16 @@ var coffeeSvcShuf = Service{ ...@@ -117,12 +123,16 @@ var coffeeSvcShuf = Service{
Name: "coffee-svc", Name: "coffee-svc",
Addresses: []Address{ Addresses: []Address{
{ {
IP: "192.0.2.5", PodNamespace: "default",
Port: 80, PodName: "coffee-6b9f5c47d7-l5zvl",
IP: "192.0.2.5",
Port: 80,
}, },
{ {
IP: "192.0.2.4", PodNamespace: "default",
Port: 80, PodName: "coffee-6b9f5c47d7-bdt68",
IP: "192.0.2.4",
Port: 80,
}, },
}, },
} }
......
...@@ -37,7 +37,7 @@ probe vk8s_tea-svc_probe { ...@@ -37,7 +37,7 @@ probe vk8s_tea-svc_probe {
.threshold = 3; .threshold = 3;
} }
backend vk8s_coffee-svc_192_0_2_4 { backend vk8s_coffee-svc_192_0_2_4_80 {
.host = "192.0.2.4"; .host = "192.0.2.4";
.port = "80"; .port = "80";
.host_header = "coffee.svc.org"; .host_header = "coffee.svc.org";
...@@ -47,7 +47,7 @@ backend vk8s_coffee-svc_192_0_2_4 { ...@@ -47,7 +47,7 @@ backend vk8s_coffee-svc_192_0_2_4 {
.proxy_header = 2; .proxy_header = 2;
.probe = vk8s_coffee-svc_probe; .probe = vk8s_coffee-svc_probe;
} }
backend vk8s_coffee-svc_192_0_2_5 { backend vk8s_coffee-svc_192_0_2_5_80 {
.host = "192.0.2.5"; .host = "192.0.2.5";
.port = "80"; .port = "80";
.host_header = "coffee.svc.org"; .host_header = "coffee.svc.org";
...@@ -57,21 +57,21 @@ backend vk8s_coffee-svc_192_0_2_5 { ...@@ -57,21 +57,21 @@ backend vk8s_coffee-svc_192_0_2_5 {
.proxy_header = 2; .proxy_header = 2;
.probe = vk8s_coffee-svc_probe; .probe = vk8s_coffee-svc_probe;
} }
backend vk8s_milk-svc_192_0_2_6 { backend vk8s_milk-svc_192_0_2_6_80 {
.host = "192.0.2.6"; .host = "192.0.2.6";
.port = "80"; .port = "80";
.host_header = "milk.svc.org"; .host_header = "milk.svc.org";
.first_byte_timeout = 3s; .first_byte_timeout = 3s;
.probe = vk8s_milk-svc_probe; .probe = vk8s_milk-svc_probe;
} }
backend vk8s_milk-svc_192_0_2_7 { backend vk8s_milk-svc_192_0_2_7_80 {
.host = "192.0.2.7"; .host = "192.0.2.7";
.port = "80"; .port = "80";
.host_header = "milk.svc.org"; .host_header = "milk.svc.org";
.first_byte_timeout = 3s; .first_byte_timeout = 3s;
.probe = vk8s_milk-svc_probe; .probe = vk8s_milk-svc_probe;
} }
backend vk8s_tea-svc_192_0_2_1 { backend vk8s_tea-svc_192_0_2_1_80 {
.host = "192.0.2.1"; .host = "192.0.2.1";
.port = "80"; .port = "80";
.host_header = "tea.svc.org"; .host_header = "tea.svc.org";
...@@ -82,7 +82,7 @@ backend vk8s_tea-svc_192_0_2_1 { ...@@ -82,7 +82,7 @@ backend vk8s_tea-svc_192_0_2_1 {
.max_connections = 200; .max_connections = 200;
.probe = vk8s_tea-svc_probe; .probe = vk8s_tea-svc_probe;
} }
backend vk8s_tea-svc_192_0_2_2 { backend vk8s_tea-svc_192_0_2_2_80 {
.host = "192.0.2.2"; .host = "192.0.2.2";
.port = "80"; .port = "80";
.host_header = "tea.svc.org"; .host_header = "tea.svc.org";
...@@ -93,7 +93,7 @@ backend vk8s_tea-svc_192_0_2_2 { ...@@ -93,7 +93,7 @@ backend vk8s_tea-svc_192_0_2_2 {
.max_connections = 200; .max_connections = 200;
.probe = vk8s_tea-svc_probe; .probe = vk8s_tea-svc_probe;
} }
backend vk8s_tea-svc_192_0_2_3 { backend vk8s_tea-svc_192_0_2_3_80 {
.host = "192.0.2.3"; .host = "192.0.2.3";
.port = "80"; .port = "80";
.host_header = "tea.svc.org"; .host_header = "tea.svc.org";
...@@ -112,25 +112,25 @@ sub vcl_init { ...@@ -112,25 +112,25 @@ sub vcl_init {
vk8s_hosts.compile(); vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.random(); new vk8s_coffee-svc_director = directors.random();
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_4 vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_4_80
, 1.0 , 1.0
); );
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_5 vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_5_80
, 1.0 , 1.0
); );
new vk8s_milk-svc_director = directors.round_robin(); new vk8s_milk-svc_director = directors.round_robin();
vk8s_milk-svc_director.add_backend(vk8s_milk-svc_192_0_2_6 vk8s_milk-svc_director.add_backend(vk8s_milk-svc_192_0_2_6_80
); );
vk8s_milk-svc_director.add_backend(vk8s_milk-svc_192_0_2_7 vk8s_milk-svc_director.add_backend(vk8s_milk-svc_192_0_2_7_80
); );
new vk8s_tea-svc_director = directors.shard(); new vk8s_tea-svc_director = directors.shard();
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_1 vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_1_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_2 vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_2_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_3 vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_3_80
); );
vk8s_tea-svc_director.set_warmup(0.5); vk8s_tea-svc_director.set_warmup(0.5);
vk8s_tea-svc_director.set_rampup(5m); vk8s_tea-svc_director.set_rampup(5m);
......
...@@ -7,23 +7,23 @@ import dynamic; ...@@ -7,23 +7,23 @@ import dynamic;
include "bogo_backend.vcl"; include "bogo_backend.vcl";
backend vk8s_coffee-svc_192_0_2_4 { backend vk8s_default_coffee-6b9f5c47d7-bdt68_80 {
.host = "192.0.2.4"; .host = "192.0.2.4";
.port = "80"; .port = "80";
} }
backend vk8s_coffee-svc_192_0_2_5 { backend vk8s_default_coffee-6b9f5c47d7-l5zvl_80 {
.host = "192.0.2.5"; .host = "192.0.2.5";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_1 { backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
.host = "192.0.2.1"; .host = "192.0.2.1";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_2 { backend vk8s_default_tea-5798f99dc5-hn27l_80 {
.host = "192.0.2.2"; .host = "192.0.2.2";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_3 { backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
.host = "192.0.2.3"; .host = "192.0.2.3";
.port = "80"; .port = "80";
} }
...@@ -35,17 +35,17 @@ sub vcl_init { ...@@ -35,17 +35,17 @@ sub vcl_init {
vk8s_hosts.compile(); vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.round_robin(); new vk8s_coffee-svc_director = directors.round_robin();
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_4 vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-bdt68_80
); );
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_5 vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-l5zvl_80
); );
new vk8s_tea-svc_director = directors.round_robin(); new vk8s_tea-svc_director = directors.round_robin();
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_1 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-5wj8n_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_2 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-hn27l_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_3 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-5wj8n_80
); );
new vk8s_cafe_example_com_url = re2.set(posix_syntax=true, anchor=start); new vk8s_cafe_example_com_url = re2.set(posix_syntax=true, anchor=start);
......
...@@ -7,23 +7,23 @@ import dynamic; ...@@ -7,23 +7,23 @@ import dynamic;
include "bogo_backend.vcl"; include "bogo_backend.vcl";
backend vk8s_coffee-svc_192_0_2_4 { backend vk8s_default_coffee-6b9f5c47d7-bdt68_80 {
.host = "192.0.2.4"; .host = "192.0.2.4";
.port = "80"; .port = "80";
} }
backend vk8s_coffee-svc_192_0_2_5 { backend vk8s_default_coffee-6b9f5c47d7-l5zvl_80 {
.host = "192.0.2.5"; .host = "192.0.2.5";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_1 { backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
.host = "192.0.2.1"; .host = "192.0.2.1";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_2 { backend vk8s_default_tea-5798f99dc5-hn27l_80 {
.host = "192.0.2.2"; .host = "192.0.2.2";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_3 { backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
.host = "192.0.2.3"; .host = "192.0.2.3";
.port = "80"; .port = "80";
} }
...@@ -37,17 +37,17 @@ sub vcl_init { ...@@ -37,17 +37,17 @@ sub vcl_init {
vk8s_hosts.compile(); vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.round_robin(); new vk8s_coffee-svc_director = directors.round_robin();
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_4 vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-bdt68_80
); );
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_5 vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-l5zvl_80
); );
new vk8s_tea-svc_director = directors.round_robin(); new vk8s_tea-svc_director = directors.round_robin();
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_1 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-5wj8n_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_2 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-hn27l_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_3 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-5wj8n_80
); );
new vk8s_vodka-svc_resolver = dynamic.resolver(); new vk8s_vodka-svc_resolver = dynamic.resolver();
......
...@@ -17,7 +17,7 @@ probe vk8s_tea-svc_probe { ...@@ -17,7 +17,7 @@ probe vk8s_tea-svc_probe {
.threshold = 3; .threshold = 3;
} }
backend vk8s_tea-svc_192_0_2_1 { backend vk8s_tea-svc_192_0_2_1_80 {
.host = "192.0.2.1"; .host = "192.0.2.1";
.port = "80"; .port = "80";
.host_header = "tea.svc.org"; .host_header = "tea.svc.org";
...@@ -28,7 +28,7 @@ backend vk8s_tea-svc_192_0_2_1 { ...@@ -28,7 +28,7 @@ backend vk8s_tea-svc_192_0_2_1 {
.max_connections = 200; .max_connections = 200;
.probe = vk8s_tea-svc_probe; .probe = vk8s_tea-svc_probe;
} }
backend vk8s_tea-svc_192_0_2_2 { backend vk8s_tea-svc_192_0_2_2_80 {
.host = "192.0.2.2"; .host = "192.0.2.2";
.port = "80"; .port = "80";
.host_header = "tea.svc.org"; .host_header = "tea.svc.org";
...@@ -39,7 +39,7 @@ backend vk8s_tea-svc_192_0_2_2 { ...@@ -39,7 +39,7 @@ backend vk8s_tea-svc_192_0_2_2 {
.max_connections = 200; .max_connections = 200;
.probe = vk8s_tea-svc_probe; .probe = vk8s_tea-svc_probe;
} }
backend vk8s_tea-svc_192_0_2_3 { backend vk8s_tea-svc_192_0_2_3_80 {
.host = "192.0.2.3"; .host = "192.0.2.3";
.port = "80"; .port = "80";
.host_header = "tea.svc.org"; .host_header = "tea.svc.org";
...@@ -54,11 +54,11 @@ backend vk8s_tea-svc_192_0_2_3 { ...@@ -54,11 +54,11 @@ backend vk8s_tea-svc_192_0_2_3 {
sub vcl_init { sub vcl_init {
new vk8s_tea-svc_director = directors.shard(); new vk8s_tea-svc_director = directors.shard();
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_1 vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_1_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_2 vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_2_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_3 vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_3_80
); );
vk8s_tea-svc_director.set_warmup(0.5); vk8s_tea-svc_director.set_warmup(0.5);
vk8s_tea-svc_director.set_rampup(5m); vk8s_tea-svc_director.set_rampup(5m);
......
...@@ -60,7 +60,7 @@ probe vk8s_tequila-svc_probe { ...@@ -60,7 +60,7 @@ probe vk8s_tequila-svc_probe {
.threshold = 3; .threshold = 3;
} }
backend vk8s_coffee-svc_192_0_2_4 { backend vk8s_coffee-svc_192_0_2_4_80 {
.host = "192.0.2.4"; .host = "192.0.2.4";
.port = "80"; .port = "80";
.host_header = "coffee.svc.org"; .host_header = "coffee.svc.org";
...@@ -70,7 +70,7 @@ backend vk8s_coffee-svc_192_0_2_4 { ...@@ -70,7 +70,7 @@ backend vk8s_coffee-svc_192_0_2_4 {
.proxy_header = 2; .proxy_header = 2;
.probe = vk8s_coffee-svc_probe; .probe = vk8s_coffee-svc_probe;
} }
backend vk8s_coffee-svc_192_0_2_5 { backend vk8s_coffee-svc_192_0_2_5_80 {
.host = "192.0.2.5"; .host = "192.0.2.5";
.port = "80"; .port = "80";
.host_header = "coffee.svc.org"; .host_header = "coffee.svc.org";
...@@ -80,21 +80,21 @@ backend vk8s_coffee-svc_192_0_2_5 { ...@@ -80,21 +80,21 @@ backend vk8s_coffee-svc_192_0_2_5 {
.proxy_header = 2; .proxy_header = 2;
.probe = vk8s_coffee-svc_probe; .probe = vk8s_coffee-svc_probe;
} }
backend vk8s_milk-svc_192_0_2_6 { backend vk8s_milk-svc_192_0_2_6_80 {
.host = "192.0.2.6"; .host = "192.0.2.6";
.port = "80"; .port = "80";
.host_header = "milk.svc.org"; .host_header = "milk.svc.org";
.first_byte_timeout = 3s; .first_byte_timeout = 3s;
.probe = vk8s_milk-svc_probe; .probe = vk8s_milk-svc_probe;
} }
backend vk8s_milk-svc_192_0_2_7 { backend vk8s_milk-svc_192_0_2_7_80 {
.host = "192.0.2.7"; .host = "192.0.2.7";
.port = "80"; .port = "80";
.host_header = "milk.svc.org"; .host_header = "milk.svc.org";
.first_byte_timeout = 3s; .first_byte_timeout = 3s;
.probe = vk8s_milk-svc_probe; .probe = vk8s_milk-svc_probe;
} }
backend vk8s_tea-svc_192_0_2_1 { backend vk8s_tea-svc_192_0_2_1_80 {
.host = "192.0.2.1"; .host = "192.0.2.1";
.port = "80"; .port = "80";
.host_header = "tea.svc.org"; .host_header = "tea.svc.org";
...@@ -105,7 +105,7 @@ backend vk8s_tea-svc_192_0_2_1 { ...@@ -105,7 +105,7 @@ backend vk8s_tea-svc_192_0_2_1 {
.max_connections = 200; .max_connections = 200;
.probe = vk8s_tea-svc_probe; .probe = vk8s_tea-svc_probe;
} }
backend vk8s_tea-svc_192_0_2_2 { backend vk8s_tea-svc_192_0_2_2_80 {
.host = "192.0.2.2"; .host = "192.0.2.2";
.port = "80"; .port = "80";
.host_header = "tea.svc.org"; .host_header = "tea.svc.org";
...@@ -116,7 +116,7 @@ backend vk8s_tea-svc_192_0_2_2 { ...@@ -116,7 +116,7 @@ backend vk8s_tea-svc_192_0_2_2 {
.max_connections = 200; .max_connections = 200;
.probe = vk8s_tea-svc_probe; .probe = vk8s_tea-svc_probe;
} }
backend vk8s_tea-svc_192_0_2_3 { backend vk8s_tea-svc_192_0_2_3_80 {
.host = "192.0.2.3"; .host = "192.0.2.3";
.port = "80"; .port = "80";
.host_header = "tea.svc.org"; .host_header = "tea.svc.org";
...@@ -137,25 +137,25 @@ sub vcl_init { ...@@ -137,25 +137,25 @@ sub vcl_init {
vk8s_hosts.compile(); vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.random(); new vk8s_coffee-svc_director = directors.random();
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_4 vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_4_80
, 1.0 , 1.0
); );
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_5 vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_5_80
, 1.0 , 1.0
); );
new vk8s_milk-svc_director = directors.round_robin(); new vk8s_milk-svc_director = directors.round_robin();
vk8s_milk-svc_director.add_backend(vk8s_milk-svc_192_0_2_6 vk8s_milk-svc_director.add_backend(vk8s_milk-svc_192_0_2_6_80
); );
vk8s_milk-svc_director.add_backend(vk8s_milk-svc_192_0_2_7 vk8s_milk-svc_director.add_backend(vk8s_milk-svc_192_0_2_7_80
); );
new vk8s_tea-svc_director = directors.shard(); new vk8s_tea-svc_director = directors.shard();
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_1 vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_1_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_2 vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_2_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_3 vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_3_80
); );
vk8s_tea-svc_director.set_warmup(0.5); vk8s_tea-svc_director.set_warmup(0.5);
vk8s_tea-svc_director.set_rampup(5m); vk8s_tea-svc_director.set_rampup(5m);
......
...@@ -7,23 +7,23 @@ import dynamic; ...@@ -7,23 +7,23 @@ import dynamic;
include "bogo_backend.vcl"; include "bogo_backend.vcl";
backend vk8s_coffee-svc_192_0_2_4 { backend vk8s_default_coffee-6b9f5c47d7-bdt68_80 {
.host = "192.0.2.4"; .host = "192.0.2.4";
.port = "80"; .port = "80";
} }
backend vk8s_coffee-svc_192_0_2_5 { backend vk8s_default_coffee-6b9f5c47d7-l5zvl_80 {
.host = "192.0.2.5"; .host = "192.0.2.5";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_1 { backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
.host = "192.0.2.1"; .host = "192.0.2.1";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_2 { backend vk8s_default_tea-5798f99dc5-hn27l_80 {
.host = "192.0.2.2"; .host = "192.0.2.2";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_3 { backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
.host = "192.0.2.3"; .host = "192.0.2.3";
.port = "80"; .port = "80";
} }
...@@ -36,17 +36,17 @@ sub vcl_init { ...@@ -36,17 +36,17 @@ sub vcl_init {
vk8s_hosts.compile(); vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.round_robin(); new vk8s_coffee-svc_director = directors.round_robin();
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_4 vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-bdt68_80
); );
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_5 vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-l5zvl_80
); );
new vk8s_tea-svc_director = directors.round_robin(); new vk8s_tea-svc_director = directors.round_robin();
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_1 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-5wj8n_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_2 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-hn27l_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_3 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-5wj8n_80
); );
new vk8s_tea_example_com_url = re2.set(posix_syntax=true, anchor=start); new vk8s_tea_example_com_url = re2.set(posix_syntax=true, anchor=start);
......
...@@ -7,23 +7,23 @@ import dynamic; ...@@ -7,23 +7,23 @@ import dynamic;
include "bogo_backend.vcl"; include "bogo_backend.vcl";
backend vk8s_coffee-svc_192_0_2_4 { backend vk8s_default_coffee-6b9f5c47d7-bdt68_80 {
.host = "192.0.2.4"; .host = "192.0.2.4";
.port = "80"; .port = "80";
} }
backend vk8s_coffee-svc_192_0_2_5 { backend vk8s_default_coffee-6b9f5c47d7-l5zvl_80 {
.host = "192.0.2.5"; .host = "192.0.2.5";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_1 { backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
.host = "192.0.2.1"; .host = "192.0.2.1";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_2 { backend vk8s_default_tea-5798f99dc5-hn27l_80 {
.host = "192.0.2.2"; .host = "192.0.2.2";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_3 { backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
.host = "192.0.2.3"; .host = "192.0.2.3";
.port = "80"; .port = "80";
} }
...@@ -35,17 +35,17 @@ sub vcl_init { ...@@ -35,17 +35,17 @@ sub vcl_init {
vk8s_hosts.compile(); vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.round_robin(); new vk8s_coffee-svc_director = directors.round_robin();
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_4 vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-bdt68_80
); );
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_5 vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-l5zvl_80
); );
new vk8s_tea-svc_director = directors.round_robin(); new vk8s_tea-svc_director = directors.round_robin();
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_1 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-5wj8n_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_2 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-hn27l_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_3 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-5wj8n_80
); );
new vk8s_cafe_example_com_url = re2.set(posix_syntax=true, anchor=start); new vk8s_cafe_example_com_url = re2.set(posix_syntax=true, anchor=start);
......
...@@ -7,15 +7,15 @@ import dynamic; ...@@ -7,15 +7,15 @@ import dynamic;
include "bogo_backend.vcl"; include "bogo_backend.vcl";
backend vk8s_tea-svc_192_0_2_1 { backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
.host = "192.0.2.1"; .host = "192.0.2.1";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_2 { backend vk8s_default_tea-5798f99dc5-hn27l_80 {
.host = "192.0.2.2"; .host = "192.0.2.2";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_3 { backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
.host = "192.0.2.3"; .host = "192.0.2.3";
.port = "80"; .port = "80";
} }
...@@ -23,11 +23,11 @@ backend vk8s_tea-svc_192_0_2_3 { ...@@ -23,11 +23,11 @@ backend vk8s_tea-svc_192_0_2_3 {
sub vcl_init { sub vcl_init {
new vk8s_tea-svc_director = directors.round_robin(); new vk8s_tea-svc_director = directors.round_robin();
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_1 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-5wj8n_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_2 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-hn27l_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_3 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-5wj8n_80
); );
} }
......
...@@ -7,35 +7,35 @@ import dynamic; ...@@ -7,35 +7,35 @@ import dynamic;
include "bogo_backend.vcl"; include "bogo_backend.vcl";
backend vk8s_coffee-svc_192_0_2_4 { backend vk8s_default_coffee-6b9f5c47d7-bdt68_80 {
.host = "192.0.2.4"; .host = "192.0.2.4";
.port = "80"; .port = "80";
} }
backend vk8s_coffee-svc_192_0_2_5 { backend vk8s_default_coffee-6b9f5c47d7-l5zvl_80 {
.host = "192.0.2.5"; .host = "192.0.2.5";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_1 { backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
.host = "192.0.2.1"; .host = "192.0.2.1";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_2 { backend vk8s_default_tea-5798f99dc5-hn27l_80 {
.host = "192.0.2.2"; .host = "192.0.2.2";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_3 { backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
.host = "192.0.2.3"; .host = "192.0.2.3";
.port = "80"; .port = "80";
} }
backend vk8s_water-svc_192_0_2_128 { backend vk8s_water-svc_192_0_2_128_8000 {
.host = "192.0.2.128"; .host = "192.0.2.128";
.port = "8000"; .port = "8000";
} }
backend vk8s_water-svc_192_0_2_129 { backend vk8s_water-svc_192_0_2_129_8000 {
.host = "192.0.2.129"; .host = "192.0.2.129";
.port = "8000"; .port = "8000";
} }
backend vk8s_water-svc_192_0_2_130 { backend vk8s_water-svc_192_0_2_130_8000 {
.host = "192.0.2.130"; .host = "192.0.2.130";
.port = "8000"; .port = "8000";
} }
...@@ -49,25 +49,25 @@ sub vcl_init { ...@@ -49,25 +49,25 @@ sub vcl_init {
vk8s_hosts.compile(); vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.round_robin(); new vk8s_coffee-svc_director = directors.round_robin();
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_4 vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-bdt68_80
); );
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_5 vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-l5zvl_80
); );
new vk8s_tea-svc_director = directors.round_robin(); new vk8s_tea-svc_director = directors.round_robin();
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_1 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-5wj8n_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_2 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-hn27l_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_3 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-5wj8n_80
); );
new vk8s_water-svc_director = directors.round_robin(); new vk8s_water-svc_director = directors.round_robin();
vk8s_water-svc_director.add_backend(vk8s_water-svc_192_0_2_128 vk8s_water-svc_director.add_backend(vk8s_water-svc_192_0_2_128_8000
); );
vk8s_water-svc_director.add_backend(vk8s_water-svc_192_0_2_129 vk8s_water-svc_director.add_backend(vk8s_water-svc_192_0_2_129_8000
); );
vk8s_water-svc_director.add_backend(vk8s_water-svc_192_0_2_130 vk8s_water-svc_director.add_backend(vk8s_water-svc_192_0_2_130_8000
); );
new vk8s_tea_example_com_url = re2.set(posix_syntax=true, anchor=start); new vk8s_tea_example_com_url = re2.set(posix_syntax=true, anchor=start);
......
...@@ -7,23 +7,23 @@ import dynamic; ...@@ -7,23 +7,23 @@ import dynamic;
include "bogo_backend.vcl"; include "bogo_backend.vcl";
backend vk8s_coffee-svc_192_0_2_4 { backend vk8s_default_coffee-6b9f5c47d7-bdt68_80 {
.host = "192.0.2.4"; .host = "192.0.2.4";
.port = "80"; .port = "80";
} }
backend vk8s_coffee-svc_192_0_2_5 { backend vk8s_default_coffee-6b9f5c47d7-l5zvl_80 {
.host = "192.0.2.5"; .host = "192.0.2.5";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_1 { backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
.host = "192.0.2.1"; .host = "192.0.2.1";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_2 { backend vk8s_default_tea-5798f99dc5-hn27l_80 {
.host = "192.0.2.2"; .host = "192.0.2.2";
.port = "80"; .port = "80";
} }
backend vk8s_tea-svc_192_0_2_3 { backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
.host = "192.0.2.3"; .host = "192.0.2.3";
.port = "80"; .port = "80";
} }
...@@ -35,17 +35,17 @@ sub vcl_init { ...@@ -35,17 +35,17 @@ sub vcl_init {
vk8s_hosts.compile(); vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.round_robin(); new vk8s_coffee-svc_director = directors.round_robin();
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_4 vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-bdt68_80
); );
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_5 vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-l5zvl_80
); );
new vk8s_tea-svc_director = directors.round_robin(); new vk8s_tea-svc_director = directors.round_robin();
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_1 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-5wj8n_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_2 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-hn27l_80
); );
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_3 vk8s_tea-svc_director.add_backend(vk8s_default_tea-5798f99dc5-5wj8n_80
); );
new vk8s_cafe_example_com_url = re2.set(posix_syntax=true, anchor=start); new vk8s_cafe_example_com_url = re2.set(posix_syntax=true, anchor=start);
......
...@@ -48,16 +48,22 @@ var teaSvc = Service{ ...@@ -48,16 +48,22 @@ var teaSvc = Service{
Name: "tea-svc", Name: "tea-svc",
Addresses: []Address{ Addresses: []Address{
{ {
IP: "192.0.2.1", PodNamespace: "default",
Port: 80, PodName: "tea-5798f99dc5-5wj8n",
IP: "192.0.2.1",
Port: 80,
}, },
{ {
IP: "192.0.2.2", PodNamespace: "default",
Port: 80, PodName: "tea-5798f99dc5-hn27l",
IP: "192.0.2.2",
Port: 80,
}, },
{ {
IP: "192.0.2.3", PodNamespace: "default",
Port: 80, PodName: "tea-5798f99dc5-5wj8n",
IP: "192.0.2.3",
Port: 80,
}, },
}, },
} }
...@@ -66,12 +72,16 @@ var coffeeSvc = Service{ ...@@ -66,12 +72,16 @@ var coffeeSvc = Service{
Name: "coffee-svc", Name: "coffee-svc",
Addresses: []Address{ Addresses: []Address{
{ {
IP: "192.0.2.4", PodNamespace: "default",
Port: 80, PodName: "coffee-6b9f5c47d7-bdt68",
IP: "192.0.2.4",
Port: 80,
}, },
{ {
IP: "192.0.2.5", PodNamespace: "default",
Port: 80, PodName: "coffee-6b9f5c47d7-l5zvl",
IP: "192.0.2.5",
Port: 80,
}, },
}, },
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
package vcl package vcl
import ( import (
"strconv"
"strings" "strings"
"text/template" "text/template"
) )
...@@ -84,7 +85,7 @@ probe {{probeName $name}} { ...@@ -84,7 +85,7 @@ probe {{probeName $name}} {
{{range $name, $svc := .IntSvcs -}} {{range $name, $svc := .IntSvcs -}}
{{range $addr := $svc.Addresses -}} {{range $addr := $svc.Addresses -}}
backend {{backendName $svc $addr.IP}} { backend {{backendName $svc $addr}} {
.host = "{{$addr.IP}}"; .host = "{{$addr.IP}}";
.port = "{{$addr.Port}}"; .port = "{{$addr.Port}}";
{{- with $svc}} {{- with $svc}}
...@@ -127,7 +128,7 @@ sub vcl_init { ...@@ -127,7 +128,7 @@ sub vcl_init {
{{- $dirType := dirType $svc}} {{- $dirType := dirType $svc}}
new {{dirName $svc}} = directors.{{$dirType}}(); new {{dirName $svc}} = directors.{{$dirType}}();
{{- range $addr := $svc.Addresses}} {{- range $addr := $svc.Addresses}}
{{dirName $svc}}.add_backend({{backendName $svc $addr.IP}} {{dirName $svc}}.add_backend({{backendName $svc $addr}}
{{- if eq $dirType "random"}} {{- if eq $dirType "random"}}
, 1.0 , 1.0
{{- end}} {{- end}}
...@@ -243,8 +244,14 @@ func dirType(svc Service) string { ...@@ -243,8 +244,14 @@ func dirType(svc Service) string {
return svc.Director.Type.String() return svc.Director.Type.String()
} }
func backendName(svc Service, addr string) string { func backendName(svc Service, addr Address) string {
return mangle(svc.Name + "_" + strings.Replace(addr, ".", "_", -1)) n := ""
if addr.PodNamespace != "" && addr.PodName != "" {
n = addr.PodNamespace + "_" + addr.PodName
} else {
n = svc.Name + "_" + strings.Replace(addr.IP, ".", "_", -1)
}
return mangle(n + "_" + strconv.Itoa(int(addr.Port)))
} }
func urlMatcher(rule Rule) string { func urlMatcher(rule Rule) string {
...@@ -268,7 +275,7 @@ var vclFuncs = template.FuncMap{ ...@@ -268,7 +275,7 @@ var vclFuncs = template.FuncMap{
"probeName": func(name string) string { "probeName": func(name string) string {
return mangle(name + "_probe") return mangle(name + "_probe")
}, },
"backendName": func(svc Service, addr string) string { "backendName": func(svc Service, addr Address) string {
return backendName(svc, addr) return backendName(svc, addr)
}, },
"dirName": func(svc Service) string { "dirName": func(svc Service) string {
......
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