-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.go
78 lines (65 loc) · 3.26 KB
/
util.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
package service
import (
"fmt"
"strings"
saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1"
"github.com/3scale/saas-operator/pkg/basereconciler"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
// ELBServiceAnnotations returns annotations for services exposed through AWS Classic LoadBalancers
func ELBServiceAnnotations(cfg saasv1alpha1.LoadBalancerSpec, hostnames []string) map[string]string {
annotations := map[string]string{
"external-dns.alpha.kubernetes.io/hostname": strings.Join(hostnames, ","),
"service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled": fmt.Sprintf("%t", *cfg.CrossZoneLoadBalancingEnabled),
"service.beta.kubernetes.io/aws-load-balancer-connection-draining-enabled": fmt.Sprintf("%t", *cfg.ConnectionDrainingEnabled),
"service.beta.kubernetes.io/aws-load-balancer-connection-draining-timeout": fmt.Sprintf("%d", *cfg.ConnectionDrainingTimeout),
"service.beta.kubernetes.io/aws-load-balancer-healthcheck-healthy-threshold": fmt.Sprintf("%d", *cfg.HealthcheckHealthyThreshold),
"service.beta.kubernetes.io/aws-load-balancer-healthcheck-unhealthy-threshold": fmt.Sprintf("%d", *cfg.HealthcheckUnhealthyThreshold),
"service.beta.kubernetes.io/aws-load-balancer-healthcheck-interval": fmt.Sprintf("%d", *cfg.HealthcheckInterval),
"service.beta.kubernetes.io/aws-load-balancer-healthcheck-timeout": fmt.Sprintf("%d", *cfg.HealthcheckTimeout),
}
if *cfg.ProxyProtocol {
annotations["service.beta.kubernetes.io/aws-load-balancer-proxy-protocol"] = "*"
}
return annotations
}
// NLBServiceAnnotations returns annotations for services exposed through AWS Network LoadBalancers
func NLBServiceAnnotations(cfg saasv1alpha1.NLBLoadBalancerSpec, hostnames []string) map[string]string {
annotations := map[string]string{
"service.beta.kubernetes.io/aws-load-balancer-type": "nlb",
"external-dns.alpha.kubernetes.io/hostname": strings.Join(hostnames, ","),
"service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled": fmt.Sprintf("%t", *cfg.CrossZoneLoadBalancingEnabled),
}
if *cfg.ProxyProtocol {
annotations["aws-nlb-helper.3scale.net/enable-targetgroups-proxy-protocol"] = "true"
}
if cfg.EIPAllocations != nil {
annotations["service.beta.kubernetes.io/aws-load-balancer-eip-allocations"] = strings.Join(cfg.EIPAllocations, ",")
}
return annotations
}
// TCPPort returns a TCP corev1.ServicePort
func TCPPort(name string, port int32, targetPort intstr.IntOrString) corev1.ServicePort {
return corev1.ServicePort{
Name: name,
Port: port,
TargetPort: targetPort,
Protocol: corev1.ProtocolTCP,
}
}
// Ports returns a list of corev1.ServicePort
func Ports(ports ...corev1.ServicePort) []corev1.ServicePort {
list := []corev1.ServicePort{}
return append(list, ports...)
}
// Excludes generates the list of excluded paths for a Service resource
func Excludes(fn basereconciler.GeneratorFunction) []string {
svc := fn().(*corev1.Service)
paths := []string{}
paths = append(paths, "/spec/clusterIP")
for idx := range svc.Spec.Ports {
paths = append(paths, fmt.Sprintf("/spec/ports/%d/nodePort", idx))
}
return paths
}