forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conversion.go
189 lines (173 loc) · 6.49 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package v1
import (
"k8s.io/kubernetes/pkg/conversion"
"k8s.io/kubernetes/pkg/runtime"
oapi "github.com/openshift/origin/pkg/api"
newer "github.com/openshift/origin/pkg/build/api"
buildutil "github.com/openshift/origin/pkg/build/util"
imageapi "github.com/openshift/origin/pkg/image/api"
)
func Convert_v1_BuildConfig_To_api_BuildConfig(in *BuildConfig, out *newer.BuildConfig, s conversion.Scope) error {
if err := autoConvert_v1_BuildConfig_To_api_BuildConfig(in, out, s); err != nil {
return err
}
newTriggers := []newer.BuildTriggerPolicy{}
// Strip off any default imagechange triggers where the buildconfig's
// "from" is not an ImageStreamTag, because those triggers
// will never be invoked.
imageRef := buildutil.GetInputReference(out.Spec.Strategy)
hasIST := imageRef != nil && imageRef.Kind == "ImageStreamTag"
for _, trigger := range out.Spec.Triggers {
if trigger.Type != newer.ImageChangeBuildTriggerType {
newTriggers = append(newTriggers, trigger)
continue
}
if (trigger.ImageChange == nil || trigger.ImageChange.From == nil) && !hasIST {
continue
}
newTriggers = append(newTriggers, trigger)
}
out.Spec.Triggers = newTriggers
return nil
}
func Convert_v1_SourceBuildStrategy_To_api_SourceBuildStrategy(in *SourceBuildStrategy, out *newer.SourceBuildStrategy, s conversion.Scope) error {
if err := autoConvert_v1_SourceBuildStrategy_To_api_SourceBuildStrategy(in, out, s); err != nil {
return err
}
switch in.From.Kind {
case "ImageStream":
out.From.Kind = "ImageStreamTag"
out.From.Name = imageapi.JoinImageStreamTag(in.From.Name, "")
}
return nil
}
func Convert_v1_DockerBuildStrategy_To_api_DockerBuildStrategy(in *DockerBuildStrategy, out *newer.DockerBuildStrategy, s conversion.Scope) error {
if err := autoConvert_v1_DockerBuildStrategy_To_api_DockerBuildStrategy(in, out, s); err != nil {
return err
}
if in.From != nil {
switch in.From.Kind {
case "ImageStream":
out.From.Kind = "ImageStreamTag"
out.From.Name = imageapi.JoinImageStreamTag(in.From.Name, "")
}
}
return nil
}
func Convert_v1_CustomBuildStrategy_To_api_CustomBuildStrategy(in *CustomBuildStrategy, out *newer.CustomBuildStrategy, s conversion.Scope) error {
if err := autoConvert_v1_CustomBuildStrategy_To_api_CustomBuildStrategy(in, out, s); err != nil {
return err
}
switch in.From.Kind {
case "ImageStream":
out.From.Kind = "ImageStreamTag"
out.From.Name = imageapi.JoinImageStreamTag(in.From.Name, "")
}
return nil
}
func Convert_v1_BuildOutput_To_api_BuildOutput(in *BuildOutput, out *newer.BuildOutput, s conversion.Scope) error {
if err := autoConvert_v1_BuildOutput_To_api_BuildOutput(in, out, s); err != nil {
return err
}
if in.To != nil && (in.To.Kind == "ImageStream" || len(in.To.Kind) == 0) {
out.To.Kind = "ImageStreamTag"
out.To.Name = imageapi.JoinImageStreamTag(in.To.Name, "")
}
return nil
}
func Convert_v1_BuildTriggerPolicy_To_api_BuildTriggerPolicy(in *BuildTriggerPolicy, out *newer.BuildTriggerPolicy, s conversion.Scope) error {
if err := autoConvert_v1_BuildTriggerPolicy_To_api_BuildTriggerPolicy(in, out, s); err != nil {
return err
}
switch in.Type {
case ImageChangeBuildTriggerTypeDeprecated:
out.Type = newer.ImageChangeBuildTriggerType
case GenericWebHookBuildTriggerTypeDeprecated:
out.Type = newer.GenericWebHookBuildTriggerType
case GitHubWebHookBuildTriggerTypeDeprecated:
out.Type = newer.GitHubWebHookBuildTriggerType
}
return nil
}
func Convert_api_SourceRevision_To_v1_SourceRevision(in *newer.SourceRevision, out *SourceRevision, s conversion.Scope) error {
if err := autoConvert_api_SourceRevision_To_v1_SourceRevision(in, out, s); err != nil {
return err
}
out.Type = BuildSourceGit
return nil
}
func Convert_api_BuildSource_To_v1_BuildSource(in *newer.BuildSource, out *BuildSource, s conversion.Scope) error {
if err := autoConvert_api_BuildSource_To_v1_BuildSource(in, out, s); err != nil {
return err
}
switch {
// It is legal for a buildsource to have both a git+dockerfile source, but in v1 that was represented
// as type git.
case in.Git != nil:
out.Type = BuildSourceGit
// It is legal for a buildsource to have both a binary+dockerfile source, but in v1 that was represented
// as type binary.
case in.Binary != nil:
out.Type = BuildSourceBinary
case in.Dockerfile != nil:
out.Type = BuildSourceDockerfile
case len(in.Images) > 0:
out.Type = BuildSourceImage
default:
out.Type = BuildSourceNone
}
return nil
}
func Convert_api_BuildStrategy_To_v1_BuildStrategy(in *newer.BuildStrategy, out *BuildStrategy, s conversion.Scope) error {
if err := autoConvert_api_BuildStrategy_To_v1_BuildStrategy(in, out, s); err != nil {
return err
}
switch {
case in.SourceStrategy != nil:
out.Type = SourceBuildStrategyType
case in.DockerStrategy != nil:
out.Type = DockerBuildStrategyType
case in.CustomStrategy != nil:
out.Type = CustomBuildStrategyType
case in.JenkinsPipelineStrategy != nil:
out.Type = JenkinsPipelineBuildStrategyType
default:
out.Type = ""
}
return nil
}
func addConversionFuncs(scheme *runtime.Scheme) error {
if err := scheme.AddConversionFuncs(
Convert_v1_BuildConfig_To_api_BuildConfig,
Convert_api_BuildConfig_To_v1_BuildConfig,
Convert_v1_SourceBuildStrategy_To_api_SourceBuildStrategy,
Convert_api_SourceBuildStrategy_To_v1_SourceBuildStrategy,
Convert_v1_DockerBuildStrategy_To_api_DockerBuildStrategy,
Convert_api_DockerBuildStrategy_To_v1_DockerBuildStrategy,
Convert_v1_CustomBuildStrategy_To_api_CustomBuildStrategy,
Convert_api_CustomBuildStrategy_To_v1_CustomBuildStrategy,
Convert_v1_BuildOutput_To_api_BuildOutput,
Convert_api_BuildOutput_To_v1_BuildOutput,
Convert_v1_BuildTriggerPolicy_To_api_BuildTriggerPolicy,
Convert_api_BuildTriggerPolicy_To_v1_BuildTriggerPolicy,
Convert_v1_SourceRevision_To_api_SourceRevision,
Convert_api_SourceRevision_To_v1_SourceRevision,
Convert_v1_BuildSource_To_api_BuildSource,
Convert_api_BuildSource_To_v1_BuildSource,
Convert_v1_BuildStrategy_To_api_BuildStrategy,
Convert_api_BuildStrategy_To_v1_BuildStrategy,
); err != nil {
return err
}
if err := scheme.AddFieldLabelConversionFunc("v1", "Build",
oapi.GetFieldLabelConversionFunc(newer.BuildToSelectableFields(&newer.Build{}), map[string]string{"name": "metadata.name"}),
); err != nil {
return err
}
if err := scheme.AddFieldLabelConversionFunc("v1", "BuildConfig",
oapi.GetFieldLabelConversionFunc(newer.BuildConfigToSelectableFields(&newer.BuildConfig{}), map[string]string{"name": "metadata.name"}),
); err != nil {
return err
}
return nil
}