This repository has been archived by the owner on Jul 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
conversion.go
75 lines (71 loc) · 1.87 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package v1
import (
"fmt"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
func init() {
err := kapi.Scheme.AddDefaultingFuncs(
func(strategy *BuildStrategy) {
if (strategy != nil) && (strategy.Type == DockerBuildStrategyType) {
// initialize DockerStrategy to a default state if it's not set.
if strategy.DockerStrategy == nil {
strategy.DockerStrategy = &DockerBuildStrategy{}
}
}
},
func(obj *SourceBuildStrategy) {
if len(obj.From.Kind) == 0 {
obj.From.Kind = "ImageStreamTag"
}
},
func(obj *DockerBuildStrategy) {
if obj.From != nil && len(obj.From.Kind) == 0 {
obj.From.Kind = "ImageStreamTag"
}
},
func(obj *CustomBuildStrategy) {
if len(obj.From.Kind) == 0 {
obj.From.Kind = "ImageStreamTag"
}
},
func(obj *BuildTriggerPolicy) {
if obj.Type == ImageChangeBuildTriggerType && obj.ImageChange == nil {
obj.ImageChange = &ImageChangeTrigger{}
}
},
)
if err != nil {
panic(err)
}
// Add field conversion funcs.
err = kapi.Scheme.AddFieldLabelConversionFunc("v1", "Build",
func(label, value string) (string, string, error) {
switch label {
case "name":
return "metadata.name", value, nil
case "status":
return "status", value, nil
case "podName":
return "podName", value, nil
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)
}
err = kapi.Scheme.AddFieldLabelConversionFunc("v1", "BuildConfig",
func(label, value string) (string, string, error) {
switch label {
case "name":
return "metadata.name", value, nil
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)
}
}