Skip to content

Commit 65f7c04

Browse files
Merge pull request #20372 from deads2k/api-04-build
switch remaining API groups to new scheme install
2 parents bb11f51 + cf3c5d3 commit 65f7c04

File tree

173 files changed

+1892
-1433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+1892
-1433
lines changed

cmd/openshift/openshift.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func main() {
2929
defer serviceability.BehaviorOnPanic(os.Getenv("OPENSHIFT_ON_PANIC"), version.Get())()
3030
defer serviceability.Profile(os.Getenv("OPENSHIFT_PROFILE")).Stop()
3131

32-
legacy.LegacyInstallAll(legacyscheme.Scheme)
32+
legacy.InstallLegacyInternalAll(legacyscheme.Scheme)
3333

3434
rand.Seed(time.Now().UTC().UnixNano())
3535
if len(os.Getenv("GOMAXPROCS")) == 0 {

examples/examples_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
)
3434

3535
func init() {
36-
legacy.LegacyInstallAll(legacyscheme.Scheme)
36+
legacy.InstallLegacyInternalAll(legacyscheme.Scheme)
3737
}
3838

3939
func walkJSONFiles(inDir string, fn func(name, path string, data []byte)) error {

hack/import-restrictions.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@
225225
"allowedImportPackageRoots": [
226226
"vendor/k8s.io/apimachinery",
227227
"vendor/k8s.io/api",
228-
"vendor/github.com/openshift/api",
229-
"github.com/openshift/origin/pkg/api/apihelpers"
228+
"vendor/github.com/openshift/api"
230229
],
231230
"allowedImportPackages": [
232-
"vendor/k8s.io/kubernetes/pkg/apis/core"
231+
"vendor/k8s.io/kubernetes/pkg/apis/core",
232+
"vendor/k8s.io/kubernetes/pkg/apis/core/v1"
233233
]
234234
},
235235

@@ -261,7 +261,10 @@
261261
"github.com/openshift/origin/pkg/api/apihelpers"
262262
],
263263
"allowedImportPackages": [
264-
"vendor/k8s.io/kubernetes/pkg/apis/core"
264+
"vendor/k8s.io/kubernetes/pkg/apis/core",
265+
"vendor/github.com/davecgh/go-spew/spew",
266+
"vendor/k8s.io/kubernetes/pkg/apis/core/v1"
267+
265268
]
266269
},
267270

@@ -350,7 +353,7 @@
350353
"github.com/openshift/origin/pkg/api",
351354
"github.com/openshift/origin/pkg/template/apis/template",
352355
"github.com/openshift/origin/pkg/template/apis/template/validation",
353-
"github.com/openshift/origin/pkg/route/apis/route"
356+
"github.com/openshift/origin/pkg/api/legacy"
354357
]
355358
},
356359

pkg/api/legacy/apps.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"k8s.io/apimachinery/pkg/runtime"
77
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
88
"k8s.io/kubernetes/pkg/apis/core"
9+
corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1"
910
"k8s.io/kubernetes/pkg/apis/extensions"
11+
extensionsv1beta1conversions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
1012

