This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
/
annotations.go
107 lines (97 loc) · 3.22 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package argotunnel
import (
"strconv"
"time"
"k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
annotationIngressClass = "kubernetes.io/ingress.class"
annotationIngressCompressionQuality = "argo.cloudflare.com/compression-quality"
annotationIngressHAConnections = "argo.cloudflare.com/ha-connections"
annotationIngressHeartbeatCount = "argo.cloudflare.com/heartbeat-count"
annotationIngressHeartbeatInterval = "argo.cloudflare.com/heartbeat-interval"
annotationIngressLoadBalancer = "argo.cloudflare.com/lb-pool"
annotationIngressNoChunkedEncoding = "argo.cloudflare.com/no-chunked-encoding"
annotationIngressRetries = "argo.cloudflare.com/retries"
annotationIngressTag = "argo.cloudflare.com/tag"
)
func parseIngressTunnelOptions(ing *v1beta1.Ingress) (opts []tunnelOption) {
if ingMeta, err := meta.Accessor(ing); err == nil {
if val, ok := parseMetaUint64(ingMeta, annotationIngressCompressionQuality); ok {
opts = append(opts, compressionQuality(val))
}
if val, ok := parseMetaInt(ingMeta, annotationIngressHAConnections); ok {
opts = append(opts, haConnections(val))
}
if val, ok := parseMetaUint64(ingMeta, annotationIngressHeartbeatCount); ok {
opts = append(opts, heartbeatCount(val))
}
if val, ok := parseMetaDuration(ingMeta, annotationIngressHeartbeatInterval); ok {
opts = append(opts, heartbeatInterval(val))
}
if val, ok := ingMeta.GetAnnotations()[annotationIngressLoadBalancer]; ok {
opts = append(opts, lbPool(val))
}
if val, ok := parseMetaBool(ingMeta, annotationIngressNoChunkedEncoding); ok {
opts = append(opts, disableChunkedEncoding(val))
}
if val, ok := parseMetaUint(ingMeta, annotationIngressRetries); ok {
opts = append(opts, retries(val))
}
if val, ok := ingMeta.GetAnnotations()[annotationIngressTag]; ok {
opts = append(opts, tags(val))
}
}
return
}
func parseMetaBool(obj metav1.Object, key string) (val bool, ok bool) {
if s, in := obj.GetAnnotations()[key]; in {
switch s {
case "true":
val, ok = true, true
case "false":
val, ok = false, true
}
}
return
}
func parseMetaDuration(obj metav1.Object, key string) (val time.Duration, ok bool) {
if s, in := obj.GetAnnotations()[key]; in {
if d, err := time.ParseDuration(s); err == nil {
val, ok = d, true
}
}
return
}
func parseMetaInt(obj metav1.Object, key string) (val int, ok bool) {
if s, in := obj.GetAnnotations()[key]; in {
if v, err := strconv.ParseInt(s, 10, 32); err == nil {
val, ok = int(v), true
}
}
return
}
func parseMetaUint(obj metav1.Object, key string) (val uint, ok bool) {
if s, in := obj.GetAnnotations()[key]; in {
if v, err := strconv.ParseUint(s, 10, 32); err == nil {
val, ok = uint(v), true
}
}
return
}
func parseMetaUint64(obj metav1.Object, key string) (val uint64, ok bool) {
if s, in := obj.GetAnnotations()[key]; in {
if v, err := strconv.ParseUint(s, 10, 64); err == nil {
val, ok = uint64(v), true
}
}
return
}
func parseIngressClass(ing *v1beta1.Ingress) (val string, ok bool) {
if ingMeta, err := meta.Accessor(ing); err == nil {
val, ok = ingMeta.GetAnnotations()[annotationIngressClass]
}
return
}