Commit c126ae04 authored by Geoff Simmons's avatar Geoff Simmons

Add VCL generation tests for Ingress with default backend.

parent b8a051b1
......@@ -138,3 +138,77 @@ func TestIngressVhostNoHost(t *testing.T) {
}
}
}
var singleSvcSpec = Spec{
DefaultService: teaSvc,
IntSvcs: map[string]Service{"tea-svc": teaSvc},
}
func TestIngressSingleSvc(t *testing.T) {
var buf bytes.Buffer
gold := "ingress_single_svc.golden"
if err := ingressTmpl.Execute(&buf, singleSvcSpec); err != nil {
t.Fatal("Execute():", err)
}
ok, err := cmpGold(buf.Bytes(), gold)
if err != nil {
t.Fatalf("Reading %s: %v", gold, err)
}
if !ok {
t.Errorf("Generated VCL for IngressSpec does not match gold "+
"file: %s", gold)
if testing.Verbose() {
t.Logf("Generated: %s", buf.String())
}
}
}
var defaultSvcProbeDir = Spec{
DefaultService: teaSvcProbeDir,
IntSvcs: map[string]Service{"tea-svc": teaSvcProbeDir},
}
func TestIngressDefaultProbeDir(t *testing.T) {
var buf bytes.Buffer
gold := "ingress_default_probe_dir.golden"
if err := ingressTmpl.Execute(&buf, defaultSvcProbeDir); err != nil {
t.Fatal("Execute():", err)
}
ok, err := cmpGold(buf.Bytes(), gold)
if err != nil {
t.Fatalf("Reading %s: %v", gold, err)
}
if !ok {
t.Errorf("Generated VCL for IngressSpec does not match gold "+
"file: %s", gold)
if testing.Verbose() {
t.Logf("Generated: %s", buf.String())
}
}
}
var barDefaultProbeDir = Spec{
DefaultService: extTequilaSvc,
Rules: append(cafeProbeDir.Rules, boozeSpec.Rules...),
IntSvcs: cafeProbeDir.IntSvcs,
ExtSvcs: boozeSpec.ExtSvcs,
}
func TestIngressDefaultRules(t *testing.T) {
var buf bytes.Buffer
gold := "ingress_default_rules.golden"
if err := ingressTmpl.Execute(&buf, barDefaultProbeDir); err != nil {
t.Fatal("Execute():", err)
}
ok, err := cmpGold(buf.Bytes(), gold)
if err != nil {
t.Fatalf("Reading %s: %v", gold, err)
}
if !ok {
t.Errorf("Generated VCL for IngressSpec does not match gold "+
"file: %s", gold)
if testing.Verbose() {
t.Logf("Generated: %s", buf.String())
}
}
}
vcl 4.1;
import std;
import directors;
import re2;
import dynamic;
backend vk8s_notfound {
# 192.0.2.0/24 reserved for docs & examples (RFC5737).
.host = "192.0.2.255";
.port = "80";
}
probe vk8s_tea-svc_probe {
.url = "/healthz";
.expected_response = 204;
.timeout = 5s;
.interval = 5s;
.initial = 2;
.window = 8;
.threshold = 3;
}
backend vk8s_tea-svc_192_0_2_1 {
.host = "192.0.2.1";
.port = "80";
.host_header = "tea.svc.org";
.connect_timeout = 1s;
.first_byte_timeout = 2s;
.between_bytes_timeout = 2s;
.proxy_header = 1;
.max_connections = 200;
.probe = vk8s_tea-svc_probe;
}
backend vk8s_tea-svc_192_0_2_2 {
.host = "192.0.2.2";
.port = "80";
.host_header = "tea.svc.org";
.connect_timeout = 1s;
.first_byte_timeout = 2s;
.between_bytes_timeout = 2s;
.proxy_header = 1;
.max_connections = 200;
.probe = vk8s_tea-svc_probe;
}
backend vk8s_tea-svc_192_0_2_3 {
.host = "192.0.2.3";
.port = "80";
.host_header = "tea.svc.org";
.connect_timeout = 1s;
.first_byte_timeout = 2s;
.between_bytes_timeout = 2s;
.proxy_header = 1;
.max_connections = 200;
.probe = vk8s_tea-svc_probe;
}
sub vcl_init {
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_2
);
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_3
);
vk8s_tea-svc_director.set_warmup(0.5);
vk8s_tea-svc_director.set_rampup(5m);
vk8s_tea-svc_director.reconfigure();
}
sub vk8s_set_backend {
set req.backend_hint = vk8s_notfound;
if (req.backend_hint == vk8s_notfound) {
set req.backend_hint = vk8s_tea-svc_director.backend();
}
}
sub vcl_miss {
call vk8s_set_backend;
}
sub vcl_pass {
call vk8s_set_backend;
}
sub vcl_pipe {
call vk8s_set_backend;
}
sub vcl_hit {
if (obj.ttl < 0s) {
# Set a backend for a background fetch.
call vk8s_set_backend;
}
}
vcl 4.1;
import std;
import directors;
import re2;
import dynamic;
backend vk8s_notfound {
# 192.0.2.0/24 reserved for docs & examples (RFC5737).
.host = "192.0.2.255";
.port = "80";
}
probe vk8s_coffee-svc_probe {
.request =
"GET /healthz HTTP/1.1"
"Host: coffee.svc.org"
"Connection: close"
;
.timeout = 4s;
.interval = 4s;
.initial = 1;
.window = 7;
.threshold = 2;
}
probe vk8s_milk-svc_probe {
.timeout = 5s;
.interval = 5s;
.window = 3;
.threshold = 2;
}
probe vk8s_tea-svc_probe {
.url = "/healthz";
.expected_response = 204;
.timeout = 5s;
.interval = 5s;
.initial = 2;
.window = 8;
.threshold = 3;
}
probe vk8s_metaxa-svc_probe {
.request =
"GET /the-worm/ HTTP/1.1"
"Host: mextaxa.example.org"
"Connection: close"
;
.timeout = 10s;
.interval = 20s;
.initial = 2;
.window = 5;
.threshold = 3;
}
probe vk8s_tequila-svc_probe {
.url = "/shot/";
.expected_response = 418;
.timeout = 5s;
.interval = 10s;
.initial = 1;
.window = 4;
.threshold = 3;
}
backend vk8s_coffee-svc_192_0_2_4 {
.host = "192.0.2.4";
.port = "80";
.host_header = "coffee.svc.org";
.connect_timeout = 3s;
.first_byte_timeout = 2s;
.between_bytes_timeout = 1s;
.proxy_header = 2;
.probe = vk8s_coffee-svc_probe;
}
backend vk8s_coffee-svc_192_0_2_5 {
.host = "192.0.2.5";
.port = "80";
.host_header = "coffee.svc.org";
.connect_timeout = 3s;
.first_byte_timeout = 2s;
.between_bytes_timeout = 1s;
.proxy_header = 2;
.probe = vk8s_coffee-svc_probe;
}
backend vk8s_milk-svc_192_0_2_6 {
.host = "192.0.2.6";
.port = "80";
.host_header = "milk.svc.org";
.first_byte_timeout = 3s;
.probe = vk8s_milk-svc_probe;
}
backend vk8s_milk-svc_192_0_2_7 {
.host = "192.0.2.7";
.port = "80";
.host_header = "milk.svc.org";
.first_byte_timeout = 3s;
.probe = vk8s_milk-svc_probe;
}
backend vk8s_tea-svc_192_0_2_1 {
.host = "192.0.2.1";
.port = "80";
.host_header = "tea.svc.org";
.connect_timeout = 1s;
.first_byte_timeout = 2s;
.between_bytes_timeout = 2s;
.proxy_header = 1;
.max_connections = 200;
.probe = vk8s_tea-svc_probe;
}
backend vk8s_tea-svc_192_0_2_2 {
.host = "192.0.2.2";
.port = "80";
.host_header = "tea.svc.org";
.connect_timeout = 1s;
.first_byte_timeout = 2s;
.between_bytes_timeout = 2s;
.proxy_header = 1;
.max_connections = 200;
.probe = vk8s_tea-svc_probe;
}
backend vk8s_tea-svc_192_0_2_3 {
.host = "192.0.2.3";
.port = "80";
.host_header = "tea.svc.org";
.connect_timeout = 1s;
.first_byte_timeout = 2s;
.between_bytes_timeout = 2s;
.proxy_header = 1;
.max_connections = 200;
.probe = vk8s_tea-svc_probe;
}
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
, 1.0
);
vk8s_coffee-svc_director.add_backend(vk8s_coffee-svc_192_0_2_5
, 1.0
);
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_7
);
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_2
);
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_3
);
vk8s_tea-svc_director.set_warmup(0.5);
vk8s_tea-svc_director.set_rampup(5m);
vk8s_tea-svc_director.reconfigure();
new vk8s_metaxa-svc_resolver = dynamic.resolver();
vk8s_metaxa-svc_resolver.set_resolution_type(STUB);
new vk8s_metaxa-svc_director = dynamic.director(
ttl_from = dns,
ttl = 30s,
resolver = vk8s_metaxa-svc_resolver.use()
, port = "8080"
, host_header = "metaxa.example.org"
, connect_timeout = 2s
, first_byte_timeout = 3s
, between_bytes_timeout = 4s
, proxy_header = 1
, max_connections = 200
, probe = vk8s_metaxa-svc_probe
);
new vk8s_tequila-svc_resolver = dynamic.resolver();
vk8s_tequila-svc_resolver.set_resolution_type(STUB);
new vk8s_tequila-svc_director = dynamic.director(
ttl_from = dns,
ttl = 30s,
resolver = vk8s_tequila-svc_resolver.use()
, port = "88"
, host_header = "tequila.example.org"
, connect_timeout = 1s
, first_byte_timeout = 2s
, between_bytes_timeout = 3s
, proxy_header = 2
, max_connections = 100
, probe = vk8s_tequila-svc_probe
);
new vk8s_cafe_example_com_url = re2.set(posix_syntax=true, anchor=start);
vk8s_cafe_example_com_url.add("/coffee",
backend=vk8s_coffee-svc_director.backend());
vk8s_cafe_example_com_url.add("/milk",
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_set_backend {
set req.backend_hint = vk8s_notfound;
if (vk8s_hosts.match(req.http.Host)) {
if (0 != 0) {
#
}
elsif (vk8s_hosts.which(select=FIRST) == 1) {
if (vk8s_cafe_example_com_url.match(req.url)) {
set req.backend_hint = vk8s_cafe_example_com_url.backend(select=FIRST);
}
}
elsif (vk8s_hosts.which(select=FIRST) == 2) {
if (vk8s_tequila_example_edu_url.match(req.url)) {
set req.backend_hint = vk8s_tequila_example_edu_url.backend(select=FIRST);
}
}
elsif (vk8s_hosts.which(select=FIRST) == 3) {
if (vk8s_metaxa_example_edu_url.match(req.url)) {
set req.backend_hint = vk8s_metaxa_example_edu_url.backend(select=FIRST);
}
}
}
if (req.backend_hint == vk8s_notfound) {
set req.backend_hint = vk8s_tequila-svc_director.backend();
}
}
sub vcl_miss {
call vk8s_set_backend;
}
sub vcl_pass {
call vk8s_set_backend;
}
sub vcl_pipe {
call vk8s_set_backend;
}
sub vcl_hit {
if (obj.ttl < 0s) {
# Set a backend for a background fetch.
call vk8s_set_backend;
}
}
vcl 4.1;
import std;
import directors;
import re2;
import dynamic;
backend vk8s_notfound {
# 192.0.2.0/24 reserved for docs & examples (RFC5737).
.host = "192.0.2.255";
.port = "80";
}
backend vk8s_tea-svc_192_0_2_1 {
.host = "192.0.2.1";
.port = "80";
}
backend vk8s_tea-svc_192_0_2_2 {
.host = "192.0.2.2";
.port = "80";
}
backend vk8s_tea-svc_192_0_2_3 {
.host = "192.0.2.3";
.port = "80";
}
sub vcl_init {
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_tea-svc_192_0_2_2
);
vk8s_tea-svc_director.add_backend(vk8s_tea-svc_192_0_2_3
);
}
sub vk8s_set_backend {
set req.backend_hint = vk8s_notfound;
if (req.backend_hint == vk8s_notfound) {
set req.backend_hint = vk8s_tea-svc_director.backend();
}
}
sub vcl_miss {
call vk8s_set_backend;
}
sub vcl_pass {
call vk8s_set_backend;
}
sub vcl_pipe {
call vk8s_set_backend;
}
sub vcl_hit {
if (obj.ttl < 0s) {
# Set a backend for a background fetch.
call vk8s_set_backend;
}
}
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