-
Notifications
You must be signed in to change notification settings - Fork 62
/
route.go
50 lines (42 loc) · 1.21 KB
/
route.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
package routes
import (
routev1 "github.com/openshift/api/route/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
)
func NewRouteDefinitionForCR(existing *routev1.Route, namespacedName types.NamespacedName, labels map[string]string, targetServiceName string, targetPortName string, passthroughTLS bool) *routev1.Route {
var desired *routev1.Route = nil
if existing == nil {
desired = &routev1.Route{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Route",
},
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Name: targetServiceName + "-rte",
Namespace: namespacedName.Namespace,
},
Spec: routev1.RouteSpec{},
}
} else {
desired = existing
}
desired.Spec.Port = &routev1.RoutePort{
TargetPort: intstr.FromString(targetPortName),
}
desired.Spec.To = routev1.RouteTargetReference{
Kind: "Service",
Name: targetServiceName,
}
if passthroughTLS {
desired.Spec.TLS = &routev1.TLSConfig{
Termination: routev1.TLSTerminationPassthrough,
InsecureEdgeTerminationPolicy: routev1.InsecureEdgeTerminationPolicyNone,
}
} else {
desired.Spec.TLS = nil
}
return desired
}