-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
build.go
90 lines (79 loc) · 2.74 KB
/
build.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
package legacy
import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/kubernetes/pkg/apis/core"
buildv1 "github.com/openshift/api/build/v1"
"github.com/openshift/origin/pkg/api/apihelpers"
"github.com/openshift/origin/pkg/build/apis/build"
buildv1helpers "github.com/openshift/origin/pkg/build/apis/build/v1"
)
// InstallLegacyBuild this looks like a lot of duplication, but the code in the individual versions is living and may
// change. The code here should never change and needs to allow the other code to move independently.
func InstallInternalLegacyBuild(scheme *runtime.Scheme) {
InstallExternalLegacyBuild(scheme)
schemeBuilder := runtime.NewSchemeBuilder(
addUngroupifiedInternalBuildTypes,
core.AddToScheme,
addLegacyBuildFieldSelectorKeyConversions,
buildv1helpers.AddConversionFuncs,
buildv1helpers.RegisterDefaults,
buildv1helpers.RegisterConversions,
)
utilruntime.Must(schemeBuilder.AddToScheme(scheme))
}
func InstallExternalLegacyBuild(scheme *runtime.Scheme) {
schemeBuilder := runtime.NewSchemeBuilder(
addUngroupifiedBuildTypes,
corev1.AddToScheme,
)
utilruntime.Must(schemeBuilder.AddToScheme(scheme))
}
func addUngroupifiedBuildTypes(scheme *runtime.Scheme) error {
types := []runtime.Object{
&buildv1.Build{},
&buildv1.BuildList{},
&buildv1.BuildConfig{},
&buildv1.BuildConfigList{},
&buildv1.BuildLog{},
&buildv1.BuildRequest{},
&buildv1.BuildLogOptions{},
&buildv1.BinaryBuildRequestOptions{},
}
scheme.AddKnownTypes(GroupVersion, types...)
return nil
}
func addUngroupifiedInternalBuildTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(InternalGroupVersion,
&build.Build{},
&build.BuildList{},
&build.BuildConfig{},
&build.BuildConfigList{},
&build.BuildLog{},
&build.BuildRequest{},
&build.BuildLogOptions{},
&build.BinaryBuildRequestOptions{},
)
return nil
}
func addLegacyBuildFieldSelectorKeyConversions(scheme *runtime.Scheme) error {
if err := scheme.AddFieldLabelConversionFunc(GroupVersion.WithKind("Build"), legacyBuildFieldSelectorKeyConversionFunc); err != nil {
return err
}
if err := scheme.AddFieldLabelConversionFunc(GroupVersion.WithKind("BuildConfig"), apihelpers.LegacyMetaV1FieldSelectorConversionWithName); err != nil {
return err
}
return nil
}
// because field selectors can vary in support by version they are exposed under, we have one function for each
// groupVersion we're registering for
func legacyBuildFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) {
switch label {
case "status",
"podName":
return label, value, nil
default:
return apihelpers.LegacyMetaV1FieldSelectorConversionWithName(label, value)
}
}