Commit e380c936 authored by Geoff Simmons's avatar Geoff Simmons

Support self-sharding with conditions under helm deployments.

parent 075c5b26
...@@ -34,49 +34,107 @@ spec: ...@@ -34,49 +34,107 @@ spec:
self-sharding: self-sharding:
type: object type: object
properties: properties:
max-secondary-ttl: shard:
type: string
pattern: '^\d+(\.\d+)?(ms|[smhdwy])$'
primaryOnly:
type: boolean
key:
type: string
pattern: "^client\\.identity$|^req\\.(url|http\\.[a-zA-Z0-9!#$%&'*+.^_`|~-]+)$"
digest:
type: string
enum:
- CRC32
- ICRC32
- MD5
- RS
- SHA1
- SHA224
- SHA256
- SHA384
- SHA512
- SHA3_224
- SHA3_256
- SHA3_512
probe:
type: object type: object
properties: properties:
timeout: max-secondary-ttl:
type: string type: string
pattern: '^\d+(\.\d+)?(ms|[smhdwy])$' pattern: '^\d+(\.\d+)?(ms|[smhdwy])$'
interval: primaryOnly:
type: boolean
key:
type: string type: string
pattern: '^\d+(\.\d+)?(ms|[smhdwy])$' pattern: "^client\\.identity$|^req\\.(url|http\\.[a-zA-Z0-9!#$%&'*+.^_`|~-]+)$"
initial: digest:
type: integer type: string
minimum: 0 enum:
window: - CRC32
type: integer - ICRC32
minimum: 0 - MD5
maximum: 64 - RS
threshold: - SHA1
type: integer - SHA224
minimum: 0 - SHA256
maximum: 64 - SHA384
- SHA512
- SHA3_224
- SHA3_256
- SHA3_512
probe:
type: object
properties:
timeout:
type: string
pattern: '^\d+(\.\d+)?(ms|[smhdwy])$'
interval:
type: string
pattern: '^\d+(\.\d+)?(ms|[smhdwy])$'
initial:
type: integer
minimum: 0
window:
type: integer
minimum: 0
maximum: 64
threshold:
type: integer
minimum: 0
maximum: 64
conditions:
type: array
minItems: 1
items:
type: object
required:
- comparand
properties:
comparand:
type: string
pattern: "^req\\.(url|method|proto|http\\.[a-zA-Z0-9!#$%&'*+.^_`|~-]+)$"
compare:
type: string
enum:
- equal
- not-equal
- match
- not-match
- prefix
- not-prefix
- exists
- not-exists
values:
type: array
minItems: 1
items:
type: string
match-flags:
type: object
properties:
max-mem:
type: integer
minimum: 0
anchor:
type: string
enum:
- none
- start
- both
utf8:
type: boolean
posix-syntax:
type: boolean
longest-match:
type: boolean
literal:
type: boolean
never-capture:
type: boolean
case-sensitive:
type: boolean
perl-classes:
type: boolean
word-boundary:
type: boolean
auth: auth:
type: array type: array
minItems: 1 minItems: 1
......
...@@ -58,6 +58,10 @@ deploy-primary-only-by-clientid-helm: ...@@ -58,6 +58,10 @@ deploy-primary-only-by-clientid-helm:
@helm install viking-ingress-primary-only-by-clientid $(CHARTDIR)/viking-test-app \ @helm install viking-ingress-primary-only-by-clientid $(CHARTDIR)/viking-test-app \
--values values-primary-only-by-clientid.yaml --values values-primary-only-by-clientid.yaml
deploy-shard-conditions-helm:
@helm install viking-ingress-shard-conditions $(CHARTDIR)/viking-test-app \
--values values-shard-conditions.yaml
deploy-cafe-kubectl: deploy-cafe-kubectl:
@kubectl apply -f $(mkdir)/../hello/cafe.yaml @kubectl apply -f $(mkdir)/../hello/cafe.yaml
@kubectl apply -f $(mkdir)/../hello/cafe-ingress.yaml @kubectl apply -f $(mkdir)/../hello/cafe-ingress.yaml
...@@ -115,6 +119,10 @@ undeploy-primary-only-by-clientid-helm: ...@@ -115,6 +119,10 @@ undeploy-primary-only-by-clientid-helm:
@helm uninstall viking-ingress-primary-only-by-clientid @helm uninstall viking-ingress-primary-only-by-clientid
$(MAKE) wait $(MAKE) wait
undeploy-shard-conditions-helm:
@helm uninstall viking-ingress-shard-conditions
$(MAKE) wait
undeploy-cafe-kubectl: undeploy-cafe-kubectl:
@kubectl delete -f $(mkdir)/../hello/cafe-ingress.yaml @kubectl delete -f $(mkdir)/../hello/cafe-ingress.yaml
@kubectl delete -f $(mkdir)/../hello/cafe.yaml @kubectl delete -f $(mkdir)/../hello/cafe.yaml
...@@ -182,6 +190,8 @@ deploy-shard-by-key: deploy-shard-by-key-helm ...@@ -182,6 +190,8 @@ deploy-shard-by-key: deploy-shard-by-key-helm
undeploy-shard-by-key: undeploy-shard-by-key-helm undeploy-shard-by-key: undeploy-shard-by-key-helm
deploy-primary-only-by-clientid: deploy-primary-only-by-clientid-helm deploy-primary-only-by-clientid: deploy-primary-only-by-clientid-helm
undeploy-primary-only-by-clientid: undeploy-primary-only-by-clientid-helm undeploy-primary-only-by-clientid: undeploy-primary-only-by-clientid-helm
deploy-shard-conditions: deploy-shard-conditions-helm
undeploy-shard-conditions: undeploy-shard-conditions-helm
endif endif
ifeq ($(EXAMPLE),self-sharding) ifeq ($(EXAMPLE),self-sharding)
......
...@@ -19,11 +19,12 @@ ingress: ...@@ -19,11 +19,12 @@ ingress:
vikingAdmSvc: varnish-ingress-admin vikingAdmSvc: varnish-ingress-admin
selfSharding: selfSharding:
primaryOnly: true shard:
key: client.identity primaryOnly: true
probe: key: client.identity
timeout: 6s probe:
interval: 6s timeout: 6s
initial: 2 interval: 6s
window: 4 initial: 2
threshold: 3 window: 4
threshold: 3
...@@ -19,10 +19,11 @@ ingress: ...@@ -19,10 +19,11 @@ ingress:
vikingAdmSvc: varnish-ingress-admin vikingAdmSvc: varnish-ingress-admin
selfSharding: selfSharding:
primaryOnly: true shard:
probe: primaryOnly: true
timeout: 6s probe:
interval: 6s timeout: 6s
initial: 2 interval: 6s
window: 4 initial: 2
threshold: 3 window: 4
threshold: 3
...@@ -19,10 +19,11 @@ ingress: ...@@ -19,10 +19,11 @@ ingress:
vikingAdmSvc: varnish-ingress-admin vikingAdmSvc: varnish-ingress-admin
selfSharding: selfSharding:
max-secondary-ttl: 2m shard:
probe: max-secondary-ttl: 2m
timeout: 6s probe:
interval: 6s timeout: 6s
initial: 2 interval: 6s
window: 4 initial: 2
threshold: 3 window: 4
threshold: 3
...@@ -19,6 +19,7 @@ ingress: ...@@ -19,6 +19,7 @@ ingress:
vikingAdmSvc: varnish-ingress-admin vikingAdmSvc: varnish-ingress-admin
selfSharding: selfSharding:
primaryOnly: true shard:
key: req.http.Host primaryOnly: true
digest: SHA3_512 key: req.http.Host
digest: SHA3_512
...@@ -19,5 +19,6 @@ ingress: ...@@ -19,5 +19,6 @@ ingress:
vikingAdmSvc: varnish-ingress-admin vikingAdmSvc: varnish-ingress-admin
selfSharding: selfSharding:
primaryOnly: true shard:
key: req.http.Host primaryOnly: true
key: req.http.Host
...@@ -19,5 +19,6 @@ ingress: ...@@ -19,5 +19,6 @@ ingress:
vikingAdmSvc: varnish-ingress-admin vikingAdmSvc: varnish-ingress-admin
selfSharding: selfSharding:
primaryOnly: true shard:
key: req.url primaryOnly: true
key: req.url
apps:
coffee:
image: nginxdemos/hello:plain-text
replicas: 2
tea:
image: nginxdemos/hello:plain-text
replicas: 3
ingress:
name: cafe-ingress
rules:
- host: cafe.example.com
paths:
- path: /tea
app: tea
- path: /coffee
app: coffee
vikingAdmSvc: varnish-ingress-admin
selfSharding:
conditions:
- comparand: req.url
compare: prefix
values:
- /foo/
shard:
primaryOnly: true
key: client.identity
probe:
timeout: 6s
interval: 6s
initial: 2
window: 4
threshold: 3
...@@ -547,11 +547,14 @@ templates: ...@@ -547,11 +547,14 @@ templates:
import blob; import blob;
import blobdigest; import blobdigest;
import taskvar; import taskvar;
import re2;
import selector;
probe vk8s_probe_varnish { probe vk8s_probe_varnish {
.request = "HEAD /vk8s_cluster_health HTTP/1.1" .request = "HEAD /vk8s_cluster_health HTTP/1.1"
"Host: vk8s_cluster" "Host: vk8s_cluster"
"Connection: close"; "Connection: close";
{{- if .Probe }}
{{- if .Probe.Timeout}} {{- if .Probe.Timeout}}
.timeout = {{.Probe.Timeout}}; .timeout = {{.Probe.Timeout}};
{{- end}} {{- end}}
...@@ -567,6 +570,7 @@ templates: ...@@ -567,6 +570,7 @@ templates:
{{- if .Probe.Threshold}} {{- if .Probe.Threshold}}
.threshold = {{.Probe.Threshold}}; .threshold = {{.Probe.Threshold}};
{{- end}} {{- end}}
{{- end}}
} }
{{range $node := .Nodes -}} {{range $node := .Nodes -}}
...@@ -596,19 +600,45 @@ templates: ...@@ -596,19 +600,45 @@ templates:
{{ if .PrimaryOnly -}} {{ if .PrimaryOnly -}}
new vk8s_cluster_primary = taskvar.backend(); new vk8s_cluster_primary = taskvar.backend();
{{- end }} {{- end }}
{{range $cidx, $c := .Conditions -}}
{{if condNeedsMatcher $c -}}
new {{condMatcher $cidx}} = {{vmod $c.Compare}}.set({{flags $c}});
{{- range $val := $c.Values}}
{{condMatcher $cidx}}.add("{{$val}}");
{{- end -}}
{{end -}}
{{end -}}
} }
sub vcl_recv { sub vcl_recv {
{{ if .PrimaryOnly -}} {{ if .PrimaryOnly -}}
{{- digest_update 'c' . }} {{ if .Conditions -}}
vk8s_cluster_primary.set(vk8s_cluster.backend(resolve=NOW if (
{{- key 'c' .}})); {{- range $cidx, $cond := .Conditions}}
if (remote.ip !~ vk8s_cluster_acl {{- if ne $cidx 0}} &&
&& "" + vk8s_cluster_primary.get() != server.identity) { {{end}}
set req.backend_hint = vk8s_cluster_primary.get(); {{- if .Negate}}! {{end}}
return (pipe); {{- if condNeedsMatcher $cond}}
} {{- condMatcher $cidx}}.{{match .Compare}}({{.Comparand}})
else {{ end }}if (remote.ip ~ vk8s_cluster_acl) { {{- else if exists .Compare}}
{{- .Comparand}}
{{- else}}
{{- .Comparand}} {{cmpRelation .Compare .Negate}} {{value $cond}}
{{- end}}
{{- end -}}
) {
{{ end -}}
{{- digest_update 'c' . }}
vk8s_cluster_primary.set(vk8s_cluster.backend(resolve=NOW
{{- key 'c' .}}));
if (remote.ip !~ vk8s_cluster_acl
&& "" + vk8s_cluster_primary.get() != server.identity) {
set req.backend_hint = vk8s_cluster_primary.get();
return (pipe);
}
{{ if .Conditions }}}{{ end -}}
{{ end -}}
if (remote.ip ~ vk8s_cluster_acl) {
if (req.http.Host == "vk8s_cluster") { if (req.http.Host == "vk8s_cluster") {
if (req.url == "/vk8s_cluster_health") { if (req.url == "/vk8s_cluster_health") {
return (synth(200)); return (synth(200));
...@@ -631,7 +661,19 @@ templates: ...@@ -631,7 +661,19 @@ templates:
sub vcl_backend_fetch { sub vcl_backend_fetch {
{{- digest_update 'b' . }} {{- digest_update 'b' . }}
vk8s_cluster_param.set({{ key 'b' .}}); vk8s_cluster_param.set({{ key 'b' .}});
if (bereq.retries == 0 if (
{{- range $cidx, $cond := .Conditions}}
{{- if .Negate}}! {{end}}
{{- if condNeedsMatcher $cond}}
{{- condMatcher $cidx}}.{{match .Compare}}({{.Comparand}})
{{- else if exists .Compare}}
{{- .Comparand}}
{{- else}}
{{- .Comparand}} {{cmpRelation .Compare .Negate}} {{value $cond}}
{{- end}}
&&
{{ end -}}
bereq.retries == 0
&& !bereq.uncacheable && !bereq.uncacheable
&& remote.ip !~ vk8s_cluster_acl && remote.ip !~ vk8s_cluster_acl
&& "" + vk8s_cluster.backend(resolve=NOW) != server.identity) { && "" + vk8s_cluster.backend(resolve=NOW) != server.identity) {
......
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