1113
appsv1 "github.com/openshift/api/apps/v1"
1214
"github.com/openshift/origin/pkg/apps/apis/apps"
@@ -15,13 +17,15 @@ import (
1517

1618
// InstallLegacyApps this looks like a lot of duplication, but the code in the individual versions is living and may
1719
// change. The code here should never change and needs to allow the other code to move independently.
18-
func InstallLegacyApps(scheme *runtime.Scheme) {
20+
func InstallInternalLegacyApps(scheme *runtime.Scheme) {
1921
InstallExternalLegacyApps(scheme)
2022

2123
schemeBuilder := runtime.NewSchemeBuilder(
2224
addUngroupifiedInternalAppsTypes,
2325
core.AddToScheme,
2426
extensions.AddToScheme,
27+
corev1conversions.AddToScheme,
28+
extensionsv1beta1conversions.AddToScheme,
2529

2630
appsv1helpers.AddConversionFuncs,
2731
appsv1helpers.RegisterDefaults,

pkg/api/legacy/authorization.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"k8s.io/apimachinery/pkg/runtime"
77
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
88
"k8s.io/kubernetes/pkg/apis/core"
9+
corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1"
910
"k8s.io/kubernetes/pkg/apis/rbac"
11+
rbacv1conversions "k8s.io/kubernetes/pkg/apis/rbac/v1"
1012

1113
authorizationv1 "github.com/openshift/api/authorization/v1"
1214
"github.com/openshift/origin/pkg/authorization/apis/authorization"
@@ -15,13 +17,15 @@ import (
1517

1618
// InstallLegacyAuthorization this looks like a lot of duplication, but the code in the individual versions is living and may
1719
// change. The code here should never change and needs to allow the other code to move independently.
18-
func InstallLegacyAuthorization(scheme *runtime.Scheme) {
20+
func InstallInternalLegacyAuthorization(scheme *runtime.Scheme) {
1921
InstallExternalLegacyAuthorization(scheme)
2022

2123
schemeBuilder := runtime.NewSchemeBuilder(
2224
addUngroupifiedInternalAuthorizationTypes,
2325
core.AddToScheme,
2426
rbac.AddToScheme,
27+
corev1conversions.AddToScheme,
28+
rbacv1conversions.AddToScheme,
2529

2630
authorizationv1helpers.AddConversionFuncs,
2731
authorizationv1helpers.AddFieldSelectorKeyConversions,

pkg/api/legacy/build.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package legacy
2+
3+
import (
4+
corev1 "k8s.io/api/core/v1"
5+
"k8s.io/apimachinery/pkg/runtime"
6+
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
7+
"k8s.io/kubernetes/pkg/apis/core"
8+
9+
buildv1 "github.com/openshift/api/build/v1"
10+
"github.com/openshift/origin/pkg/api/apihelpers"
11+
"github.com/openshift/origin/pkg/build/apis/build"
12+
buildv1helpers "github.com/openshift/origin/pkg/build/apis/build/v1"
13+
)
14+
15+
// InstallLegacyBuild this looks like a lot of duplication, but the code in the individual versions is living and may
16+
// change. The code here should never change and needs to allow the other code to move independently.
17+
func InstallInternalLegacyBuild(scheme *runtime.Scheme) {
18+
InstallExternalLegacyBuild(scheme)
19+
20+
schemeBuilder := runtime.NewSchemeBuilder(
21+
addUngroupifiedInternalBuildTypes,
22+
core.AddToScheme,
23+
24+
addLegacyBuildFieldSelectorKeyConversions,
25+
buildv1helpers.AddConversionFuncs,
26+
buildv1helpers.RegisterDefaults,
27+
buildv1helpers.RegisterConversions,
28+
)
29+
utilruntime.Must(schemeBuilder.AddToScheme(scheme))
30+
}
31+
32+
func InstallExternalLegacyBuild(scheme *runtime.Scheme) {
33+
schemeBuilder := runtime.NewSchemeBuilder(
34+
addUngroupifiedBuildTypes,
35+
corev1.AddToScheme,
36+
)
37+
utilruntime.Must(schemeBuilder.AddToScheme(scheme))
38+
}
39+
40+
func addUngroupifiedBuildTypes(scheme *runtime.Scheme) error {
41+
types := []runtime.Object{
42+
&buildv1.Build{},
43+
&buildv1.BuildList{},
44+
&buildv1.BuildConfig{},
45+
&buildv1.BuildConfigList{},
46+
&buildv1.BuildLog{},
47+
&buildv1.BuildRequest{},
48+
&buildv1.BuildLogOptions{},
49+
&buildv1.BinaryBuildRequestOptions{},
50+
}
51+
scheme.AddKnownTypes(GroupVersion, types...)
52+
return nil
53+
}
54+
55+
func addUngroupifiedInternalBuildTypes(scheme *runtime.Scheme) error {
56+
scheme.AddKnownTypes(internalGroupVersion,
57+
&build.Build{},
58+
&build.BuildList{},
59+
&build.BuildConfig{},
60+
&build.BuildConfigList{},
61+
&build.BuildLog{},
62+
&build.BuildRequest{},
63+
&build.BuildLogOptions{},
64+
&build.BinaryBuildRequestOptions{},
65+
)
66+
return nil
67+
}
68+
69+
func addLegacyBuildFieldSelectorKeyConversions(scheme *runtime.Scheme) error {
70+
if err := scheme.AddFieldLabelConversionFunc(GroupVersion.String(), "Build", legacyBuildFieldSelectorKeyConversionFunc); err != nil {
71+
return err
72+
}
73+
if err := scheme.AddFieldLabelConversionFunc(GroupVersion.String(), "BuildConfig", apihelpers.LegacyMetaV1FieldSelectorConversionWithName); err != nil {
74+
return err
75+
}
76+
return nil
77+
}
78+
79+
// because field selectors can vary in support by version they are exposed under, we have one function for each
80+
// groupVersion we're registering for
81+
82+
func legacyBuildFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) {
83+
switch label {
84+
case "status",
85+
"podName":
86+
return label, value, nil
87+
default:
88+
return apihelpers.LegacyMetaV1FieldSelectorConversionWithName(label, value)
89+
}
90+
}

pkg/api/legacy/build_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package legacy
2+
3+
import (
4+
"testing"
5+
6+
"github.com/openshift/origin/pkg/api/apihelpers/apitesting"
7+
"k8s.io/apimachinery/pkg/runtime"
8+
9+
internal "github.com/openshift/origin/pkg/build/apis/build"
10+
)
11+
12+
func TestBuildFieldSelectorConversions(t *testing.T) {
13+
install := func(scheme *runtime.Scheme) error {
14+
InstallInternalLegacyBuild(scheme)
15+
return nil
16+
}
17+
18+
apitesting.FieldKeyCheck{
19+
SchemeBuilder: []func(*runtime.Scheme) error{install},
20+
Kind: GroupVersion.WithKind("Build"),
21+
// Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST
22+
AllowedExternalFieldKeys: []string{"name", "status", "podName"},
23+
FieldKeyEvaluatorFn: internal.BuildFieldSelector,
24+
}.Check(t)
25+
26+
apitesting.FieldKeyCheck{
27+
SchemeBuilder: []func(*runtime.Scheme) error{install},
28+
Kind: GroupVersion.WithKind("BuildConfig"),
29+
// Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST
30+
AllowedExternalFieldKeys: []string{"name"},
31+
}.Check(t)
32+
33+
}

pkg/api/legacy/image.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package legacy
2+
3+
import (
4+
corev1 "k8s.io/api/core/v1"
5+
"k8s.io/apimachinery/pkg/runtime"
6+
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
7+
"k8s.io/kubernetes/pkg/apis/core"
8+
corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1"
9+
10+
"github.com/openshift/api/image/docker10"
11+
"github.com/openshift/api/image/dockerpre012"
12+
imagev1 "github.com/openshift/api/image/v1"
13+
"github.com/openshift/origin/pkg/api/apihelpers"
14+
"github.com/openshift/origin/pkg/image/apis/image"
15+
imagev1helpers "github.com/openshift/origin/pkg/image/apis/image/v1"
16+
)
17+
18+
// InstallLegacyImage this looks like a lot of duplication, but the code in the individual versions is living and may
19+
// change. The code here should never change and needs to allow the other code to move independently.
20+
func InstallInternalLegacyImage(scheme *runtime.Scheme) {
21+
InstallExternalLegacyImage(scheme)
22+
23+
schemeBuilder := runtime.NewSchemeBuilder(
24+
addUngroupifiedInternalImageTypes,
25+
core.AddToScheme,
26+
corev1conversions.AddToScheme,
27+
28+
addLegacyImageFieldSelectorKeyConversions,
29+
imagev1helpers.RegisterDefaults,
30+
imagev1helpers.RegisterConversions,
31+
)
32+
utilruntime.Must(schemeBuilder.AddToScheme(scheme))
33+
}
34+
35+
func InstallExternalLegacyImage(scheme *runtime.Scheme) {
36+
schemeBuilder := runtime.NewSchemeBuilder(
37+
addUngroupifiedImageTypes,
38+
docker10.AddToSchemeInCoreGroup,
39+
dockerpre012.AddToSchemeInCoreGroup,
40+
corev1.AddToScheme,
41+
)
42+
utilruntime.Must(schemeBuilder.AddToScheme(scheme))
43+
}
44+
45+
func addUngroupifiedImageTypes(scheme *runtime.Scheme) error {
46+
types := []runtime.Object{
47+
&imagev1.Image{},
48+
&imagev1.ImageList{},
49+
&imagev1.ImageSignature{},
50+
&imagev1.ImageStream{},
51+
&imagev1.ImageStreamList{},
52+
&imagev1.ImageStreamMapping{},
53+
&imagev1.ImageStreamTag{},
54+
&imagev1.ImageStreamTagList{},
55+
&imagev1.ImageStreamImage{},
56+
&imagev1.ImageStreamImport{},
57+
}
58+
scheme.AddKnownTypes(GroupVersion, types...)
59+
return nil
60+
}
61+
62+
func addUngroupifiedInternalImageTypes(scheme *runtime.Scheme) error {
63+
scheme.AddKnownTypes(internalGroupVersion,
64+
&image.Image{},
65+
&image.ImageList{},
66+
&image.DockerImage{},
67+
&image.ImageSignature{},
68+
&image.ImageStream{},
69+
&image.ImageStreamList{},
70+
&image.ImageStreamMapping{},
71+
&image.ImageStreamTag{},
72+
&image.ImageStreamTagList{},
73+
&image.ImageStreamImage{},
74+
&image.ImageStreamImport{},
75+
)
76+
return nil
77+
}
78+
79+
func addLegacyImageFieldSelectorKeyConversions(scheme *runtime.Scheme) error {
80+
if err := scheme.AddFieldLabelConversionFunc(GroupVersion.String(), "ImageStream", legacyImageStreamFieldSelectorKeyConversionFunc); err != nil {
81+
return err
82+
}
83+
return nil
84+
}
85+
86+
func legacyImageStreamFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) {
87+
switch label {
88+
case "spec.dockerImageRepository",
89+
"status.dockerImageRepository":
90+
return label, value, nil
91+
default:
92+
return apihelpers.LegacyMetaV1FieldSelectorConversionWithName(label, value)
93+
}
94+
}

0 commit comments

Comments
 (0)