-
Notifications
You must be signed in to change notification settings - Fork 90
/
ingress_config.go
63 lines (59 loc) · 1.8 KB
/
ingress_config.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
package ingress
import (
kotsv1beta1 "github.com/replicatedhq/kots/kotskinds/apis/kots/v1beta1"
kotsadmtypes "github.com/replicatedhq/kots/pkg/kotsadm/types"
extensions "k8s.io/api/extensions/v1beta1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
func IngressFromConfig(ingressConfig kotsv1beta1.IngressResourceConfig, name string, serviceName string, servicePort int, additionalLabels map[string]string) *extensionsv1beta1.Ingress {
ingressTLS := []extensions.IngressTLS{}
if ingressConfig.TLSSecretName != "" {
tls := extensions.IngressTLS{
SecretName: ingressConfig.TLSSecretName,
}
if ingressConfig.Host != "" {
tls.Hosts = append(tls.Hosts, ingressConfig.Host)
}
ingressTLS = append(ingressTLS, tls)
}
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-body-size": "100m",
}
for k, v := range ingressConfig.Annotations {
annotations[k] = v
}
return &extensionsv1beta1.Ingress{
TypeMeta: metav1.TypeMeta{
APIVersion: "extensions/v1beta1",
Kind: "Ingress",
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: kotsadmtypes.GetKotsadmLabels(additionalLabels),
Annotations: annotations,
},
Spec: extensionsv1beta1.IngressSpec{
Rules: []extensionsv1beta1.IngressRule{
{
Host: ingressConfig.Host,
IngressRuleValue: extensionsv1beta1.IngressRuleValue{
HTTP: &extensionsv1beta1.HTTPIngressRuleValue{
Paths: []extensionsv1beta1.HTTPIngressPath{
{
Path: ingressConfig.Path,
Backend: extensionsv1beta1.IngressBackend{
ServiceName: serviceName,
ServicePort: intstr.FromInt(servicePort),
},
},
},
},
},
},
},
TLS: ingressTLS,
},
}
}