forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conversion.go
58 lines (52 loc) · 1.33 KB
/
conversion.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
package v1beta3
import (
"fmt"
"k8s.io/kubernetes/pkg/runtime"
)
func addConversionFuncs(scheme *runtime.Scheme) {
err := scheme.AddDefaultingFuncs(
func(obj *RouteSpec) {
if len(obj.To.Kind) == 0 {
obj.To.Kind = "Service"
}
},
func(obj *TLSConfig) {
if len(obj.Termination) == 0 && len(obj.DestinationCACertificate) == 0 {
obj.Termination = TLSTerminationEdge
}
switch obj.Termination {
case TLSTerminationType("Reencrypt"):
obj.Termination = TLSTerminationReencrypt
case TLSTerminationType("Edge"):
obj.Termination = TLSTerminationEdge
case TLSTerminationType("Passthrough"):
obj.Termination = TLSTerminationPassthrough
}
},
)
if err != nil {
panic(err)
}
err = scheme.AddConversionFuncs()
if err != nil {
panic(err)
}
// Add field conversion funcs.
err = scheme.AddFieldLabelConversionFunc("v1beta3", "Route",
func(label, value string) (string, string, error) {
switch label {
case "metadata.name",
"spec.host",
"spec.path",
"spec.to.name":
return label, value, nil
// This is for backwards compatibility with old v1 clients which send spec.host
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
}
})
if err != nil {
// If one of the conversion functions is malformed, detect it immediately.
panic(err)
}
}