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

Refactor generated VCL to implement Ingress path matching rules.

Now using the SUB feature of VMOD re2. This simplifies and
improves the scalability of the matching logic (one subroutine
call, rather than an if-elsif sequence that is as long as the
number of paths). Will also simplify the implementation of
pathType for k8s-1.22.
parent 9e39ac94
......@@ -107,10 +107,6 @@ backend vk8s_tea-svc_192_0_2_3_80 {
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qcafe.example.com\E(:\d+)?");
vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.random();
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_4_80
, 1.0
......@@ -143,17 +139,24 @@ sub vcl_init {
backend=vk8s_milk-svc_director.backend());
vk8s_cafe_example_com_url.add("/tea",
backend=vk8s_tea-svc_director.backend());
vk8s_cafe_example_com_url.compile();
}
sub vk8s_cafe_example_com_match {
if (vk8s_cafe_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qcafe.example.com\E(:\d+)?",
sub=vk8s_cafe_example_com_match);
}
sub vcl_backend_fetch {
set bereq.backend = vk8s_notfound;
if (vk8s_hosts.match(bereq.http.Host)) {
if (vk8s_hosts.which(select=FIRST) == 1) {
if (vk8s_cafe_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
call vk8s_hosts.subroutine(select=FIRST);
}
if (bereq.backend == vk8s_notfound) {
......
......@@ -30,10 +30,6 @@ backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qcafe.example.com\E(:\d+)?");
vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.round_robin();
vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-bdt68_80
);
......@@ -53,17 +49,24 @@ sub vcl_init {
backend=vk8s_coffee-svc_director.backend());
vk8s_cafe_example_com_url.add("/tea",
backend=vk8s_tea-svc_director.backend());
vk8s_cafe_example_com_url.compile();
}
sub vk8s_cafe_example_com_match {
if (vk8s_cafe_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qcafe.example.com\E(:\d+)?",
sub=vk8s_cafe_example_com_match);
}
sub vcl_backend_fetch {
set bereq.backend = vk8s_notfound;
if (vk8s_hosts.match(bereq.http.Host)) {
if (vk8s_hosts.which(select=FIRST) == 1) {
if (vk8s_cafe_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
call vk8s_hosts.subroutine(select=FIRST);
}
if (bereq.backend == vk8s_notfound) {
......
......@@ -30,12 +30,6 @@ backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qcafe.example.com\E(:\d+)?");
vk8s_hosts.add("\Qwhiskey.example.com\E(:\d+)?");
vk8s_hosts.add("\Qvodka.example.com\E(:\d+)?");
vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.round_robin();
vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-bdt68_80
);
......@@ -73,37 +67,48 @@ sub vcl_init {
backend=vk8s_coffee-svc_director.backend());
vk8s_cafe_example_com_url.add("/tea",
backend=vk8s_tea-svc_director.backend());
vk8s_cafe_example_com_url.compile();
new vk8s_whiskey_example_com_url = re2.set(posix_syntax=true, anchor=start);
vk8s_whiskey_example_com_url.add("/",
backend=vk8s_whiskey-svc_director.backend("whiskey.example.com"));
vk8s_whiskey_example_com_url.compile();
new vk8s_vodka_example_com_url = re2.set(posix_syntax=true, anchor=start);
vk8s_vodka_example_com_url.add("/",
backend=vk8s_vodka-svc_director.backend("vodka.example.com"));
vk8s_vodka_example_com_url.compile();
}
sub vk8s_cafe_example_com_match {
if (vk8s_cafe_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
sub vk8s_whiskey_example_com_match {
if (vk8s_whiskey_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_whiskey_example_com_url.backend(select=FIRST);
}
}
sub vk8s_vodka_example_com_match {
if (vk8s_vodka_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_vodka_example_com_url.backend(select=FIRST);
}
}
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qcafe.example.com\E(:\d+)?",
sub=vk8s_cafe_example_com_match);
vk8s_hosts.add("\Qwhiskey.example.com\E(:\d+)?",
sub=vk8s_whiskey_example_com_match);
vk8s_hosts.add("\Qvodka.example.com\E(:\d+)?",
sub=vk8s_vodka_example_com_match);
}
sub vcl_backend_fetch {
set bereq.backend = vk8s_notfound;
if (vk8s_hosts.match(bereq.http.Host)) {
if (vk8s_hosts.which(select=FIRST) == 1) {
if (vk8s_cafe_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
elsif (vk8s_hosts.which(select=FIRST) == 2) {
if (vk8s_whiskey_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_whiskey_example_com_url.backend(select=FIRST);
}
}
elsif (vk8s_hosts.which(select=FIRST) == 3) {
if (vk8s_vodka_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_vodka_example_com_url.backend(select=FIRST);
}
}
call vk8s_hosts.subroutine(select=FIRST);
}
if (bereq.backend == vk8s_notfound) {
......
......@@ -33,11 +33,6 @@ probe vk8s_tequila-svc_probe {
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qtequila.example.edu\E(:\d+)?");
vk8s_hosts.add("\Qmetaxa.example.edu\E(:\d+)?");
vk8s_hosts.compile();
new vk8s_metaxa-svc_resolver = dynamic.resolver();
vk8s_metaxa-svc_resolver.set_resolution_type(STUB);
new vk8s_metaxa-svc_director = dynamic.director(
......@@ -73,27 +68,36 @@ sub vcl_init {
new vk8s_tequila_example_edu_url = re2.set(posix_syntax=true, anchor=start);
vk8s_tequila_example_edu_url.add("/",
backend=vk8s_tequila-svc_director.backend("tequila.example.com"));
vk8s_tequila_example_edu_url.compile();
new vk8s_metaxa_example_edu_url = re2.set(posix_syntax=true, anchor=start);
vk8s_metaxa_example_edu_url.add("/",
backend=vk8s_metaxa-svc_director.backend("metaxa.example.com"));
vk8s_metaxa_example_edu_url.compile();
}
sub vk8s_tequila_example_edu_match {
if (vk8s_tequila_example_edu_url.match(bereq.url)) {
set bereq.backend = vk8s_tequila_example_edu_url.backend(select=FIRST);
}
}
sub vk8s_metaxa_example_edu_match {
if (vk8s_metaxa_example_edu_url.match(bereq.url)) {
set bereq.backend = vk8s_metaxa_example_edu_url.backend(select=FIRST);
}
}
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qtequila.example.edu\E(:\d+)?",
sub=vk8s_tequila_example_edu_match);
vk8s_hosts.add("\Qmetaxa.example.edu\E(:\d+)?",
sub=vk8s_metaxa_example_edu_match);
}
sub vcl_backend_fetch {
set bereq.backend = vk8s_notfound;
if (vk8s_hosts.match(bereq.http.Host)) {
if (vk8s_hosts.which(select=FIRST) == 1) {
if (vk8s_tequila_example_edu_url.match(bereq.url)) {
set bereq.backend = vk8s_tequila_example_edu_url.backend(select=FIRST);
}
}
elsif (vk8s_hosts.which(select=FIRST) == 2) {
if (vk8s_metaxa_example_edu_url.match(bereq.url)) {
set bereq.backend = vk8s_metaxa_example_edu_url.backend(select=FIRST);
}
}
call vk8s_hosts.subroutine(select=FIRST);
}
if (bereq.backend == vk8s_notfound) {
......
......@@ -65,6 +65,8 @@ sub vcl_init {
vk8s_tea-svc_director.reconfigure();
}
sub vcl_backend_fetch {
set bereq.backend = vk8s_notfound;
......
......@@ -130,12 +130,6 @@ backend vk8s_tea-svc_192_0_2_3_80 {
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qcafe.example.com\E(:\d+)?");
vk8s_hosts.add("\Qtequila.example.edu\E(:\d+)?");
vk8s_hosts.add("\Qmetaxa.example.edu\E(:\d+)?");
vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.random();
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_4_80
, 1.0
......@@ -200,37 +194,48 @@ sub vcl_init {
backend=vk8s_milk-svc_director.backend());
vk8s_cafe_example_com_url.add("/tea",
backend=vk8s_tea-svc_director.backend());
vk8s_cafe_example_com_url.compile();
new vk8s_tequila_example_edu_url = re2.set(posix_syntax=true, anchor=start);
vk8s_tequila_example_edu_url.add("/",
backend=vk8s_tequila-svc_director.backend("tequila.example.com"));
vk8s_tequila_example_edu_url.compile();
new vk8s_metaxa_example_edu_url = re2.set(posix_syntax=true, anchor=start);
vk8s_metaxa_example_edu_url.add("/",
backend=vk8s_metaxa-svc_director.backend("metaxa.example.com"));
vk8s_metaxa_example_edu_url.compile();
}
sub vk8s_cafe_example_com_match {
if (vk8s_cafe_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
sub vk8s_tequila_example_edu_match {
if (vk8s_tequila_example_edu_url.match(bereq.url)) {
set bereq.backend = vk8s_tequila_example_edu_url.backend(select=FIRST);
}
}
sub vk8s_metaxa_example_edu_match {
if (vk8s_metaxa_example_edu_url.match(bereq.url)) {
set bereq.backend = vk8s_metaxa_example_edu_url.backend(select=FIRST);
}
}
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qcafe.example.com\E(:\d+)?",
sub=vk8s_cafe_example_com_match);
vk8s_hosts.add("\Qtequila.example.edu\E(:\d+)?",
sub=vk8s_tequila_example_edu_match);
vk8s_hosts.add("\Qmetaxa.example.edu\E(:\d+)?",
sub=vk8s_metaxa_example_edu_match);
}
sub vcl_backend_fetch {
set bereq.backend = vk8s_notfound;
if (vk8s_hosts.match(bereq.http.Host)) {
if (vk8s_hosts.which(select=FIRST) == 1) {
if (vk8s_cafe_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
elsif (vk8s_hosts.which(select=FIRST) == 2) {
if (vk8s_tequila_example_edu_url.match(bereq.url)) {
set bereq.backend = vk8s_tequila_example_edu_url.backend(select=FIRST);
}
}
elsif (vk8s_hosts.which(select=FIRST) == 3) {
if (vk8s_metaxa_example_edu_url.match(bereq.url)) {
set bereq.backend = vk8s_metaxa_example_edu_url.backend(select=FIRST);
}
}
call vk8s_hosts.subroutine(select=FIRST);
}
if (bereq.backend == vk8s_notfound) {
......
......@@ -30,11 +30,6 @@ backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qtea.example.com\E(:\d+)?");
vk8s_hosts.add("[^:]+(:\d+)?");
vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.round_robin();
vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-bdt68_80
);
......@@ -52,29 +47,38 @@ sub vcl_init {
new vk8s_tea_example_com_url = re2.set(posix_syntax=true, anchor=start);
vk8s_tea_example_com_url.add("/",
backend=vk8s_tea-svc_director.backend());
vk8s_tea_example_com_url.compile();
new vk8s_any_host = re2.set(posix_syntax=true, anchor=start);
vk8s_any_host.add("/coffee",
new vk8s_any_host_url = re2.set(posix_syntax=true, anchor=start);
vk8s_any_host_url.add("/coffee",
backend=vk8s_coffee-svc_director.backend());
vk8s_any_host.add("/tea",
vk8s_any_host_url.add("/tea",
backend=vk8s_tea-svc_director.backend());
vk8s_any_host.compile();
}
sub vk8s_tea_example_com_match {
if (vk8s_tea_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_tea_example_com_url.backend(select=FIRST);
}
}
sub vk8s_any_host_match {
if (vk8s_any_host_url.match(bereq.url)) {
set bereq.backend = vk8s_any_host_url.backend(select=FIRST);
}
}
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qtea.example.com\E(:\d+)?",
sub=vk8s_tea_example_com_match);
vk8s_hosts.add("[^:]+(:\d+)?",
sub=vk8s_any_host_match);
}
sub vcl_backend_fetch {
set bereq.backend = vk8s_notfound;
if (vk8s_hosts.match(bereq.http.Host)) {
if (vk8s_hosts.which(select=FIRST) == 1) {
if (vk8s_tea_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_tea_example_com_url.backend(select=FIRST);
}
}
elsif (vk8s_hosts.which(select=FIRST) == 2) {
if (vk8s_any_host.match(bereq.url)) {
set bereq.backend = vk8s_any_host.backend(select=FIRST);
}
}
call vk8s_hosts.subroutine(select=FIRST);
}
if (bereq.backend == vk8s_notfound) {
......
......@@ -30,10 +30,6 @@ backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qcafe.example.com\E(:\d+)?");
vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.round_robin();
vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-bdt68_80
);
......@@ -53,17 +49,24 @@ sub vcl_init {
backend=vk8s_coffee-svc_director.backend());
vk8s_cafe_example_com_url.add("/tea",
backend=vk8s_tea-svc_director.backend());
vk8s_cafe_example_com_url.compile();
}
sub vk8s_cafe_example_com_match {
if (vk8s_cafe_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qcafe.example.com\E(:\d+)?",
sub=vk8s_cafe_example_com_match);
}
sub vcl_backend_fetch {
set bereq.backend = vk8s_notfound;
if (vk8s_hosts.match(bereq.http.Host)) {
if (vk8s_hosts.which(select=FIRST) == 1) {
if (vk8s_cafe_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
call vk8s_hosts.subroutine(select=FIRST);
}
if (bereq.backend == vk8s_notfound) {
......
......@@ -31,6 +31,8 @@ sub vcl_init {
);
}
sub vcl_backend_fetch {
set bereq.backend = vk8s_notfound;
......
......@@ -42,12 +42,6 @@ backend vk8s_water-svc_192_0_2_130_8000 {
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qtea.example.com\E(:\d+)?");
vk8s_hosts.add("\Qcoffee.example.com\E(:\d+)?");
vk8s_hosts.add("[^:]+(:\d+)?");
vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.round_robin();
vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-bdt68_80
);
......@@ -73,37 +67,48 @@ sub vcl_init {
new vk8s_tea_example_com_url = re2.set(posix_syntax=true, anchor=start);
vk8s_tea_example_com_url.add("/",
backend=vk8s_tea-svc_director.backend());
vk8s_tea_example_com_url.compile();
new vk8s_coffee_example_com_url = re2.set(posix_syntax=true, anchor=start);
vk8s_coffee_example_com_url.add("/",
backend=vk8s_coffee-svc_director.backend());
vk8s_coffee_example_com_url.compile();
new vk8s_any_host = re2.set(posix_syntax=true, anchor=start);
vk8s_any_host.add("/",
new vk8s_any_host_url = re2.set(posix_syntax=true, anchor=start);
vk8s_any_host_url.add("/",
backend=vk8s_water-svc_director.backend());
vk8s_any_host.compile();
}
sub vk8s_tea_example_com_match {
if (vk8s_tea_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_tea_example_com_url.backend(select=FIRST);
}
}
sub vk8s_coffee_example_com_match {
if (vk8s_coffee_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_coffee_example_com_url.backend(select=FIRST);
}
}
sub vk8s_any_host_match {
if (vk8s_any_host_url.match(bereq.url)) {
set bereq.backend = vk8s_any_host_url.backend(select=FIRST);
}
}
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qtea.example.com\E(:\d+)?",
sub=vk8s_tea_example_com_match);
vk8s_hosts.add("\Qcoffee.example.com\E(:\d+)?",
sub=vk8s_coffee_example_com_match);
vk8s_hosts.add("[^:]+(:\d+)?",
sub=vk8s_any_host_match);
}
sub vcl_backend_fetch {
set bereq.backend = vk8s_notfound;
if (vk8s_hosts.match(bereq.http.Host)) {
if (vk8s_hosts.which(select=FIRST) == 1) {
if (vk8s_tea_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_tea_example_com_url.backend(select=FIRST);
}
}
elsif (vk8s_hosts.which(select=FIRST) == 2) {
if (vk8s_coffee_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_coffee_example_com_url.backend(select=FIRST);
}
}
elsif (vk8s_hosts.which(select=FIRST) == 3) {
if (vk8s_any_host.match(bereq.url)) {
set bereq.backend = vk8s_any_host.backend(select=FIRST);
}
}
call vk8s_hosts.subroutine(select=FIRST);
}
if (bereq.backend == vk8s_notfound) {
......
......@@ -30,10 +30,6 @@ backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qcafe.example.com\E(:\d+)?");
vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.round_robin();
vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-bdt68_80
);
......@@ -53,17 +49,24 @@ sub vcl_init {
backend=vk8s_coffee-svc_director.backend());
vk8s_cafe_example_com_url.add("/tea",
backend=vk8s_tea-svc_director.backend());
vk8s_cafe_example_com_url.compile();
}
sub vk8s_cafe_example_com_match {
if (vk8s_cafe_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qcafe.example.com\E(:\d+)?",
sub=vk8s_cafe_example_com_match);
}
sub vcl_backend_fetch {
set bereq.backend = vk8s_notfound;
if (vk8s_hosts.match(bereq.http.Host)) {
if (vk8s_hosts.which(select=FIRST) == 1) {
if (vk8s_cafe_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
call vk8s_hosts.subroutine(select=FIRST);
}
if (bereq.backend == vk8s_notfound) {
......
......@@ -11,6 +11,8 @@ include "bogo_backend.vcl";
sub vcl_init {}
sub vcl_backend_fetch {
set bereq.backend = vk8s_notfound;
......
......@@ -37,10 +37,6 @@ backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qcafe.example.com\E(:\d+)?");
vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.round_robin();
vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-bdt68_80
);
......@@ -60,17 +56,24 @@ sub vcl_init {
backend=vk8s_coffee-svc_director.backend());
vk8s_cafe_example_com_url.add("/tea",
backend=vk8s_tea-svc_director.backend());
vk8s_cafe_example_com_url.compile();
}
sub vk8s_cafe_example_com_match {
if (vk8s_cafe_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qcafe.example.com\E(:\d+)?",
sub=vk8s_cafe_example_com_match);
}
sub vcl_backend_fetch {
set bereq.backend = vk8s_notfound;
if (vk8s_hosts.match(bereq.http.Host)) {
if (vk8s_hosts.which(select=FIRST) == 1) {
if (vk8s_cafe_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
call vk8s_hosts.subroutine(select=FIRST);
}
if (bereq.backend == vk8s_notfound) {
......
......@@ -34,10 +34,6 @@ backend vk8s_default_tea-5798f99dc5-5wj8n_80 {
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qcafe.example.com\E(:\d+)?");
vk8s_hosts.compile();
new vk8s_coffee-svc_director = directors.round_robin();
vk8s_coffee-svc_director.add_backend(vk8s_default_coffee-6b9f5c47d7-bdt68_80
);
......@@ -57,17 +53,24 @@ sub vcl_init {
backend=vk8s_coffee-svc_director.backend());
vk8s_cafe_example_com_url.add("/tea",
backend=vk8s_tea-svc_director.backend());
vk8s_cafe_example_com_url.compile();
}
sub vk8s_cafe_example_com_match {
if (vk8s_cafe_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
vk8s_hosts.add("\Qcafe.example.com\E(:\d+)?",
sub=vk8s_cafe_example_com_match);
}
sub vcl_backend_fetch {
set bereq.backend = vk8s_notfound;
if (vk8s_hosts.match(bereq.http.Host)) {
if (vk8s_hosts.which(select=FIRST) == 1) {
if (vk8s_cafe_example_com_url.match(bereq.url)) {
set bereq.backend = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
call vk8s_hosts.subroutine(select=FIRST);
}
if (bereq.backend == vk8s_notfound) {
......
......@@ -124,13 +124,6 @@ backend {{backendName $svc $addr}} {
{{end}}
sub vcl_init {
{{- if .Rules}}
new vk8s_hosts = re2.set(anchor=both);
{{- range $rule := .Rules}}
vk8s_hosts.add("{{hostRegex $rule.Host}}(:\d+)?");
{{- end}}
vk8s_hosts.compile();
{{end}}
{{- range $name, $svc := .IntSvcs}}
{{- $dirType := dirType $svc}}
......@@ -229,21 +222,33 @@ sub vcl_init {
backend={{dirName $svc}}.backend());
{{- end}}
{{- end}}
{{urlMatcher $rule}}.compile();
{{end -}}
}
{{ range $rule := .Rules -}}
sub {{hostMangle $rule.Host}}_match {
if ({{urlMatcher $rule}}.match(bereq.url)) {
set bereq.backend = {{urlMatcher $rule}}.backend(select=FIRST);
}
}
{{end -}}
{{ if .Rules -}}
sub vcl_init {
new vk8s_hosts = re2.set(anchor=both);
{{- range $rule := .Rules}}
vk8s_hosts.add("{{hostRegex $rule.Host}}(:\d+)?",
sub={{hostMangle $rule.Host}}_match);
{{- end}}
}
{{- end}}
sub vcl_backend_fetch {
set bereq.backend = vk8s_notfound;
{{- if .Rules}}
if (vk8s_hosts.match(bereq.http.Host)) {
{{- range $i, $rule := .Rules}}
{{ifelse $i}} (vk8s_hosts.which(select=FIRST) == {{plusOne $i}}) {
if ({{urlMatcher $rule}}.match(bereq.url)) {
set bereq.backend = {{urlMatcher $rule}}.backend(select=FIRST);
}
}
{{- end}}
call vk8s_hosts.subroutine(select=FIRST);
}
{{- end}}
......@@ -266,11 +271,15 @@ func dirType(svc Service) string {
return svc.Director.Type.String()
}
func urlMatcher(rule Rule) string {
if rule.Host == "" {
func hostMangle(host string) string {
if host == "" {
return mangle("any_host")
}
return mangle(strings.Replace(rule.Host, ".", "_", -1) + "_url")
return mangle(strings.Replace(host, ".", "_", -1))
}
func urlMatcher(rule Rule) string {
return hostMangle(rule.Host) + "_url"
}
func hostRegex(host string) string {
......@@ -299,6 +308,7 @@ var vclFuncs = template.FuncMap{
"dirType": func(svc Service) string { return dirType(svc) },
"hostRegex": func(host string) string { return hostRegex(host) },
"backendName": backendName,
"hostMangle": hostMangle,
"needsVia": needsVia,
"probeName": func(name string) string {
return mangle(name + "_probe")
......
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