-
Notifications
You must be signed in to change notification settings - Fork 11
/
ingress.go
88 lines (73 loc) · 2.33 KB
/
ingress.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
package controllers
import (
"fmt"
"github.com/jitsi-contrib/jitsi-kubernetes-operator/api/v1alpha1"
"github.com/presslabs/controller-util/pkg/syncer"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
func NewIngressSyncer(jitsi *v1alpha1.Jitsi, c client.Client) syncer.Interface {
obj := &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-web", jitsi.Name),
Namespace: jitsi.Namespace,
},
}
return syncer.NewObjectSyncer("Ingress", jitsi, obj, c, func() error {
pathType := networkingv1.PathTypePrefix
obj.Annotations = jitsi.Spec.Ingress.Annotations
// with this nginx ingress becomes a requierement
// TODO make nginx ingress an option
obj.Annotations["nginx.ingress.kubernetes.io/server-snippet"] = fmt.Sprintf(`add_header X-Jitsi-Shard shard;
location = /xmpp-websocket {
proxy_pass http://%s-prosody.%s:5280/xmpp-websocket;
proxy_http_version 1.1;
proxy_set_header Connection "upgrade";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host %s;
proxy_set_header X-Forwarded-For $remote_addr;
tcp_nodelay on;
}
location ~ ^/colibri-ws/([a-zA-Z0-9-\.]+)/(.*) {
proxy_pass http://$1:9090/colibri-ws/$1/$2$is_args$args;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
tcp_nodelay on;
}`, jitsi.Name, jitsi.Namespace, jitsi.Spec.Domain)
obj.Labels = jitsi.ComponentLabels("web")
obj.Spec.Rules = []networkingv1.IngressRule{
{
Host: jitsi.Spec.Domain,
IngressRuleValue: networkingv1.IngressRuleValue{
HTTP: &networkingv1.HTTPIngressRuleValue{
Paths: []networkingv1.HTTPIngressPath{
{
Path: "/",
PathType: &pathType,
Backend: networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{
Name: fmt.Sprintf("%s-web", jitsi.Name),
Port: networkingv1.ServiceBackendPort{
Name: "http",
},
},
},
},
},
},
},
},
}
if jitsi.Spec.Ingress.TLS {
obj.Spec.TLS = []networkingv1.IngressTLS{
{
Hosts: []string{jitsi.Spec.Domain},
SecretName: jitsi.Spec.Domain + "-tls",
},
}
}
return nil
})
}