This repository has been archived by the owner on Aug 12, 2020. It is now read-only.
/
annotations.go
53 lines (48 loc) · 1.48 KB
/
annotations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package envoy
import "strconv"
const (
// GatewayPrefix prefix annotation
GatewayPrefix = "gateway.appmesh.k8s.aws/"
// GatewayExpose expose boolean annotation
GatewayExpose = GatewayPrefix + "expose"
// GatewayDomain annotation with a comma separated list of public or internal domains
GatewayDomain = GatewayPrefix + "domain"
// GatewayTimeout max response duration annotation
GatewayTimeout = GatewayPrefix + "timeout"
// GatewayRetries number of retries annotation
GatewayRetries = GatewayPrefix + "retries"
// GatewayPrimary primary virtual service name annotation
GatewayPrimary = GatewayPrefix + "primary"
// GatewayCanary canary virtual service name annotation
GatewayCanary = GatewayPrefix + "canary"
// GatewayCanaryWeight traffic weight percentage annotation
GatewayCanaryWeight = GatewayPrefix + "canary-weight"
)
// CanaryFromAnnotations parses the annotations and returns a canary object
func CanaryFromAnnotations(an map[string]string) *Canary {
var primaryCluster string
var canaryCluster string
var canaryWeight int
for key, value := range an {
if key == GatewayPrimary {
primaryCluster = value
}
if key == GatewayCanary {
canaryCluster = value
}
if key == GatewayCanaryWeight {
r, err := strconv.Atoi(value)
if err == nil {
canaryWeight = r
}
}
}
if primaryCluster != "" && canaryCluster != "" {
return &Canary{
PrimaryCluster: primaryCluster,
CanaryCluster: canaryCluster,
CanaryWeight: canaryWeight,
}
}
return nil
}