Commit ffa46910 authored by Geoff Simmons's avatar Geoff Simmons

Refactor the naming of Varnish backends in VCL for self-sharding.

Now consistent with the naming of IngressBackends. Adds the vk8s_
prefix, the namespace and port to the name.
parent 3f307b14
......@@ -310,7 +310,9 @@ func (worker *NamespaceWorker) configSharding(spec *vcl.Spec,
}
ns, name := getTargetPod(addr)
if ns != "" && name != "" {
node.Name = ns + "_" + name
node.Name = eps.Name
node.Addresses[0].PodNamespace = ns
node.Addresses[0].PodName = name
}
node.Addresses[0].IP = addr.IP
node.Addresses[0].Port = httpPort
......
......@@ -61,7 +61,7 @@ probe vk8s_probe_varnish {
}
{{range $node := .Nodes -}}
backend {{$node.Name}} {
backend {{backendName $node}} {
.host = "{{(index $node.Addresses 0).IP}}";
.port = "{{(index $node.Addresses 0).Port}}";
.probe = vk8s_probe_varnish;
......@@ -78,7 +78,7 @@ acl vk8s_cluster_acl {
sub vcl_init {
new vk8s_cluster = directors.shard();
{{range $node := .Nodes -}}
vk8s_cluster.add_backend({{$node.Name}});
vk8s_cluster.add_backend({{backendName $node}});
{{end -}}
vk8s_cluster.reconfigure();
{{- digest_init . }}
......@@ -229,6 +229,9 @@ var shardFuncMap = template.FuncMap{
"key": keyParams,
"digest_init": digestInit,
"digest_update": digestUpdate,
"backendName": func(svc Service) string {
return backendName(svc, svc.Addresses[0])
},
}
var shardTmpl = template.Must(template.New(selfShardName).Funcs(shardFuncMap).
......
......@@ -36,7 +36,7 @@ import (
var varnishCluster = ShardCluster{
Nodes: []Service{
{
Name: "varnish-8445d4f7f-z2b9p",
Name: "viking-service",
Addresses: []Address{{
PodNamespace: "default",
PodName: "varnish-8445d4f7f-z2b9p",
......@@ -45,16 +45,14 @@ var varnishCluster = ShardCluster{
}},
},
{
Name: "varnish-8445d4f7f-k22dn",
Name: "viking-service",
Addresses: []Address{{
PodNamespace: "default",
PodName: "varnish-8445d4f7f-k22dn",
IP: "172.17.0.13",
Port: 80,
IP: "172.17.0.13",
Port: 80,
}},
},
{
Name: "varnish-8445d4f7f-ldljf",
Name: "viking-service",
Addresses: []Address{{
PodNamespace: "default",
PodName: "varnish-8445d4f7f-ldljf",
......
......@@ -34,6 +34,7 @@ import (
"hash/fnv"
"math/big"
"regexp"
"strconv"
"strings"
)
......@@ -116,6 +117,16 @@ func mangle(s string) string {
return bound(string(mangled), maxSymLen)
}
func backendName(svc Service, addr Address) string {
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 cmpRelation(cmp CompareType, negate bool) string {
switch cmp {
case Equal:
......
......@@ -87,19 +87,19 @@ probe vk8s_probe_varnish {
.threshold = 3;
}
backend varnish-8445d4f7f-z2b9p {
backend vk8s_default_varnish-8445d4f7f-z2b9p_80 {
.host = "172.17.0.12";
.port = "80";
.probe = vk8s_probe_varnish;
}
backend varnish-8445d4f7f-k22dn {
backend vk8s_viking-service_172_17_0_13_80 {
.host = "172.17.0.13";
.port = "80";
.probe = vk8s_probe_varnish;
}
backend varnish-8445d4f7f-ldljf {
backend vk8s_default_varnish-8445d4f7f-ldljf_80 {
.host = "172.17.0.14";
.port = "80";
.probe = vk8s_probe_varnish;
......@@ -113,9 +113,9 @@ acl vk8s_cluster_acl {
sub vcl_init {
new vk8s_cluster = directors.shard();
vk8s_cluster.add_backend(varnish-8445d4f7f-z2b9p);
vk8s_cluster.add_backend(varnish-8445d4f7f-k22dn);
vk8s_cluster.add_backend(varnish-8445d4f7f-ldljf);
vk8s_cluster.add_backend(vk8s_default_varnish-8445d4f7f-z2b9p_80);
vk8s_cluster.add_backend(vk8s_viking-service_172_17_0_13_80);
vk8s_cluster.add_backend(vk8s_default_varnish-8445d4f7f-ldljf_80);
vk8s_cluster.reconfigure();
}
......
......@@ -15,19 +15,19 @@ probe vk8s_probe_varnish {
.threshold = 3;
}
backend varnish-8445d4f7f-z2b9p {
backend vk8s_default_varnish-8445d4f7f-z2b9p_80 {
.host = "172.17.0.12";
.port = "80";
.probe = vk8s_probe_varnish;
}
backend varnish-8445d4f7f-k22dn {
backend vk8s_viking-service_172_17_0_13_80 {
.host = "172.17.0.13";
.port = "80";
.probe = vk8s_probe_varnish;
}
backend varnish-8445d4f7f-ldljf {
backend vk8s_default_varnish-8445d4f7f-ldljf_80 {
.host = "172.17.0.14";
.port = "80";
.probe = vk8s_probe_varnish;
......@@ -41,9 +41,9 @@ acl vk8s_cluster_acl {
sub vcl_init {
new vk8s_cluster = directors.shard();
vk8s_cluster.add_backend(varnish-8445d4f7f-z2b9p);
vk8s_cluster.add_backend(varnish-8445d4f7f-k22dn);
vk8s_cluster.add_backend(varnish-8445d4f7f-ldljf);
vk8s_cluster.add_backend(vk8s_default_varnish-8445d4f7f-z2b9p_80);
vk8s_cluster.add_backend(vk8s_viking-service_172_17_0_13_80);
vk8s_cluster.add_backend(vk8s_default_varnish-8445d4f7f-ldljf_80);
vk8s_cluster.reconfigure();
}
......
......@@ -15,19 +15,19 @@ probe vk8s_probe_varnish {
.threshold = 3;
}
backend varnish-8445d4f7f-z2b9p {
backend vk8s_default_varnish-8445d4f7f-z2b9p_80 {
.host = "172.17.0.12";
.port = "80";
.probe = vk8s_probe_varnish;
}
backend varnish-8445d4f7f-k22dn {
backend vk8s_viking-service_172_17_0_13_80 {
.host = "172.17.0.13";
.port = "80";
.probe = vk8s_probe_varnish;
}
backend varnish-8445d4f7f-ldljf {
backend vk8s_default_varnish-8445d4f7f-ldljf_80 {
.host = "172.17.0.14";
.port = "80";
.probe = vk8s_probe_varnish;
......@@ -41,9 +41,9 @@ acl vk8s_cluster_acl {
sub vcl_init {
new vk8s_cluster = directors.shard();
vk8s_cluster.add_backend(varnish-8445d4f7f-z2b9p);
vk8s_cluster.add_backend(varnish-8445d4f7f-k22dn);
vk8s_cluster.add_backend(varnish-8445d4f7f-ldljf);
vk8s_cluster.add_backend(vk8s_default_varnish-8445d4f7f-z2b9p_80);
vk8s_cluster.add_backend(vk8s_viking-service_172_17_0_13_80);
vk8s_cluster.add_backend(vk8s_default_varnish-8445d4f7f-ldljf_80);
vk8s_cluster.reconfigure();
}
......
......@@ -15,19 +15,19 @@ probe vk8s_probe_varnish {
.threshold = 3;
}
backend varnish-8445d4f7f-z2b9p {
backend vk8s_default_varnish-8445d4f7f-z2b9p_80 {
.host = "172.17.0.12";
.port = "80";
.probe = vk8s_probe_varnish;
}
backend varnish-8445d4f7f-k22dn {
backend vk8s_viking-service_172_17_0_13_80 {
.host = "172.17.0.13";
.port = "80";
.probe = vk8s_probe_varnish;
}
backend varnish-8445d4f7f-ldljf {
backend vk8s_default_varnish-8445d4f7f-ldljf_80 {
.host = "172.17.0.14";
.port = "80";
.probe = vk8s_probe_varnish;
......@@ -41,9 +41,9 @@ acl vk8s_cluster_acl {
sub vcl_init {
new vk8s_cluster = directors.shard();
vk8s_cluster.add_backend(varnish-8445d4f7f-z2b9p);
vk8s_cluster.add_backend(varnish-8445d4f7f-k22dn);
vk8s_cluster.add_backend(varnish-8445d4f7f-ldljf);
vk8s_cluster.add_backend(vk8s_default_varnish-8445d4f7f-z2b9p_80);
vk8s_cluster.add_backend(vk8s_viking-service_172_17_0_13_80);
vk8s_cluster.add_backend(vk8s_default_varnish-8445d4f7f-ldljf_80);
vk8s_cluster.reconfigure();
new vk8s_shard_digest = blobdigest.digest(SHA3_512);
}
......
......@@ -15,19 +15,19 @@ probe vk8s_probe_varnish {
.threshold = 3;
}
backend varnish-8445d4f7f-z2b9p {
backend vk8s_default_varnish-8445d4f7f-z2b9p_80 {
.host = "172.17.0.12";
.port = "80";
.probe = vk8s_probe_varnish;
}
backend varnish-8445d4f7f-k22dn {
backend vk8s_viking-service_172_17_0_13_80 {
.host = "172.17.0.13";
.port = "80";
.probe = vk8s_probe_varnish;
}
backend varnish-8445d4f7f-ldljf {
backend vk8s_default_varnish-8445d4f7f-ldljf_80 {
.host = "172.17.0.14";
.port = "80";
.probe = vk8s_probe_varnish;
......@@ -41,9 +41,9 @@ acl vk8s_cluster_acl {
sub vcl_init {
new vk8s_cluster = directors.shard();
vk8s_cluster.add_backend(varnish-8445d4f7f-z2b9p);
vk8s_cluster.add_backend(varnish-8445d4f7f-k22dn);
vk8s_cluster.add_backend(varnish-8445d4f7f-ldljf);
vk8s_cluster.add_backend(vk8s_default_varnish-8445d4f7f-z2b9p_80);
vk8s_cluster.add_backend(vk8s_viking-service_172_17_0_13_80);
vk8s_cluster.add_backend(vk8s_default_varnish-8445d4f7f-ldljf_80);
vk8s_cluster.reconfigure();
}
......
......@@ -15,19 +15,19 @@ probe vk8s_probe_varnish {
.threshold = 3;
}
backend varnish-8445d4f7f-z2b9p {
backend vk8s_default_varnish-8445d4f7f-z2b9p_80 {
.host = "172.17.0.12";
.port = "80";
.probe = vk8s_probe_varnish;
}
backend varnish-8445d4f7f-k22dn {
backend vk8s_viking-service_172_17_0_13_80 {
.host = "172.17.0.13";
.port = "80";
.probe = vk8s_probe_varnish;
}
backend varnish-8445d4f7f-ldljf {
backend vk8s_default_varnish-8445d4f7f-ldljf_80 {
.host = "172.17.0.14";
.port = "80";
.probe = vk8s_probe_varnish;
......@@ -41,9 +41,9 @@ acl vk8s_cluster_acl {
sub vcl_init {
new vk8s_cluster = directors.shard();
vk8s_cluster.add_backend(varnish-8445d4f7f-z2b9p);
vk8s_cluster.add_backend(varnish-8445d4f7f-k22dn);
vk8s_cluster.add_backend(varnish-8445d4f7f-ldljf);
vk8s_cluster.add_backend(vk8s_default_varnish-8445d4f7f-z2b9p_80);
vk8s_cluster.add_backend(vk8s_viking-service_172_17_0_13_80);
vk8s_cluster.add_backend(vk8s_default_varnish-8445d4f7f-ldljf_80);
vk8s_cluster.reconfigure();
}
......
......@@ -29,7 +29,6 @@
package vcl
import (
"strconv"
"strings"
"text/template"
)
......@@ -244,16 +243,6 @@ func dirType(svc Service) string {
return svc.Director.Type.String()
}
func backendName(svc Service, addr Address) string {
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 {
if rule.Host == "" {
return mangle("any_host")
......@@ -269,15 +258,13 @@ func hostRegex(host string) string {
}
var vclFuncs = template.FuncMap{
"plusOne": func(i int) int { return i + 1 },
"dirType": func(svc Service) string { return dirType(svc) },
"hostRegex": func(host string) string { return hostRegex(host) },
"plusOne": func(i int) int { return i + 1 },
"dirType": func(svc Service) string { return dirType(svc) },
"hostRegex": func(host string) string { return hostRegex(host) },
"backendName": backendName,
"probeName": func(name string) string {
return mangle(name + "_probe")
},
"backendName": func(svc Service, addr Address) string {
return backendName(svc, addr)
},
"dirName": func(svc Service) string {
return mangle(svc.Name + "_director")
},
......
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