Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
k8s-ingress
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
3
Merge Requests
3
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
uplex-varnish
k8s-ingress
Commits
c126ae04
Commit
c126ae04
authored
Dec 06, 2020
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add VCL generation tests for Ingress with default backend.
parent
b8a051b1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
499 additions
and
0 deletions
+499
-0
ingresses_test.go
pkg/varnish/vcl/ingresses_test.go
+74
-0
ingress_default_probe_dir.golden
pkg/varnish/vcl/testdata/ingress_default_probe_dir.golden
+97
-0
ingress_default_rules.golden
pkg/varnish/vcl/testdata/ingress_default_rules.golden
+265
-0
ingress_single_svc.golden
pkg/varnish/vcl/testdata/ingress_single_svc.golden
+63
-0
No files found.
pkg/varnish/vcl/ingresses_test.go
View file @
c126ae04
...
...
@@ -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
())
}
}
}
pkg/varnish/vcl/testdata/ingress_default_probe_dir.golden
0 → 100644
View file @
c126ae04
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;
}
}
pkg/varnish/vcl/testdata/ingress_default_rules.golden
0 → 100644
View file @
c126ae04
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;
}
}
pkg/varnish/vcl/testdata/ingress_single_svc.golden
0 → 100644
View file @
c126ae04
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;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment