diff --git a/cmd/openshift/openshift.go b/cmd/openshift/openshift.go index 0c440f1026e5..41b4c2b71b99 100644 --- a/cmd/openshift/openshift.go +++ b/cmd/openshift/openshift.go @@ -29,7 +29,7 @@ func main() { defer serviceability.BehaviorOnPanic(os.Getenv("OPENSHIFT_ON_PANIC"), version.Get())() defer serviceability.Profile(os.Getenv("OPENSHIFT_PROFILE")).Stop() - legacy.LegacyInstallAll(legacyscheme.Scheme) + legacy.InstallLegacyInternalAll(legacyscheme.Scheme) rand.Seed(time.Now().UTC().UnixNano()) if len(os.Getenv("GOMAXPROCS")) == 0 { diff --git a/examples/examples_test.go b/examples/examples_test.go index cbad43c6ed48..b064e029333f 100644 --- a/examples/examples_test.go +++ b/examples/examples_test.go @@ -33,7 +33,7 @@ import ( ) func init() { - legacy.LegacyInstallAll(legacyscheme.Scheme) + legacy.InstallLegacyInternalAll(legacyscheme.Scheme) } func walkJSONFiles(inDir string, fn func(name, path string, data []byte)) error { diff --git a/hack/import-restrictions.json b/hack/import-restrictions.json index 06a2720b9dfe..a3a22d013337 100644 --- a/hack/import-restrictions.json +++ b/hack/import-restrictions.json @@ -225,11 +225,11 @@ "allowedImportPackageRoots": [ "vendor/k8s.io/apimachinery", "vendor/k8s.io/api", - "vendor/github.com/openshift/api", - "github.com/openshift/origin/pkg/api/apihelpers" + "vendor/github.com/openshift/api" ], "allowedImportPackages": [ - "vendor/k8s.io/kubernetes/pkg/apis/core" + "vendor/k8s.io/kubernetes/pkg/apis/core", + "vendor/k8s.io/kubernetes/pkg/apis/core/v1" ] }, @@ -261,7 +261,10 @@ "github.com/openshift/origin/pkg/api/apihelpers" ], "allowedImportPackages": [ - "vendor/k8s.io/kubernetes/pkg/apis/core" + "vendor/k8s.io/kubernetes/pkg/apis/core", + "vendor/github.com/davecgh/go-spew/spew", + "vendor/k8s.io/kubernetes/pkg/apis/core/v1" + ] }, @@ -350,7 +353,7 @@ "github.com/openshift/origin/pkg/api", "github.com/openshift/origin/pkg/template/apis/template", "github.com/openshift/origin/pkg/template/apis/template/validation", - "github.com/openshift/origin/pkg/route/apis/route" + "github.com/openshift/origin/pkg/api/legacy" ] }, diff --git a/pkg/api/legacy/apps.go b/pkg/api/legacy/apps.go index 8fd1fc3ab35e..c4316364b51d 100644 --- a/pkg/api/legacy/apps.go +++ b/pkg/api/legacy/apps.go @@ -6,7 +6,9 @@ import ( "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/kubernetes/pkg/apis/core" + corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1" "k8s.io/kubernetes/pkg/apis/extensions" + extensionsv1beta1conversions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1" appsv1 "github.com/openshift/api/apps/v1" "github.com/openshift/origin/pkg/apps/apis/apps" @@ -15,13 +17,15 @@ import ( // InstallLegacyApps 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 InstallLegacyApps(scheme *runtime.Scheme) { +func InstallInternalLegacyApps(scheme *runtime.Scheme) { InstallExternalLegacyApps(scheme) schemeBuilder := runtime.NewSchemeBuilder( addUngroupifiedInternalAppsTypes, core.AddToScheme, extensions.AddToScheme, + corev1conversions.AddToScheme, + extensionsv1beta1conversions.AddToScheme, appsv1helpers.AddConversionFuncs, appsv1helpers.RegisterDefaults, diff --git a/pkg/api/legacy/authorization.go b/pkg/api/legacy/authorization.go index df7d80d86b20..94f91bd4694a 100644 --- a/pkg/api/legacy/authorization.go +++ b/pkg/api/legacy/authorization.go @@ -6,7 +6,9 @@ import ( "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/kubernetes/pkg/apis/core" + corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1" "k8s.io/kubernetes/pkg/apis/rbac" + rbacv1conversions "k8s.io/kubernetes/pkg/apis/rbac/v1" authorizationv1 "github.com/openshift/api/authorization/v1" "github.com/openshift/origin/pkg/authorization/apis/authorization" @@ -15,13 +17,15 @@ import ( // InstallLegacyAuthorization 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 InstallLegacyAuthorization(scheme *runtime.Scheme) { +func InstallInternalLegacyAuthorization(scheme *runtime.Scheme) { InstallExternalLegacyAuthorization(scheme) schemeBuilder := runtime.NewSchemeBuilder( addUngroupifiedInternalAuthorizationTypes, core.AddToScheme, rbac.AddToScheme, + corev1conversions.AddToScheme, + rbacv1conversions.AddToScheme, authorizationv1helpers.AddConversionFuncs, authorizationv1helpers.AddFieldSelectorKeyConversions, diff --git a/pkg/api/legacy/build.go b/pkg/api/legacy/build.go new file mode 100644 index 000000000000..ca7ef926faf1 --- /dev/null +++ b/pkg/api/legacy/build.go @@ -0,0 +1,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.String(), "Build", legacyBuildFieldSelectorKeyConversionFunc); err != nil { + return err + } + if err := scheme.AddFieldLabelConversionFunc(GroupVersion.String(), "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) + } +} diff --git a/pkg/api/legacy/build_test.go b/pkg/api/legacy/build_test.go new file mode 100644 index 000000000000..f7dfd0c81848 --- /dev/null +++ b/pkg/api/legacy/build_test.go @@ -0,0 +1,33 @@ +package legacy + +import ( + "testing" + + "github.com/openshift/origin/pkg/api/apihelpers/apitesting" + "k8s.io/apimachinery/pkg/runtime" + + internal "github.com/openshift/origin/pkg/build/apis/build" +) + +func TestBuildFieldSelectorConversions(t *testing.T) { + install := func(scheme *runtime.Scheme) error { + InstallInternalLegacyBuild(scheme) + return nil + } + + apitesting.FieldKeyCheck{ + SchemeBuilder: []func(*runtime.Scheme) error{install}, + Kind: GroupVersion.WithKind("Build"), + // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST + AllowedExternalFieldKeys: []string{"name", "status", "podName"}, + FieldKeyEvaluatorFn: internal.BuildFieldSelector, + }.Check(t) + + apitesting.FieldKeyCheck{ + SchemeBuilder: []func(*runtime.Scheme) error{install}, + Kind: GroupVersion.WithKind("BuildConfig"), + // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST + AllowedExternalFieldKeys: []string{"name"}, + }.Check(t) + +} diff --git a/pkg/api/legacy/image.go b/pkg/api/legacy/image.go new file mode 100644 index 000000000000..ce5a8a6a1ac0 --- /dev/null +++ b/pkg/api/legacy/image.go @@ -0,0 +1,94 @@ +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" + corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1" + + "github.com/openshift/api/image/docker10" + "github.com/openshift/api/image/dockerpre012" + imagev1 "github.com/openshift/api/image/v1" + "github.com/openshift/origin/pkg/api/apihelpers" + "github.com/openshift/origin/pkg/image/apis/image" + imagev1helpers "github.com/openshift/origin/pkg/image/apis/image/v1" +) + +// InstallLegacyImage 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 InstallInternalLegacyImage(scheme *runtime.Scheme) { + InstallExternalLegacyImage(scheme) + + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedInternalImageTypes, + core.AddToScheme, + corev1conversions.AddToScheme, + + addLegacyImageFieldSelectorKeyConversions, + imagev1helpers.RegisterDefaults, + imagev1helpers.RegisterConversions, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func InstallExternalLegacyImage(scheme *runtime.Scheme) { + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedImageTypes, + docker10.AddToSchemeInCoreGroup, + dockerpre012.AddToSchemeInCoreGroup, + corev1.AddToScheme, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func addUngroupifiedImageTypes(scheme *runtime.Scheme) error { + types := []runtime.Object{ + &imagev1.Image{}, + &imagev1.ImageList{}, + &imagev1.ImageSignature{}, + &imagev1.ImageStream{}, + &imagev1.ImageStreamList{}, + &imagev1.ImageStreamMapping{}, + &imagev1.ImageStreamTag{}, + &imagev1.ImageStreamTagList{}, + &imagev1.ImageStreamImage{}, + &imagev1.ImageStreamImport{}, + } + scheme.AddKnownTypes(GroupVersion, types...) + return nil +} + +func addUngroupifiedInternalImageTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(internalGroupVersion, + &image.Image{}, + &image.ImageList{}, + &image.DockerImage{}, + &image.ImageSignature{}, + &image.ImageStream{}, + &image.ImageStreamList{}, + &image.ImageStreamMapping{}, + &image.ImageStreamTag{}, + &image.ImageStreamTagList{}, + &image.ImageStreamImage{}, + &image.ImageStreamImport{}, + ) + return nil +} + +func addLegacyImageFieldSelectorKeyConversions(scheme *runtime.Scheme) error { + if err := scheme.AddFieldLabelConversionFunc(GroupVersion.String(), "ImageStream", legacyImageStreamFieldSelectorKeyConversionFunc); err != nil { + return err + } + return nil +} + +func legacyImageStreamFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { + switch label { + case "spec.dockerImageRepository", + "status.dockerImageRepository": + return label, value, nil + default: + return apihelpers.LegacyMetaV1FieldSelectorConversionWithName(label, value) + } +} diff --git a/pkg/api/legacy/image_test.go b/pkg/api/legacy/image_test.go new file mode 100644 index 000000000000..9b9b754ec06b --- /dev/null +++ b/pkg/api/legacy/image_test.go @@ -0,0 +1,93 @@ +package legacy + +import ( + "reflect" + "testing" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/serializer" + "k8s.io/apimachinery/pkg/util/diff" + kapi "k8s.io/kubernetes/pkg/apis/core" + + "github.com/openshift/origin/pkg/api/apihelpers/apitesting" + internal "github.com/openshift/origin/pkg/image/apis/image" +) + +func TestImageRoundTripVersionedObject(t *testing.T) { + scheme := runtime.NewScheme() + InstallInternalLegacyImage(scheme) + codecs := serializer.NewCodecFactory(scheme) + + d := &internal.DockerImage{ + Config: &internal.DockerConfig{ + Env: []string{"A=1", "B=2"}, + }, + } + i := &internal.Image{ + ObjectMeta: metav1.ObjectMeta{Name: "foo"}, + + DockerImageLayers: []internal.ImageLayer{{Name: "foo", LayerSize: 10}}, + DockerImageMetadata: *d, + DockerImageReference: "foo/bar/baz", + } + + data, err := runtime.Encode(codecs.LegacyCodec(GroupVersion), i) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + + obj, err := runtime.Decode(codecs.UniversalDecoder(), data) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + image := obj.(*internal.Image) + if image.DockerImageMetadataVersion != "1.0" { + t.Errorf("did not default to correct metadata version: %#v", image) + } + image.DockerImageMetadataVersion = "" + if !reflect.DeepEqual(i, image) { + t.Errorf("unable to round trip object: %s", diff.ObjectDiff(i, image)) + } +} + +func TestImageFieldSelectors(t *testing.T) { + install := func(scheme *runtime.Scheme) error { + InstallInternalLegacyImage(scheme) + return nil + } + + apitesting.FieldKeyCheck{ + SchemeBuilder: []func(*runtime.Scheme) error{install}, + Kind: GroupVersion.WithKind("ImageStream"), + // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST + AllowedExternalFieldKeys: []string{"name", "spec.dockerImageRepository", "status.dockerImageRepository"}, + FieldKeyEvaluatorFn: internal.ImageStreamSelector, + }.Check(t) +} + +func TestImageImportSpecDefaulting(t *testing.T) { + scheme := runtime.NewScheme() + codecs := serializer.NewCodecFactory(scheme) + InstallInternalLegacyImage(scheme) + + i := &internal.ImageStreamImport{ + Spec: internal.ImageStreamImportSpec{ + Images: []internal.ImageImportSpec{ + {From: kapi.ObjectReference{Name: "something:other"}}, + }, + }, + } + data, err := runtime.Encode(codecs.LegacyCodec(GroupVersion), i) + if err != nil { + t.Fatal(err) + } + obj, err := runtime.Decode(codecs.UniversalDecoder(), data) + if err != nil { + t.Fatal(err) + } + isi := obj.(*internal.ImageStreamImport) + if isi.Spec.Images[0].To == nil || isi.Spec.Images[0].To.Name != "other" { + t.Errorf("unexpected round trip: %#v", isi) + } +} diff --git a/pkg/api/legacy/install.go b/pkg/api/legacy/install.go index f611264ff65d..12d0a654408e 100644 --- a/pkg/api/legacy/install.go +++ b/pkg/api/legacy/install.go @@ -3,28 +3,6 @@ package legacy import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - - buildapi "github.com/openshift/origin/pkg/build/apis/build" - buildapiv1 "github.com/openshift/origin/pkg/build/apis/build/v1" - imageapi "github.com/openshift/origin/pkg/image/apis/image" - imageapiv1 "github.com/openshift/origin/pkg/image/apis/image/v1" - networkapi "github.com/openshift/origin/pkg/network/apis/network" - networkapiv1 "github.com/openshift/origin/pkg/network/apis/network/v1" - oauthapi "github.com/openshift/origin/pkg/oauth/apis/oauth" - oauthapiv1 "github.com/openshift/origin/pkg/oauth/apis/oauth/v1" - projectapi "github.com/openshift/origin/pkg/project/apis/project" - projectapiv1 "github.com/openshift/origin/pkg/project/apis/project/v1" - quotaapi "github.com/openshift/origin/pkg/quota/apis/quota" - quotaapiv1 "github.com/openshift/origin/pkg/quota/apis/quota/v1" - routeapi "github.com/openshift/origin/pkg/route/apis/route" - routeapiv1 "github.com/openshift/origin/pkg/route/apis/route/v1" - securityapi "github.com/openshift/origin/pkg/security/apis/security" - securityapiv1 "github.com/openshift/origin/pkg/security/apis/security/v1" - templateapi "github.com/openshift/origin/pkg/template/apis/template" - templateapiv1 "github.com/openshift/origin/pkg/template/apis/template/v1" - userapi "github.com/openshift/origin/pkg/user/apis/user" - userapiv1 "github.com/openshift/origin/pkg/user/apis/user/v1" ) var ( @@ -43,67 +21,32 @@ func Resource(resource string) schema.GroupResource { return schema.GroupResource{Group: GroupName, Resource: resource} } -func InstallLegacyBuild(scheme *runtime.Scheme) { - utilruntime.Must(buildapi.AddToSchemeInCoreGroup(scheme)) - utilruntime.Must(buildapiv1.AddToSchemeInCoreGroup(scheme)) -} - -func InstallLegacyImage(scheme *runtime.Scheme) { - utilruntime.Must(imageapi.AddToSchemeInCoreGroup(scheme)) - utilruntime.Must(imageapiv1.AddToSchemeInCoreGroup(scheme)) -} - -func InstallLegacyNetwork(scheme *runtime.Scheme) { - utilruntime.Must(networkapi.AddToSchemeInCoreGroup(scheme)) - utilruntime.Must(networkapiv1.AddToSchemeInCoreGroup(scheme)) -} - -func InstallLegacyOAuth(scheme *runtime.Scheme) { - utilruntime.Must(oauthapi.AddToSchemeInCoreGroup(scheme)) - utilruntime.Must(oauthapiv1.AddToSchemeInCoreGroup(scheme)) -} - -func InstallLegacyProject(scheme *runtime.Scheme) { - utilruntime.Must(projectapi.AddToSchemeInCoreGroup(scheme)) - utilruntime.Must(projectapiv1.AddToSchemeInCoreGroup(scheme)) -} - -func InstallLegacyQuota(scheme *runtime.Scheme) { - utilruntime.Must(quotaapi.AddToSchemeInCoreGroup(scheme)) - utilruntime.Must(quotaapiv1.AddToSchemeInCoreGroup(scheme)) -} - -func InstallLegacyRoute(scheme *runtime.Scheme) { - utilruntime.Must(routeapi.AddToSchemeInCoreGroup(scheme)) - utilruntime.Must(routeapiv1.AddToSchemeInCoreGroup(scheme)) -} - -func InstallLegacySecurity(scheme *runtime.Scheme) { - utilruntime.Must(securityapi.AddToSchemeInCoreGroup(scheme)) - utilruntime.Must(securityapiv1.AddToSchemeInCoreGroup(scheme)) -} - -func InstallLegacyTemplate(scheme *runtime.Scheme) { - utilruntime.Must(templateapi.AddToSchemeInCoreGroup(scheme)) - utilruntime.Must(templateapiv1.AddToSchemeInCoreGroup(scheme)) -} - -func InstallLegacyUser(scheme *runtime.Scheme) { - utilruntime.Must(userapi.AddToSchemeInCoreGroup(scheme)) - utilruntime.Must(userapiv1.AddToSchemeInCoreGroup(scheme)) -} - -func LegacyInstallAll(scheme *runtime.Scheme) { - InstallLegacyApps(scheme) - InstallLegacyAuthorization(scheme) - InstallLegacyBuild(scheme) - InstallLegacyImage(scheme) - InstallLegacyNetwork(scheme) - InstallLegacyOAuth(scheme) - InstallLegacyProject(scheme) - InstallLegacyQuota(scheme) - InstallLegacyRoute(scheme) - InstallLegacySecurity(scheme) - InstallLegacyTemplate(scheme) - InstallLegacyUser(scheme) +func InstallLegacyInternalAll(scheme *runtime.Scheme) { + InstallInternalLegacyApps(scheme) + InstallInternalLegacyAuthorization(scheme) + InstallInternalLegacyBuild(scheme) + InstallInternalLegacyImage(scheme) + InstallInternalLegacyNetwork(scheme) + InstallInternalLegacyOAuth(scheme) + InstallInternalLegacyProject(scheme) + InstallInternalLegacyQuota(scheme) + InstallInternalLegacyRoute(scheme) + InstallInternalLegacySecurity(scheme) + InstallInternalLegacyTemplate(scheme) + InstallInternalLegacyUser(scheme) +} + +func InstallLegacyExternalAll(scheme *runtime.Scheme) { + InstallExternalLegacyApps(scheme) + InstallExternalLegacyAuthorization(scheme) + InstallExternalLegacyBuild(scheme) + InstallExternalLegacyImage(scheme) + InstallExternalLegacyNetwork(scheme) + InstallExternalLegacyOAuth(scheme) + InstallExternalLegacyProject(scheme) + InstallExternalLegacyQuota(scheme) + InstallExternalLegacyRoute(scheme) + InstallExternalLegacySecurity(scheme) + InstallExternalLegacyTemplate(scheme) + InstallExternalLegacyUser(scheme) } diff --git a/pkg/api/legacy/network.go b/pkg/api/legacy/network.go new file mode 100644 index 000000000000..e8b0df5b111e --- /dev/null +++ b/pkg/api/legacy/network.go @@ -0,0 +1,60 @@ +package legacy + +import ( + "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + + networkv1 "github.com/openshift/api/network/v1" + "github.com/openshift/origin/pkg/network/apis/network" + networkv1helpers "github.com/openshift/origin/pkg/network/apis/network/v1" +) + +// InstallLegacyNetwork 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 InstallInternalLegacyNetwork(scheme *runtime.Scheme) { + InstallExternalLegacyNetwork(scheme) + + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedInternalNetworkTypes, + + networkv1helpers.RegisterDefaults, + networkv1helpers.RegisterConversions, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func InstallExternalLegacyNetwork(scheme *runtime.Scheme) { + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedNetworkTypes, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func addUngroupifiedNetworkTypes(scheme *runtime.Scheme) error { + types := []runtime.Object{ + &networkv1.ClusterNetwork{}, + &networkv1.ClusterNetworkList{}, + &networkv1.HostSubnet{}, + &networkv1.HostSubnetList{}, + &networkv1.NetNamespace{}, + &networkv1.NetNamespaceList{}, + &networkv1.EgressNetworkPolicy{}, + &networkv1.EgressNetworkPolicyList{}, + } + scheme.AddKnownTypes(GroupVersion, types...) + return nil +} + +func addUngroupifiedInternalNetworkTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(internalGroupVersion, + &network.ClusterNetwork{}, + &network.ClusterNetworkList{}, + &network.HostSubnet{}, + &network.HostSubnetList{}, + &network.NetNamespace{}, + &network.NetNamespaceList{}, + &network.EgressNetworkPolicy{}, + &network.EgressNetworkPolicyList{}, + ) + return nil +} diff --git a/pkg/api/legacy/oauth.go b/pkg/api/legacy/oauth.go new file mode 100644 index 000000000000..bee4143ce2bf --- /dev/null +++ b/pkg/api/legacy/oauth.go @@ -0,0 +1,108 @@ +package legacy + +import ( + "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + + oauthv1 "github.com/openshift/api/oauth/v1" + "github.com/openshift/origin/pkg/oauth/apis/oauth" + oauthv1helpers "github.com/openshift/origin/pkg/oauth/apis/oauth/v1" +) + +// InstallLegacyOAuth 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 InstallInternalLegacyOAuth(scheme *runtime.Scheme) { + InstallExternalLegacyOAuth(scheme) + + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedInternalOAuthTypes, + + addLegacyOAuthFieldSelectorKeyConversions, + oauthv1helpers.RegisterDefaults, + oauthv1helpers.RegisterConversions, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func InstallExternalLegacyOAuth(scheme *runtime.Scheme) { + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedOAuthTypes, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func addUngroupifiedOAuthTypes(scheme *runtime.Scheme) error { + types := []runtime.Object{ + &oauthv1.OAuthAccessToken{}, + &oauthv1.OAuthAccessTokenList{}, + &oauthv1.OAuthAuthorizeToken{}, + &oauthv1.OAuthAuthorizeTokenList{}, + &oauthv1.OAuthClient{}, + &oauthv1.OAuthClientList{}, + &oauthv1.OAuthClientAuthorization{}, + &oauthv1.OAuthClientAuthorizationList{}, + &oauthv1.OAuthRedirectReference{}, + } + scheme.AddKnownTypes(GroupVersion, types...) + return nil +} + +func addUngroupifiedInternalOAuthTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(internalGroupVersion, + &oauth.OAuthAccessToken{}, + &oauth.OAuthAccessTokenList{}, + &oauth.OAuthAuthorizeToken{}, + &oauth.OAuthAuthorizeTokenList{}, + &oauth.OAuthClient{}, + &oauth.OAuthClientList{}, + &oauth.OAuthClientAuthorization{}, + &oauth.OAuthClientAuthorizationList{}, + &oauth.OAuthRedirectReference{}, + ) + return nil +} + +func addLegacyOAuthFieldSelectorKeyConversions(scheme *runtime.Scheme) error { + if err := scheme.AddFieldLabelConversionFunc(GroupVersion.String(), "OAuthAccessToken", legacyOAuthAccessTokenFieldSelectorKeyConversionFunc); err != nil { + return err + } + if err := scheme.AddFieldLabelConversionFunc(GroupVersion.String(), "OAuthAuthorizeToken", legacyOAuthAuthorizeTokenFieldSelectorKeyConversionFunc); err != nil { + return err + } + if err := scheme.AddFieldLabelConversionFunc(GroupVersion.String(), "OAuthClientAuthorization", legacyOAuthClientAuthorizationFieldSelectorKeyConversionFunc); err != nil { + return err + } + return nil +} + +func legacyOAuthAccessTokenFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { + switch label { + case "clientName", + "userName", + "userUID", + "authorizeToken": + return label, value, nil + default: + return runtime.DefaultMetaV1FieldSelectorConversion(label, value) + } +} +func legacyOAuthAuthorizeTokenFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { + switch label { + case "clientName", + "userName", + "userUID": + return label, value, nil + default: + return runtime.DefaultMetaV1FieldSelectorConversion(label, value) + } +} +func legacyOAuthClientAuthorizationFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { + switch label { + case "clientName", + "userName", + "userUID": + return label, value, nil + default: + return runtime.DefaultMetaV1FieldSelectorConversion(label, value) + } +} diff --git a/pkg/api/legacy/oauth_test.go b/pkg/api/legacy/oauth_test.go new file mode 100644 index 000000000000..37287f295d1e --- /dev/null +++ b/pkg/api/legacy/oauth_test.go @@ -0,0 +1,40 @@ +package legacy + +import ( + "testing" + + "k8s.io/apimachinery/pkg/runtime" + + "github.com/openshift/origin/pkg/api/apihelpers/apitesting" + oauthapi "github.com/openshift/origin/pkg/oauth/apis/oauth" +) + +func TestOAuthFieldSelectorConversions(t *testing.T) { + install := func(scheme *runtime.Scheme) error { + InstallInternalLegacyOAuth(scheme) + return nil + } + + apitesting.FieldKeyCheck{ + SchemeBuilder: []func(*runtime.Scheme) error{install}, + Kind: GroupVersion.WithKind("OAuthAccessToken"), + // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST + AllowedExternalFieldKeys: []string{"clientName", "userName", "userUID", "authorizeToken"}, + FieldKeyEvaluatorFn: oauthapi.OAuthAccessTokenFieldSelector, + }.Check(t) + apitesting.FieldKeyCheck{ + SchemeBuilder: []func(*runtime.Scheme) error{install}, + Kind: GroupVersion.WithKind("OAuthAuthorizeToken"), + // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST + AllowedExternalFieldKeys: []string{"clientName", "userName", "userUID"}, + FieldKeyEvaluatorFn: oauthapi.OAuthAuthorizeTokenFieldSelector, + }.Check(t) + apitesting.FieldKeyCheck{ + SchemeBuilder: []func(*runtime.Scheme) error{install}, + Kind: GroupVersion.WithKind("OAuthClientAuthorization"), + // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST + AllowedExternalFieldKeys: []string{"clientName", "userName", "userUID"}, + FieldKeyEvaluatorFn: oauthapi.OAuthClientAuthorizationFieldSelector, + }.Check(t) + +} diff --git a/pkg/api/legacy/project.go b/pkg/api/legacy/project.go new file mode 100644 index 000000000000..38b0a8b6d874 --- /dev/null +++ b/pkg/api/legacy/project.go @@ -0,0 +1,71 @@ +package legacy + +import ( + "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + + projectv1 "github.com/openshift/api/project/v1" + "github.com/openshift/origin/pkg/api/apihelpers" + "github.com/openshift/origin/pkg/project/apis/project" + projectv1helpers "github.com/openshift/origin/pkg/project/apis/project/v1" +) + +// InstallLegacyProject 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 InstallInternalLegacyProject(scheme *runtime.Scheme) { + InstallExternalLegacyProject(scheme) + + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedInternalProjectTypes, + + addLegacyProjectFieldSelectorKeyConversions, + projectv1helpers.RegisterDefaults, + projectv1helpers.RegisterConversions, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func InstallExternalLegacyProject(scheme *runtime.Scheme) { + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedProjectTypes, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func addUngroupifiedProjectTypes(scheme *runtime.Scheme) error { + types := []runtime.Object{ + &projectv1.Project{}, + &projectv1.ProjectList{}, + &projectv1.ProjectRequest{}, + } + scheme.AddKnownTypes(GroupVersion, types...) + return nil +} + +func addUngroupifiedInternalProjectTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(internalGroupVersion, + &project.Project{}, + &project.ProjectList{}, + &project.ProjectRequest{}, + ) + return nil +} + +func addLegacyProjectFieldSelectorKeyConversions(scheme *runtime.Scheme) error { + if err := scheme.AddFieldLabelConversionFunc(GroupVersion.String(), "Project", legacyProjectFieldSelectorKeyConversionFunc); err != nil { + return err + } + return nil +} + +// we don't actually do any evaluation, only passing through, so we don't have our own field selector to test. The upstream +// cannot remove the field selectors or they break compatibility, so we're fine. + +func legacyProjectFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { + switch label { + case "status.phase": + return label, value, nil + default: + return apihelpers.LegacyMetaV1FieldSelectorConversionWithName(label, value) + } +} diff --git a/pkg/api/legacy/quota.go b/pkg/api/legacy/quota.go new file mode 100644 index 000000000000..fc1ac8835b74 --- /dev/null +++ b/pkg/api/legacy/quota.go @@ -0,0 +1,52 @@ +package legacy + +import ( + "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + + quotav1 "github.com/openshift/api/quota/v1" + "github.com/openshift/origin/pkg/quota/apis/quota" + quotav1helpers "github.com/openshift/origin/pkg/quota/apis/quota/v1" +) + +// InstallLegacyQuota 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 InstallInternalLegacyQuota(scheme *runtime.Scheme) { + InstallExternalLegacyQuota(scheme) + + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedInternalQuotaTypes, + + quotav1helpers.RegisterDefaults, + quotav1helpers.RegisterConversions, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func InstallExternalLegacyQuota(scheme *runtime.Scheme) { + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedQuotaTypes, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func addUngroupifiedQuotaTypes(scheme *runtime.Scheme) error { + types := []runtime.Object{ + "av1.ClusterResourceQuota{}, + "av1.ClusterResourceQuotaList{}, + "av1.AppliedClusterResourceQuota{}, + "av1.AppliedClusterResourceQuotaList{}, + } + scheme.AddKnownTypes(GroupVersion, types...) + return nil +} + +func addUngroupifiedInternalQuotaTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(internalGroupVersion, + "a.ClusterResourceQuota{}, + "a.ClusterResourceQuotaList{}, + "a.AppliedClusterResourceQuota{}, + "a.AppliedClusterResourceQuotaList{}, + ) + return nil +} diff --git a/pkg/api/legacy/route.go b/pkg/api/legacy/route.go new file mode 100644 index 000000000000..d4086a7db27f --- /dev/null +++ b/pkg/api/legacy/route.go @@ -0,0 +1,73 @@ +package legacy + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + + routev1 "github.com/openshift/api/route/v1" + "github.com/openshift/origin/pkg/route/apis/route" + routev1helpers "github.com/openshift/origin/pkg/route/apis/route/v1" + "k8s.io/kubernetes/pkg/apis/core" + corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1" +) + +// InstallLegacyRoute 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 InstallInternalLegacyRoute(scheme *runtime.Scheme) { + InstallExternalLegacyRoute(scheme) + + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedInternalRouteTypes, + core.AddToScheme, + corev1conversions.AddToScheme, + + addLegacyRouteFieldSelectorKeyConversions, + routev1helpers.RegisterDefaults, + routev1helpers.RegisterConversions, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func InstallExternalLegacyRoute(scheme *runtime.Scheme) { + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedRouteTypes, + corev1.AddToScheme, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func addUngroupifiedRouteTypes(scheme *runtime.Scheme) error { + types := []runtime.Object{ + &routev1.Route{}, + &routev1.RouteList{}, + } + scheme.AddKnownTypes(GroupVersion, types...) + return nil +} + +func addUngroupifiedInternalRouteTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(internalGroupVersion, + &route.Route{}, + &route.RouteList{}, + ) + return nil +} + +func addLegacyRouteFieldSelectorKeyConversions(scheme *runtime.Scheme) error { + if err := scheme.AddFieldLabelConversionFunc(GroupVersion.String(), "Route", legacyRouteFieldSelectorKeyConversionFunc); err != nil { + return err + } + return nil +} + +func legacyRouteFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { + switch label { + case "spec.path", + "spec.host", + "spec.to.name": + return label, value, nil + default: + return runtime.DefaultMetaV1FieldSelectorConversion(label, value) + } +} diff --git a/pkg/api/legacy/route_test.go b/pkg/api/legacy/route_test.go new file mode 100644 index 000000000000..14ff85423ed4 --- /dev/null +++ b/pkg/api/legacy/route_test.go @@ -0,0 +1,25 @@ +package legacy + +import ( + "testing" + + "k8s.io/apimachinery/pkg/runtime" + + "github.com/openshift/origin/pkg/api/apihelpers/apitesting" + "github.com/openshift/origin/pkg/route/apis/route" +) + +func TestRouteFieldSelectorConversions(t *testing.T) { + install := func(scheme *runtime.Scheme) error { + InstallInternalLegacyRoute(scheme) + return nil + } + apitesting.FieldKeyCheck{ + SchemeBuilder: []func(*runtime.Scheme) error{install}, + Kind: GroupVersion.WithKind("Route"), + // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST + AllowedExternalFieldKeys: []string{"spec.host", "spec.path", "spec.to.name"}, + FieldKeyEvaluatorFn: route.RouteFieldSelector, + }.Check(t) + +} diff --git a/pkg/api/legacy/security.go b/pkg/api/legacy/security.go new file mode 100644 index 000000000000..8b39333a96e0 --- /dev/null +++ b/pkg/api/legacy/security.go @@ -0,0 +1,63 @@ +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" + + securityv1 "github.com/openshift/api/security/v1" + "github.com/openshift/origin/pkg/security/apis/security" + securityv1helpers "github.com/openshift/origin/pkg/security/apis/security/v1" + corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1" +) + +// InstallLegacySecurity 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 InstallInternalLegacySecurity(scheme *runtime.Scheme) { + InstallExternalLegacySecurity(scheme) + + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedInternalSecurityTypes, + core.AddToScheme, + corev1conversions.AddToScheme, + + securityv1helpers.AddConversionFuncs, + securityv1helpers.AddDefaultingFuncs, + securityv1helpers.RegisterDefaults, + securityv1helpers.RegisterConversions, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func InstallExternalLegacySecurity(scheme *runtime.Scheme) { + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedSecurityTypes, + corev1.AddToScheme, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func addUngroupifiedSecurityTypes(scheme *runtime.Scheme) error { + types := []runtime.Object{ + &securityv1.SecurityContextConstraints{}, + &securityv1.SecurityContextConstraintsList{}, + &securityv1.PodSecurityPolicySubjectReview{}, + &securityv1.PodSecurityPolicySelfSubjectReview{}, + &securityv1.PodSecurityPolicyReview{}, + } + scheme.AddKnownTypes(GroupVersion, types...) + return nil +} + +func addUngroupifiedInternalSecurityTypes(scheme *runtime.Scheme) error { + types := []runtime.Object{ + &security.SecurityContextConstraints{}, + &security.SecurityContextConstraintsList{}, + &security.PodSecurityPolicySubjectReview{}, + &security.PodSecurityPolicySelfSubjectReview{}, + &security.PodSecurityPolicyReview{}, + } + scheme.AddKnownTypes(internalGroupVersion, types...) + return nil +} diff --git a/pkg/api/legacy/template.go b/pkg/api/legacy/template.go new file mode 100644 index 000000000000..a60fe574610f --- /dev/null +++ b/pkg/api/legacy/template.go @@ -0,0 +1,59 @@ +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" + + templatev1 "github.com/openshift/api/template/v1" + "github.com/openshift/origin/pkg/template/apis/template" + templatev1helpers "github.com/openshift/origin/pkg/template/apis/template/v1" + corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1" +) + +// InstallLegacyTemplate 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 InstallInternalLegacyTemplate(scheme *runtime.Scheme) { + InstallExternalLegacyTemplate(scheme) + + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedInternalTemplateTypes, + core.AddToScheme, + corev1conversions.AddToScheme, + + templatev1helpers.RegisterDefaults, + templatev1helpers.RegisterConversions, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func InstallExternalLegacyTemplate(scheme *runtime.Scheme) { + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedTemplateTypes, + corev1.AddToScheme, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func addUngroupifiedTemplateTypes(scheme *runtime.Scheme) error { + types := []runtime.Object{ + &templatev1.Template{}, + &templatev1.TemplateList{}, + } + scheme.AddKnownTypes(GroupVersion, types...) + scheme.AddKnownTypeWithName(GroupVersion.WithKind("TemplateConfig"), &templatev1.Template{}) + scheme.AddKnownTypeWithName(GroupVersion.WithKind("ProcessedTemplate"), &templatev1.Template{}) + return nil +} + +func addUngroupifiedInternalTemplateTypes(scheme *runtime.Scheme) error { + types := []runtime.Object{ + &template.Template{}, + &template.TemplateList{}, + } + scheme.AddKnownTypes(internalGroupVersion, types...) + scheme.AddKnownTypeWithName(internalGroupVersion.WithKind("TemplateConfig"), &template.Template{}) + scheme.AddKnownTypeWithName(internalGroupVersion.WithKind("ProcessedTemplate"), &template.Template{}) + return nil +} diff --git a/pkg/api/legacy/user.go b/pkg/api/legacy/user.go new file mode 100644 index 000000000000..234d9c415830 --- /dev/null +++ b/pkg/api/legacy/user.go @@ -0,0 +1,84 @@ +package legacy + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + + userv1 "github.com/openshift/api/user/v1" + "github.com/openshift/origin/pkg/user/apis/user" + userv1helpers "github.com/openshift/origin/pkg/user/apis/user/v1" + "k8s.io/kubernetes/pkg/apis/core" + corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1" +) + +// InstallLegacyUser 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 InstallInternalLegacyUser(scheme *runtime.Scheme) { + InstallExternalLegacyUser(scheme) + + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedInternalUserTypes, + core.AddToScheme, + corev1conversions.AddToScheme, + + addLegacyUserFieldSelectorKeyConversions, + userv1helpers.RegisterDefaults, + userv1helpers.RegisterConversions, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func InstallExternalLegacyUser(scheme *runtime.Scheme) { + schemeBuilder := runtime.NewSchemeBuilder( + addUngroupifiedUserTypes, + corev1.AddToScheme, + ) + utilruntime.Must(schemeBuilder.AddToScheme(scheme)) +} + +func addUngroupifiedUserTypes(scheme *runtime.Scheme) error { + types := []runtime.Object{ + &userv1.User{}, + &userv1.UserList{}, + &userv1.Identity{}, + &userv1.IdentityList{}, + &userv1.UserIdentityMapping{}, + &userv1.Group{}, + &userv1.GroupList{}, + } + scheme.AddKnownTypes(GroupVersion, types...) + return nil +} + +func addUngroupifiedInternalUserTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(internalGroupVersion, + &user.User{}, + &user.UserList{}, + &user.Identity{}, + &user.IdentityList{}, + &user.UserIdentityMapping{}, + &user.Group{}, + &user.GroupList{}, + ) + return nil +} + +func addLegacyUserFieldSelectorKeyConversions(scheme *runtime.Scheme) error { + if err := scheme.AddFieldLabelConversionFunc(GroupVersion.String(), "Identity", legacyIdentityFieldSelectorKeyConversionFunc); err != nil { + return err + } + return nil +} + +func legacyIdentityFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { + switch label { + case "providerName", + "providerUserName", + "user.name", + "user.uid": + return label, value, nil + default: + return runtime.DefaultMetaV1FieldSelectorConversion(label, value) + } +} diff --git a/pkg/api/legacy/user_test.go b/pkg/api/legacy/user_test.go new file mode 100644 index 000000000000..9273274d73e9 --- /dev/null +++ b/pkg/api/legacy/user_test.go @@ -0,0 +1,25 @@ +package legacy + +import ( + "testing" + + "k8s.io/apimachinery/pkg/runtime" + + "github.com/openshift/origin/pkg/api/apihelpers/apitesting" + userapi "github.com/openshift/origin/pkg/user/apis/user" +) + +func TestUserFieldSelectorConversions(t *testing.T) { + install := func(scheme *runtime.Scheme) error { + InstallInternalLegacyUser(scheme) + return nil + } + apitesting.FieldKeyCheck{ + SchemeBuilder: []func(*runtime.Scheme) error{install}, + Kind: GroupVersion.WithKind("Identity"), + // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST + AllowedExternalFieldKeys: []string{"providerName", "providerUserName", "user.name", "user.uid"}, + FieldKeyEvaluatorFn: userapi.IdentityFieldSelector, + }.Check(t) + +} diff --git a/pkg/api/meta/pods.go b/pkg/api/meta/pods.go index 75491847119f..0eee101a5f33 100644 --- a/pkg/api/meta/pods.go +++ b/pkg/api/meta/pods.go @@ -19,7 +19,9 @@ import ( oapps "github.com/openshift/api/apps" appsapiv1 "github.com/openshift/api/apps/v1" + "github.com/openshift/api/security" securityapiv1 "github.com/openshift/api/security/v1" + "github.com/openshift/origin/pkg/api/legacy" appsapi "github.com/openshift/origin/pkg/apps/apis/apps" securityapi "github.com/openshift/origin/pkg/security/apis/security" ) @@ -62,15 +64,15 @@ var resourcesToCheck = map[schema.GroupResource]schema.GroupKind{ extensions.Resource("replicasets"): extensions.Kind("ReplicaSet"), apps.Resource("statefulsets"): apps.Kind("StatefulSet"), - {Group: "", Resource: "deploymentconfigs"}: {Group: "", Kind: "DeploymentConfig"}, - {Group: "", Resource: "podsecuritypolicysubjectreviews"}: {Group: "", Kind: "PodSecurityPolicySubjectReview"}, - {Group: "", Resource: "podsecuritypolicyselfsubjectreviews"}: {Group: "", Kind: "PodSecurityPolicySelfSubjectReview"}, - {Group: "", Resource: "podsecuritypolicyreviews"}: {Group: "", Kind: "PodSecurityPolicyReview"}, + legacy.Resource("deploymentconfigs"): legacy.Kind("DeploymentConfig"), + legacy.Resource("podsecuritypolicysubjectreviews"): legacy.Kind("PodSecurityPolicySubjectReview"), + legacy.Resource("podsecuritypolicyselfsubjectreviews"): legacy.Kind("PodSecurityPolicySelfSubjectReview"), + legacy.Resource("podsecuritypolicyreviews"): legacy.Kind("PodSecurityPolicyReview"), - oapps.Resource("deploymentconfigs"): oapps.Kind("DeploymentConfig"), - securityapi.Resource("podsecuritypolicysubjectreviews"): securityapi.Kind("PodSecurityPolicySubjectReview"), - securityapi.Resource("podsecuritypolicyselfsubjectreviews"): securityapi.Kind("PodSecurityPolicySelfSubjectReview"), - securityapi.Resource("podsecuritypolicyreviews"): securityapi.Kind("PodSecurityPolicyReview"), + oapps.Resource("deploymentconfigs"): oapps.Kind("DeploymentConfig"), + security.Resource("podsecuritypolicysubjectreviews"): security.Kind("PodSecurityPolicySubjectReview"), + security.Resource("podsecuritypolicyselfsubjectreviews"): security.Kind("PodSecurityPolicySelfSubjectReview"), + security.Resource("podsecuritypolicyreviews"): security.Kind("PodSecurityPolicyReview"), } // HasPodSpec returns true if the resource is known to have a pod spec. diff --git a/pkg/apps/apis/apps/install/install.go b/pkg/apps/apis/apps/install/install.go index c05cbd007c9a..6019fa257070 100644 --- a/pkg/apps/apis/apps/install/install.go +++ b/pkg/apps/apis/apps/install/install.go @@ -6,7 +6,6 @@ import ( "k8s.io/kubernetes/pkg/api/legacyscheme" appsv1 "github.com/openshift/api/apps/v1" - appsapi "github.com/openshift/origin/pkg/apps/apis/apps" appsapiv1 "github.com/openshift/origin/pkg/apps/apis/apps/v1" ) @@ -16,7 +15,6 @@ func init() { // Install registers the API group and adds types to a scheme func Install(scheme *runtime.Scheme) { - utilruntime.Must(appsapi.AddToScheme(scheme)) utilruntime.Must(appsapiv1.Install(scheme)) utilruntime.Must(scheme.SetVersionPriority(appsv1.GroupVersion)) } diff --git a/pkg/apps/controller/util/scheme.go b/pkg/apps/controller/util/scheme.go index 6b986c0af84e..8b97119c3230 100644 --- a/pkg/apps/controller/util/scheme.go +++ b/pkg/apps/controller/util/scheme.go @@ -22,7 +22,7 @@ var ( ) func init() { - legacy.InstallLegacyApps(annotationDecodingScheme) + legacy.InstallInternalLegacyApps(annotationDecodingScheme) // TODO eventually we shouldn't deal in internal versions, but for now decode into one. utilruntime.Must(appsv1helpers.Install(annotationDecodingScheme)) annotationDecoderCodecFactory := serializer.NewCodecFactory(annotationDecodingScheme) diff --git a/pkg/apps/registry/instantiate/rest_test.go b/pkg/apps/registry/instantiate/rest_test.go index af1ab2da4374..5e5ad2572419 100644 --- a/pkg/apps/registry/instantiate/rest_test.go +++ b/pkg/apps/registry/instantiate/rest_test.go @@ -11,6 +11,7 @@ import ( kapihelper "k8s.io/kubernetes/pkg/apis/core/helper" "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake" + "github.com/openshift/api/image" appsapi "github.com/openshift/origin/pkg/apps/apis/apps" _ "github.com/openshift/origin/pkg/apps/apis/apps/install" appstest "github.com/openshift/origin/pkg/apps/apis/apps/test" @@ -238,7 +239,7 @@ func TestProcess_matchScenarios(t *testing.T) { fake.AddReactor("get", "imagestreams", func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) { if test.notFound { name := action.(clientgotesting.GetAction).GetName() - return true, nil, errors.NewNotFound(imageapi.Resource("ImageStream"), name) + return true, nil, errors.NewNotFound(image.Resource("ImageStream"), name) } stream := fakeStream(appstest.ImageStreamName, imageapi.DefaultImageTag, appstest.DockerImageReference, appstest.ImageID) return true, stream, nil diff --git a/pkg/apps/util/scheme.go b/pkg/apps/util/scheme.go index eb1e4b16abe2..5e78319a75f1 100644 --- a/pkg/apps/util/scheme.go +++ b/pkg/apps/util/scheme.go @@ -21,7 +21,7 @@ var ( ) func init() { - legacy.InstallLegacyApps(annotationDecodingScheme) + legacy.InstallInternalLegacyApps(annotationDecodingScheme) utilruntime.Must(appsv1helpers.Install(annotationDecodingScheme)) annotationDecoderCodecFactory := serializer.NewCodecFactory(annotationDecodingScheme) annotationDecoder = annotationDecoderCodecFactory.UniversalDecoder(appsv1.GroupVersion) diff --git a/pkg/authorization/authorizer/personal_subjectaccessreview.go b/pkg/authorization/authorizer/personal_subjectaccessreview.go index 4b189534adfd..0792fe9fdd6a 100644 --- a/pkg/authorization/authorizer/personal_subjectaccessreview.go +++ b/pkg/authorization/authorizer/personal_subjectaccessreview.go @@ -125,6 +125,6 @@ var ( ) func init() { - legacy.InstallLegacyAuthorization(sarScheme) + legacy.InstallInternalLegacyAuthorization(sarScheme) utilruntime.Must(authorizationv1helpers.Install(sarScheme)) } diff --git a/pkg/authorization/authorizer/scope/converter.go b/pkg/authorization/authorizer/scope/converter.go index ee257f797901..a77c7d4c0057 100644 --- a/pkg/authorization/authorizer/scope/converter.go +++ b/pkg/authorization/authorizer/scope/converter.go @@ -198,7 +198,7 @@ func (userEvaluator) ResolveRules(scope, namespace string, _ rbaclisters.Cluster case UserInfo: return []rbacv1.PolicyRule{ rbacv1helpers.NewRule("get"). - Groups(userapi.GroupName, userapi.LegacyGroupName). + Groups(userapi.GroupName, legacy.GroupName). Resources("users"). Names("~"). RuleOrDie(), @@ -217,14 +217,14 @@ func (userEvaluator) ResolveRules(scope, namespace string, _ rbaclisters.Cluster case UserListScopedProjects: return []rbacv1.PolicyRule{ rbacv1helpers.NewRule("list", "watch"). - Groups(projectapi.GroupName, projectapi.LegacyGroupName). + Groups(projectapi.GroupName, legacy.GroupName). Resources("projects"). RuleOrDie(), }, nil case UserListAllProjects: return []rbacv1.PolicyRule{ rbacv1helpers.NewRule("list", "watch"). - Groups(projectapi.GroupName, projectapi.LegacyGroupName). + Groups(projectapi.GroupName, legacy.GroupName). Resources("projects"). RuleOrDie(), rbacv1helpers.NewRule("get"). @@ -261,7 +261,7 @@ var escalatingScopeResources = []schema.GroupResource{ {Group: kapi.GroupName, Resource: "secrets"}, {Group: imageapi.GroupName, Resource: "imagestreams/secrets"}, - {Group: imageapi.LegacyGroupName, Resource: "imagestreams/secrets"}, + {Group: legacy.GroupName, Resource: "imagestreams/secrets"}, {Group: oauthapi.GroupName, Resource: "oauthauthorizetokens"}, {Group: legacy.GroupName, Resource: "oauthauthorizetokens"}, diff --git a/pkg/build/admission/jenkinsbootstrapper/admission.go b/pkg/build/admission/jenkinsbootstrapper/admission.go index 89ad6f6d0ece..329399c10dbf 100644 --- a/pkg/build/admission/jenkinsbootstrapper/admission.go +++ b/pkg/build/admission/jenkinsbootstrapper/admission.go @@ -17,7 +17,9 @@ import ( coreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion" kadmission "k8s.io/kubernetes/pkg/kubeapiserver/admission" + "github.com/openshift/api/build" templateclient "github.com/openshift/client-go/template/clientset/versioned" + "github.com/openshift/origin/pkg/api/legacy" jenkinscontroller "github.com/openshift/origin/pkg/build/admission/jenkinsbootstrapper/jenkins" buildapi "github.com/openshift/origin/pkg/build/apis/build" authenticationclient "github.com/openshift/origin/pkg/client/impersonatingclient" @@ -65,10 +67,10 @@ func (a *jenkinsBootstrapper) Admit(attributes admission.Attributes) error { } gr := attributes.GetResource().GroupResource() switch gr { - case buildapi.Resource("buildconfigs"), - buildapi.Resource("builds"), - buildapi.LegacyResource("buildconfigs"), - buildapi.LegacyResource("builds"): + case build.Resource("buildconfigs"), + build.Resource("builds"), + legacy.Resource("buildconfigs"), + legacy.Resource("builds"): default: return nil } diff --git a/pkg/build/admission/jenkinsbootstrapper/admission_test.go b/pkg/build/admission/jenkinsbootstrapper/admission_test.go index bd185e26dbe9..aa841c12e635 100644 --- a/pkg/build/admission/jenkinsbootstrapper/admission_test.go +++ b/pkg/build/admission/jenkinsbootstrapper/admission_test.go @@ -14,6 +14,7 @@ import ( "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake" templatefake "github.com/openshift/client-go/template/clientset/versioned/fake" + "github.com/openshift/origin/pkg/api/legacy" buildapi "github.com/openshift/origin/pkg/build/apis/build" configapi "github.com/openshift/origin/pkg/cmd/server/apis/config" ) @@ -32,37 +33,37 @@ func TestAdmission(t *testing.T) { }{ { name: "disabled", - attributes: admission.NewAttributesRecord(enableBuild, nil, schema.GroupVersionKind{}, "namespace", "name", buildapi.LegacySchemeGroupVersion.WithResource("builds"), "", admission.Create, &user.DefaultInfo{}), + attributes: admission.NewAttributesRecord(enableBuild, nil, schema.GroupVersionKind{}, "namespace", "name", legacy.GroupVersion.WithResource("builds"), "", admission.Create, &user.DefaultInfo{}), jenkinsEnabled: boolptr(false), validateClients: noAction, }, { name: "not a jenkins build", - attributes: admission.NewAttributesRecord(&buildapi.Build{Spec: buildapi.BuildSpec{CommonSpec: buildapi.CommonSpec{Strategy: buildapi.BuildStrategy{}}}}, nil, schema.GroupVersionKind{}, "namespace", "name", buildapi.LegacySchemeGroupVersion.WithResource("builds"), "", admission.Create, &user.DefaultInfo{}), + attributes: admission.NewAttributesRecord(&buildapi.Build{Spec: buildapi.BuildSpec{CommonSpec: buildapi.CommonSpec{Strategy: buildapi.BuildStrategy{}}}}, nil, schema.GroupVersionKind{}, "namespace", "name", legacy.GroupVersion.WithResource("builds"), "", admission.Create, &user.DefaultInfo{}), jenkinsEnabled: boolptr(true), validateClients: noAction, }, { name: "not a build kind", - attributes: admission.NewAttributesRecord(&kapi.Service{}, nil, schema.GroupVersionKind{}, "namespace", "name", buildapi.LegacySchemeGroupVersion.WithResource("builds"), "", admission.Create, &user.DefaultInfo{}), + attributes: admission.NewAttributesRecord(&kapi.Service{}, nil, schema.GroupVersionKind{}, "namespace", "name", legacy.GroupVersion.WithResource("builds"), "", admission.Create, &user.DefaultInfo{}), jenkinsEnabled: boolptr(true), validateClients: noAction, }, { name: "not a build resource", - attributes: admission.NewAttributesRecord(enableBuild, nil, schema.GroupVersionKind{}, "namespace", "name", buildapi.LegacySchemeGroupVersion.WithResource("notbuilds"), "", admission.Create, &user.DefaultInfo{}), + attributes: admission.NewAttributesRecord(enableBuild, nil, schema.GroupVersionKind{}, "namespace", "name", legacy.GroupVersion.WithResource("notbuilds"), "", admission.Create, &user.DefaultInfo{}), jenkinsEnabled: boolptr(true), validateClients: noAction, }, { name: "subresource", - attributes: admission.NewAttributesRecord(enableBuild, nil, schema.GroupVersionKind{}, "namespace", "name", buildapi.LegacySchemeGroupVersion.WithResource("builds"), "subresource", admission.Create, &user.DefaultInfo{}), + attributes: admission.NewAttributesRecord(enableBuild, nil, schema.GroupVersionKind{}, "namespace", "name", legacy.GroupVersion.WithResource("builds"), "subresource", admission.Create, &user.DefaultInfo{}), jenkinsEnabled: boolptr(true), validateClients: noAction, }, { name: "service present", - attributes: admission.NewAttributesRecord(enableBuild, nil, schema.GroupVersionKind{}, "namespace", "name", buildapi.LegacySchemeGroupVersion.WithResource("builds"), "", admission.Create, &user.DefaultInfo{}), + attributes: admission.NewAttributesRecord(enableBuild, nil, schema.GroupVersionKind{}, "namespace", "name", legacy.GroupVersion.WithResource("builds"), "", admission.Create, &user.DefaultInfo{}), jenkinsEnabled: boolptr(true), objects: []runtime.Object{ &kapi.Service{ObjectMeta: metav1.ObjectMeta{Namespace: "namespace", Name: "jenkins"}}, @@ -76,7 +77,7 @@ func TestAdmission(t *testing.T) { }, { name: "works on true", - attributes: admission.NewAttributesRecord(enableBuild, nil, schema.GroupVersionKind{}, "namespace", "name", buildapi.LegacySchemeGroupVersion.WithResource("builds"), "", admission.Create, &user.DefaultInfo{}), + attributes: admission.NewAttributesRecord(enableBuild, nil, schema.GroupVersionKind{}, "namespace", "name", legacy.GroupVersion.WithResource("builds"), "", admission.Create, &user.DefaultInfo{}), objects: []runtime.Object{ &kapi.Service{ObjectMeta: metav1.ObjectMeta{Namespace: "namespace", Name: "jenkins"}}, }, @@ -90,7 +91,7 @@ func TestAdmission(t *testing.T) { }, { name: "enabled default", - attributes: admission.NewAttributesRecord(enableBuild, nil, schema.GroupVersionKind{}, "namespace", "name", buildapi.LegacySchemeGroupVersion.WithResource("builds"), "", admission.Create, &user.DefaultInfo{}), + attributes: admission.NewAttributesRecord(enableBuild, nil, schema.GroupVersionKind{}, "namespace", "name", legacy.GroupVersion.WithResource("builds"), "", admission.Create, &user.DefaultInfo{}), objects: []runtime.Object{ &kapi.Service{ObjectMeta: metav1.ObjectMeta{Namespace: "namespace", Name: "jenkins"}}, }, @@ -103,7 +104,7 @@ func TestAdmission(t *testing.T) { }, { name: "service missing", - attributes: admission.NewAttributesRecord(enableBuild, nil, schema.GroupVersionKind{}, "namespace", "name", buildapi.LegacySchemeGroupVersion.WithResource("builds"), "", admission.Create, &user.DefaultInfo{}), + attributes: admission.NewAttributesRecord(enableBuild, nil, schema.GroupVersionKind{}, "namespace", "name", legacy.GroupVersion.WithResource("builds"), "", admission.Create, &user.DefaultInfo{}), jenkinsEnabled: boolptr(true), objects: []runtime.Object{}, validateClients: func(kubeClient *fake.Clientset, templateClient *templatefake.Clientset) string { diff --git a/pkg/build/admission/strategyrestrictions/admission.go b/pkg/build/admission/strategyrestrictions/admission.go index df2ef2fc576f..91235199b015 100644 --- a/pkg/build/admission/strategyrestrictions/admission.go +++ b/pkg/build/admission/strategyrestrictions/admission.go @@ -5,6 +5,8 @@ import ( "io" "strings" + "github.com/openshift/api/build" + "github.com/openshift/origin/pkg/api/legacy" "github.com/openshift/origin/pkg/build/buildscheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" @@ -50,10 +52,10 @@ func NewBuildByStrategy() admission.Interface { func (a *buildByStrategy) Admit(attr admission.Attributes) error { gr := attr.GetResource().GroupResource() switch gr { - case buildapi.Resource("buildconfigs"), - buildapi.LegacyResource("buildconfigs"): - case buildapi.Resource("builds"), - buildapi.LegacyResource("builds"): + case build.Resource("buildconfigs"), + legacy.Resource("buildconfigs"): + case build.Resource("builds"), + legacy.Resource("builds"): // Explicitly exclude the builds/details subresource because it's only // updating commit info and cannot change build type. if attr.GetSubresource() == "details" { @@ -103,15 +105,15 @@ func (a *buildByStrategy) ValidateInitialization() error { func resourceForStrategyType(strategy buildapi.BuildStrategy) (schema.GroupResource, error) { switch { case strategy.DockerStrategy != nil && strategy.DockerStrategy.ImageOptimizationPolicy != nil && *strategy.DockerStrategy.ImageOptimizationPolicy != buildapi.ImageOptimizationNone: - return buildapi.Resource(bootstrappolicy.OptimizedDockerBuildResource), nil + return build.Resource(bootstrappolicy.OptimizedDockerBuildResource), nil case strategy.DockerStrategy != nil: - return buildapi.Resource(bootstrappolicy.DockerBuildResource), nil + return build.Resource(bootstrappolicy.DockerBuildResource), nil case strategy.CustomStrategy != nil: - return buildapi.Resource(bootstrappolicy.CustomBuildResource), nil + return build.Resource(bootstrappolicy.CustomBuildResource), nil case strategy.SourceStrategy != nil: - return buildapi.Resource(bootstrappolicy.SourceBuildResource), nil + return build.Resource(bootstrappolicy.SourceBuildResource), nil case strategy.JenkinsPipelineStrategy != nil: - return buildapi.Resource(bootstrappolicy.JenkinsPipelineBuildResource), nil + return build.Resource(bootstrappolicy.JenkinsPipelineBuildResource), nil default: return schema.GroupResource{}, fmt.Errorf("unrecognized build strategy: %#v", strategy) } @@ -183,8 +185,8 @@ func (a *buildByStrategy) checkBuildConfigAuthorization(buildConfig *buildapi.Bu func (a *buildByStrategy) checkBuildRequestAuthorization(req *buildapi.BuildRequest, attr admission.Attributes) error { gr := attr.GetResource().GroupResource() switch gr { - case buildapi.Resource("builds"), - buildapi.LegacyResource("builds"): + case build.Resource("builds"), + legacy.Resource("builds"): build, err := a.buildClient.BuildV1().Builds(attr.GetNamespace()).Get(req.Name, metav1.GetOptions{}) if err != nil { return admission.NewForbidden(attr, err) @@ -195,8 +197,8 @@ func (a *buildByStrategy) checkBuildRequestAuthorization(req *buildapi.BuildRequ } return a.checkBuildAuthorization(internalBuild, attr) - case buildapi.Resource("buildconfigs"), - buildapi.LegacyResource("buildconfigs"): + case build.Resource("buildconfigs"), + legacy.Resource("buildconfigs"): buildConfig, err := a.buildClient.BuildV1().BuildConfigs(attr.GetNamespace()).Get(req.Name, metav1.GetOptions{}) if err != nil { return admission.NewForbidden(attr, err) diff --git a/pkg/build/admission/strategyrestrictions/admission_test.go b/pkg/build/admission/strategyrestrictions/admission_test.go index c438270b4723..079700d4ee77 100644 --- a/pkg/build/admission/strategyrestrictions/admission_test.go +++ b/pkg/build/admission/strategyrestrictions/admission_test.go @@ -20,6 +20,7 @@ import ( buildapi "github.com/openshift/origin/pkg/build/apis/build" oadmission "github.com/openshift/origin/pkg/cmd/server/admission" + "github.com/openshift/api/build" _ "github.com/openshift/origin/pkg/build/apis/build/install" ) @@ -41,8 +42,8 @@ func TestBuildAdmission(t *testing.T) { { name: "allowed source build", object: internalTestBuild(buildapi.BuildStrategy{SourceStrategy: &buildapi.SourceBuildStrategy{}}), - kind: buildapi.Kind("Build"), - resource: buildapi.Resource("builds"), + kind: build.Kind("Build"), + resource: build.Resource("builds"), reviewResponse: reviewResponse(true, ""), expectedResource: "builds", expectedSubresource: "source", @@ -52,8 +53,8 @@ func TestBuildAdmission(t *testing.T) { name: "allowed source build clone", object: testBuildRequest("test-build"), responseObject: v1TestBuild(buildapiv1.BuildStrategy{SourceStrategy: &buildapiv1.SourceBuildStrategy{}}), - kind: buildapi.Kind("Build"), - resource: buildapi.Resource("builds"), + kind: build.Kind("Build"), + resource: build.Resource("builds"), subResource: "clone", reviewResponse: reviewResponse(true, ""), expectedResource: "builds", @@ -63,8 +64,8 @@ func TestBuildAdmission(t *testing.T) { { name: "denied docker build", object: internalTestBuild(buildapi.BuildStrategy{DockerStrategy: &buildapi.DockerBuildStrategy{}}), - kind: buildapi.Kind("Build"), - resource: buildapi.Resource("builds"), + kind: build.Kind("Build"), + resource: build.Resource("builds"), reviewResponse: reviewResponse(false, "cannot create build of type docker build"), expectAccept: false, expectedResource: "builds", @@ -74,8 +75,8 @@ func TestBuildAdmission(t *testing.T) { name: "denied docker build clone", object: testBuildRequest("buildname"), responseObject: v1TestBuild(buildapiv1.BuildStrategy{DockerStrategy: &buildapiv1.DockerBuildStrategy{}}), - kind: buildapi.Kind("Build"), - resource: buildapi.Resource("builds"), + kind: build.Kind("Build"), + resource: build.Resource("builds"), subResource: "clone", reviewResponse: reviewResponse(false, "cannot create build of type docker build"), expectAccept: false, @@ -85,8 +86,8 @@ func TestBuildAdmission(t *testing.T) { { name: "allowed custom build", object: internalTestBuild(buildapi.BuildStrategy{CustomStrategy: &buildapi.CustomBuildStrategy{}}), - kind: buildapi.Kind("Build"), - resource: buildapi.Resource("builds"), + kind: build.Kind("Build"), + resource: build.Resource("builds"), reviewResponse: reviewResponse(true, ""), expectedResource: "builds", expectedSubresource: "custom", @@ -95,8 +96,8 @@ func TestBuildAdmission(t *testing.T) { { name: "allowed build config", object: internalTestBuildConfig(buildapi.BuildStrategy{DockerStrategy: &buildapi.DockerBuildStrategy{}}), - kind: buildapi.Kind("BuildConfig"), - resource: buildapi.Resource("buildconfigs"), + kind: build.Kind("BuildConfig"), + resource: build.Resource("buildconfigs"), reviewResponse: reviewResponse(true, ""), expectAccept: true, expectedResource: "builds", @@ -106,8 +107,8 @@ func TestBuildAdmission(t *testing.T) { name: "allowed build config instantiate", responseObject: v1TestBuildConfig(buildapiv1.BuildStrategy{DockerStrategy: &buildapiv1.DockerBuildStrategy{}}), object: testBuildRequest("test-buildconfig"), - kind: buildapi.Kind("Build"), - resource: buildapi.Resource("buildconfigs"), + kind: build.Kind("Build"), + resource: build.Resource("buildconfigs"), subResource: "instantiate", reviewResponse: reviewResponse(true, ""), expectAccept: true, @@ -117,8 +118,8 @@ func TestBuildAdmission(t *testing.T) { { name: "forbidden build config", object: internalTestBuildConfig(buildapi.BuildStrategy{CustomStrategy: &buildapi.CustomBuildStrategy{}}), - kind: buildapi.Kind("Build"), - resource: buildapi.Resource("buildconfigs"), + kind: build.Kind("Build"), + resource: build.Resource("buildconfigs"), reviewResponse: reviewResponse(false, ""), expectAccept: false, expectedResource: "builds", @@ -128,8 +129,8 @@ func TestBuildAdmission(t *testing.T) { name: "forbidden build config instantiate", responseObject: v1TestBuildConfig(buildapiv1.BuildStrategy{CustomStrategy: &buildapiv1.CustomBuildStrategy{}}), object: testBuildRequest("buildname"), - kind: buildapi.Kind("Build"), - resource: buildapi.Resource("buildconfigs"), + kind: build.Kind("Build"), + resource: build.Resource("buildconfigs"), subResource: "instantiate", reviewResponse: reviewResponse(false, ""), expectAccept: false, @@ -139,8 +140,8 @@ func TestBuildAdmission(t *testing.T) { { name: "unrecognized request object", object: &fakeObject{}, - kind: buildapi.Kind("BuildConfig"), - resource: buildapi.Resource("buildconfigs"), + kind: build.Kind("BuildConfig"), + resource: build.Resource("buildconfigs"), reviewResponse: reviewResponse(true, ""), expectAccept: false, expectedError: "Internal error occurred: [Unrecognized request object &admission.fakeObject{}, couldn't find ObjectMeta field in admission.fakeObject{}]", @@ -148,8 +149,8 @@ func TestBuildAdmission(t *testing.T) { { name: "details on forbidden docker build", object: internalTestBuild(buildapi.BuildStrategy{DockerStrategy: &buildapi.DockerBuildStrategy{}}), - kind: buildapi.Kind("Build"), - resource: buildapi.Resource("builds"), + kind: build.Kind("Build"), + resource: build.Resource("builds"), subResource: "details", reviewResponse: reviewResponse(false, "cannot create build of type docker build"), expectAccept: true, @@ -157,8 +158,8 @@ func TestBuildAdmission(t *testing.T) { { name: "allowed jenkins pipeline build", object: internalTestBuild(buildapi.BuildStrategy{JenkinsPipelineStrategy: &buildapi.JenkinsPipelineBuildStrategy{}}), - kind: buildapi.Kind("Build"), - resource: buildapi.Resource("builds"), + kind: build.Kind("Build"), + resource: build.Resource("builds"), reviewResponse: reviewResponse(true, ""), expectedResource: "builds", expectedSubresource: "jenkinspipeline", @@ -168,8 +169,8 @@ func TestBuildAdmission(t *testing.T) { name: "allowed jenkins pipeline build clone", object: testBuildRequest("test-build"), responseObject: v1TestBuild(buildapiv1.BuildStrategy{JenkinsPipelineStrategy: &buildapiv1.JenkinsPipelineBuildStrategy{}}), - kind: buildapi.Kind("Build"), - resource: buildapi.Resource("builds"), + kind: build.Kind("Build"), + resource: build.Resource("builds"), subResource: "clone", reviewResponse: reviewResponse(true, ""), expectedResource: "builds", diff --git a/pkg/build/apis/build/install/install.go b/pkg/build/apis/build/install/install.go index 39d71a14f863..f7ee865a5549 100644 --- a/pkg/build/apis/build/install/install.go +++ b/pkg/build/apis/build/install/install.go @@ -5,7 +5,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/kubernetes/pkg/api/legacyscheme" - buildapi "github.com/openshift/origin/pkg/build/apis/build" + buildv1 "github.com/openshift/api/build/v1" buildapiv1 "github.com/openshift/origin/pkg/build/apis/build/v1" ) @@ -15,7 +15,6 @@ func init() { // Install registers the API group and adds types to a scheme func Install(scheme *runtime.Scheme) { - utilruntime.Must(buildapi.AddToScheme(scheme)) - utilruntime.Must(buildapiv1.AddToScheme(scheme)) - utilruntime.Must(scheme.SetVersionPriority(buildapiv1.SchemeGroupVersion)) + utilruntime.Must(buildapiv1.Install(scheme)) + utilruntime.Must(scheme.SetVersionPriority(buildv1.GroupVersion)) } diff --git a/pkg/build/apis/build/register.go b/pkg/build/apis/build/register.go index e7cbb375a05f..24c1015c26fc 100644 --- a/pkg/build/apis/build/register.go +++ b/pkg/build/apis/build/register.go @@ -3,40 +3,33 @@ package build import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - kapi "k8s.io/kubernetes/pkg/apis/core" + "k8s.io/kubernetes/pkg/apis/core" ) const ( - GroupName = "build.openshift.io" - LegacyGroupName = "" + GroupName = "build.openshift.io" ) var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: runtime.APIVersionInternal} - - LegacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme + schemeBuilder = runtime.NewSchemeBuilder( + addKnownTypes, + core.AddToScheme, + ) + Install = schemeBuilder.AddToScheme - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // DEPRECATED kept for generated code + SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} + // DEPRECATED kept for generated code + AddToScheme = schemeBuilder.AddToScheme ) -// Kind takes an unqualified kind and returns back a Group qualified GroupKind -func Kind(kind string) schema.GroupKind { - return SchemeGroupVersion.WithKind(kind).GroupKind() -} - -// Resource takes an unqualified resource and returns back a Group qualified GroupResource +// Resource kept for generated code +// DEPRECATED func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } -func LegacyResource(resource string) schema.GroupResource { - return LegacySchemeGroupVersion.WithResource(resource).GroupResource() -} - -// addKnownTypes adds types to API group +// Adds the list of known types to api.Scheme. func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &Build{}, @@ -48,24 +41,7 @@ func addKnownTypes(scheme *runtime.Scheme) error { &BuildLogOptions{}, &BinaryBuildRequestOptions{}, // This is needed for webhooks - &kapi.PodProxyOptions{}, + &core.PodProxyOptions{}, ) return nil } - -// addLegacyKnownTypes adds types to legacy API group -// DEPRECATED: This will be deprecated and should not be modified. -func addLegacyKnownTypes(scheme *runtime.Scheme) error { - types := []runtime.Object{ - &Build{}, - &BuildList{}, - &BuildConfig{}, - &BuildConfigList{}, - &BuildLog{}, - &BuildRequest{}, - &BuildLogOptions{}, - &BinaryBuildRequestOptions{}, - } - scheme.AddKnownTypes(LegacySchemeGroupVersion, types...) - return nil -} diff --git a/pkg/build/apis/build/v1/conversion.go b/pkg/build/apis/build/v1/conversion.go index 0395d445389a..1eb26eb6a66b 100644 --- a/pkg/build/apis/build/v1/conversion.go +++ b/pkg/build/apis/build/v1/conversion.go @@ -5,7 +5,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "github.com/openshift/api/build/v1" - "github.com/openshift/origin/pkg/api/apihelpers" newer "github.com/openshift/origin/pkg/build/apis/build" imageapi "github.com/openshift/origin/pkg/image/apis/image" ) @@ -150,7 +149,7 @@ func Convert_build_BuildStrategy_To_v1_BuildStrategy(in *newer.BuildStrategy, ou return nil } -func addConversionFuncs(scheme *runtime.Scheme) error { +func AddConversionFuncs(scheme *runtime.Scheme) error { return scheme.AddConversionFuncs( Convert_v1_BuildConfig_To_build_BuildConfig, Convert_build_BuildConfig_To_v1_BuildConfig, @@ -173,31 +172,8 @@ func addConversionFuncs(scheme *runtime.Scheme) error { ) } -func addLegacyFieldSelectorKeyConversions(scheme *runtime.Scheme) error { - if err := scheme.AddFieldLabelConversionFunc(LegacySchemeGroupVersion.String(), "Build", legacyBuildFieldSelectorKeyConversionFunc); err != nil { - return err - } - if err := scheme.AddFieldLabelConversionFunc(LegacySchemeGroupVersion.String(), "BuildConfig", apihelpers.LegacyMetaV1FieldSelectorConversionWithName); err != nil { - return err - } - return nil -} - -func addFieldSelectorKeyConversions(scheme *runtime.Scheme) error { - return scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.String(), "Build", buildFieldSelectorKeyConversionFunc) -} - -// 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) - } +func AddFieldSelectorKeyConversions(scheme *runtime.Scheme) error { + return scheme.AddFieldLabelConversionFunc(v1.GroupVersion.String(), "Build", buildFieldSelectorKeyConversionFunc) } func buildFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { diff --git a/pkg/build/apis/build/v1/conversion_test.go b/pkg/build/apis/build/v1/conversion_test.go index b3b1d1fb4053..3e293bafd324 100644 --- a/pkg/build/apis/build/v1/conversion_test.go +++ b/pkg/build/apis/build/v1/conversion_test.go @@ -3,16 +3,16 @@ package v1 import ( "testing" - kolder "k8s.io/api/core/v1" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/conversion/queryparams" runtime "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer" - knewer "k8s.io/kubernetes/pkg/apis/core" + kinternal "k8s.io/kubernetes/pkg/apis/core" - v1 "github.com/openshift/api/build/v1" + "github.com/openshift/api/build/v1" "github.com/openshift/origin/pkg/api/apihelpers/apitesting" - newer "github.com/openshift/origin/pkg/build/apis/build" + internal "github.com/openshift/origin/pkg/build/apis/build" ) var scheme = runtime.NewScheme() @@ -20,45 +20,27 @@ var Convert = scheme.Convert var codecs = serializer.NewCodecFactory(scheme) func init() { - LegacySchemeBuilder.AddToScheme(scheme) - newer.LegacySchemeBuilder.AddToScheme(scheme) - SchemeBuilder.AddToScheme(scheme) - newer.SchemeBuilder.AddToScheme(scheme) + Install(scheme) } func TestFieldSelectorConversions(t *testing.T) { - apitesting.FieldKeyCheck{ - SchemeBuilder: []func(*runtime.Scheme) error{LegacySchemeBuilder.AddToScheme, newer.LegacySchemeBuilder.AddToScheme}, - Kind: LegacySchemeGroupVersion.WithKind("Build"), - // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST - AllowedExternalFieldKeys: []string{"name", "status", "podName"}, - FieldKeyEvaluatorFn: newer.BuildFieldSelector, - }.Check(t) - - apitesting.FieldKeyCheck{ - SchemeBuilder: []func(*runtime.Scheme) error{LegacySchemeBuilder.AddToScheme, newer.LegacySchemeBuilder.AddToScheme}, - Kind: LegacySchemeGroupVersion.WithKind("BuildConfig"), - // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST - AllowedExternalFieldKeys: []string{"name"}, - }.Check(t) apitesting.FieldKeyCheck{ - SchemeBuilder: []func(*runtime.Scheme) error{SchemeBuilder.AddToScheme, newer.SchemeBuilder.AddToScheme}, - Kind: SchemeGroupVersion.WithKind("Build"), + SchemeBuilder: []func(*runtime.Scheme) error{Install}, + Kind: v1.GroupVersion.WithKind("Build"), // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST AllowedExternalFieldKeys: []string{"status", "podName"}, - FieldKeyEvaluatorFn: newer.BuildFieldSelector, + FieldKeyEvaluatorFn: internal.BuildFieldSelector, }.Check(t) } func TestBinaryBuildRequestOptions(t *testing.T) { - - r := &newer.BinaryBuildRequestOptions{ + r := &internal.BinaryBuildRequestOptions{ AsFile: "Dockerfile", Commit: "abcdef", } - versioned, err := scheme.ConvertToVersion(r, kolder.SchemeGroupVersion) + versioned, err := scheme.ConvertToVersion(r, v1.GroupVersion) if err != nil { t.Fatal(err) } @@ -91,14 +73,14 @@ func TestV1APIBuildConfigConversion(t *testing.T) { Strategy: v1.BuildStrategy{ Type: v1.DockerBuildStrategyType, DockerStrategy: &v1.DockerBuildStrategy{ - From: &kolder.ObjectReference{ + From: &corev1.ObjectReference{ Kind: "ImageStream", Name: "fromstream", }, }, }, Output: v1.BuildOutput{ - To: &kolder.ObjectReference{ + To: &corev1.ObjectReference{ Kind: "ImageStream", Name: "outputstream", }, @@ -131,14 +113,14 @@ func TestV1APIBuildConfigConversion(t *testing.T) { Strategy: v1.BuildStrategy{ Type: v1.SourceBuildStrategyType, SourceStrategy: &v1.SourceBuildStrategy{ - From: kolder.ObjectReference{ + From: corev1.ObjectReference{ Kind: "ImageStream", Name: "fromstream", }, }, }, Output: v1.BuildOutput{ - To: &kolder.ObjectReference{ + To: &corev1.ObjectReference{ Kind: "ImageStream", Name: "outputstream", }, @@ -171,14 +153,14 @@ func TestV1APIBuildConfigConversion(t *testing.T) { Strategy: v1.BuildStrategy{ Type: v1.CustomBuildStrategyType, CustomStrategy: &v1.CustomBuildStrategy{ - From: kolder.ObjectReference{ + From: corev1.ObjectReference{ Kind: "ImageStream", Name: "fromstream", }, }, }, Output: v1.BuildOutput{ - To: &kolder.ObjectReference{ + To: &corev1.ObjectReference{ Kind: "ImageStream", Name: "outputstream", }, @@ -201,7 +183,7 @@ func TestV1APIBuildConfigConversion(t *testing.T) { for c, bc := range buildConfigs { - var internalbuild newer.BuildConfig + var internalbuild internal.BuildConfig Convert(bc, &internalbuild, nil) switch bc.Spec.Strategy.Type { @@ -224,13 +206,13 @@ func TestV1APIBuildConfigConversion(t *testing.T) { var foundImageChange, foundGitHub, foundGeneric bool for _, trigger := range internalbuild.Spec.Triggers { switch trigger.Type { - case newer.ImageChangeBuildTriggerType: + case internal.ImageChangeBuildTriggerType: foundImageChange = true - case newer.GenericWebHookBuildTriggerType: + case internal.GenericWebHookBuildTriggerType: foundGeneric = true - case newer.GitHubWebHookBuildTriggerType: + case internal.GitHubWebHookBuildTriggerType: foundGitHub = true } } @@ -247,15 +229,15 @@ func TestV1APIBuildConfigConversion(t *testing.T) { } func TestAPIV1NoSourceBuildConfigConversion(t *testing.T) { - buildConfigs := []*newer.BuildConfig{ + buildConfigs := []*internal.BuildConfig{ { ObjectMeta: metav1.ObjectMeta{Name: "config-id", Namespace: "namespace"}, - Spec: newer.BuildConfigSpec{ - CommonSpec: newer.CommonSpec{ - Source: newer.BuildSource{}, - Strategy: newer.BuildStrategy{ - DockerStrategy: &newer.DockerBuildStrategy{ - From: &knewer.ObjectReference{ + Spec: internal.BuildConfigSpec{ + CommonSpec: internal.CommonSpec{ + Source: internal.BuildSource{}, + Strategy: internal.BuildStrategy{ + DockerStrategy: &internal.DockerBuildStrategy{ + From: &kinternal.ObjectReference{ Kind: "ImageStream", Name: "fromstream", }, @@ -266,12 +248,12 @@ func TestAPIV1NoSourceBuildConfigConversion(t *testing.T) { }, { ObjectMeta: metav1.ObjectMeta{Name: "config-id", Namespace: "namespace"}, - Spec: newer.BuildConfigSpec{ - CommonSpec: newer.CommonSpec{ - Source: newer.BuildSource{}, - Strategy: newer.BuildStrategy{ - SourceStrategy: &newer.SourceBuildStrategy{ - From: knewer.ObjectReference{ + Spec: internal.BuildConfigSpec{ + CommonSpec: internal.CommonSpec{ + Source: internal.BuildSource{}, + Strategy: internal.BuildStrategy{ + SourceStrategy: &internal.SourceBuildStrategy{ + From: kinternal.ObjectReference{ Kind: "ImageStream", Name: "fromstream", }, @@ -282,12 +264,12 @@ func TestAPIV1NoSourceBuildConfigConversion(t *testing.T) { }, { ObjectMeta: metav1.ObjectMeta{Name: "config-id", Namespace: "namespace"}, - Spec: newer.BuildConfigSpec{ - CommonSpec: newer.CommonSpec{ - Source: newer.BuildSource{}, - Strategy: newer.BuildStrategy{ - CustomStrategy: &newer.CustomBuildStrategy{ - From: knewer.ObjectReference{ + Spec: internal.BuildConfigSpec{ + CommonSpec: internal.CommonSpec{ + Source: internal.BuildSource{}, + Strategy: internal.BuildStrategy{ + CustomStrategy: &internal.CustomBuildStrategy{ + From: kinternal.ObjectReference{ Kind: "ImageStream", Name: "fromstream", }, @@ -317,7 +299,7 @@ func TestInvalidImageChangeTriggerRemoval(t *testing.T) { Strategy: v1.BuildStrategy{ Type: v1.DockerBuildStrategyType, DockerStrategy: &v1.DockerBuildStrategy{ - From: &kolder.ObjectReference{ + From: &corev1.ObjectReference{ Kind: "DockerImage", Name: "fromimage", }, @@ -332,7 +314,7 @@ func TestInvalidImageChangeTriggerRemoval(t *testing.T) { { Type: v1.ImageChangeBuildTriggerType, ImageChange: &v1.ImageChangeTrigger{ - From: &kolder.ObjectReference{ + From: &corev1.ObjectReference{ Kind: "ImageStreamTag", Name: "imagestream", }, @@ -342,7 +324,7 @@ func TestInvalidImageChangeTriggerRemoval(t *testing.T) { }, } - var internalBC newer.BuildConfig + var internalBC internal.BuildConfig Convert(&buildConfig, &internalBC, nil) if len(internalBC.Spec.Triggers) != 1 { @@ -373,7 +355,7 @@ func TestImageChangeTriggerNilImageChangePointer(t *testing.T) { }, } - var internalBC newer.BuildConfig + var internalBC internal.BuildConfig Convert(&buildConfig, &internalBC, nil) for _, ic := range internalBC.Spec.Triggers { diff --git a/pkg/build/apis/build/v1/defaults_test.go b/pkg/build/apis/build/v1/defaults_test.go index e77c40a2607c..af46cf264b30 100644 --- a/pkg/build/apis/build/v1/defaults_test.go +++ b/pkg/build/apis/build/v1/defaults_test.go @@ -144,7 +144,7 @@ func TestDefaults(t *testing.T) { } func roundTrip(t *testing.T, obj runtime.Object) runtime.Object { - data, err := runtime.Encode(codecs.LegacyCodec(LegacySchemeGroupVersion), obj) + data, err := runtime.Encode(codecs.LegacyCodec(v1.GroupVersion), obj) if err != nil { t.Errorf("%v\n %#v", err, obj) return nil diff --git a/pkg/build/apis/build/v1/register.go b/pkg/build/apis/build/v1/register.go index ed2f44148e00..67890eef21e0 100644 --- a/pkg/build/apis/build/v1/register.go +++ b/pkg/build/apis/build/v1/register.go @@ -1,38 +1,21 @@ package v1 import ( - "github.com/openshift/api/build/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) + corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1" -const GroupName = "build.openshift.io" -const LegacyGroupName = "" + "github.com/openshift/api/build/v1" + "github.com/openshift/origin/pkg/build/apis/build" +) var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: "v1"} - - LegacySchemeBuilder = runtime.NewSchemeBuilder(v1.DeprecatedInstallWithoutGroup, addConversionFuncs, addLegacyFieldSelectorKeyConversions, RegisterDefaults, RegisterConversions) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme - - SchemeBuilder = runtime.NewSchemeBuilder(v1.Install, addConversionFuncs, addFieldSelectorKeyConversions, RegisterDefaults) - AddToScheme = SchemeBuilder.AddToScheme - - localSchemeBuilder = &SchemeBuilder + localSchemeBuilder = runtime.NewSchemeBuilder( + build.Install, + v1.Install, + corev1conversions.AddToScheme, + AddConversionFuncs, + AddFieldSelectorKeyConversions, + RegisterDefaults, + ) + Install = localSchemeBuilder.AddToScheme ) - -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} - -// LegacyResource takes an unqualified resource and returns back a Group qualified GroupResource -func LegacyResource(resource string) schema.GroupResource { - return LegacySchemeGroupVersion.WithResource(resource).GroupResource() -} - -// IsResourceOrLegacy checks if the provided GroupResources matches with the given -// resource by looking up the API group and also the legacy API. -func IsResourceOrLegacy(resource string, gr schema.GroupResource) bool { - return gr == Resource(resource) || gr == LegacyResource(resource) -} diff --git a/pkg/build/builder/cmd/builder.go b/pkg/build/builder/cmd/builder.go index 5714221a5223..e258f4b5f3b3 100644 --- a/pkg/build/builder/cmd/builder.go +++ b/pkg/build/builder/cmd/builder.go @@ -36,7 +36,7 @@ var ( func init() { // TODO only use external versions, so we only add external types - legacy.InstallLegacyBuild(buildEnvVarScheme) + legacy.InstallInternalLegacyBuild(buildEnvVarScheme) utilruntime.Must(buildapiv1.AddToScheme(buildEnvVarScheme)) buildEnvVarJSONCodec = buildEnvVarCodecFactory.LegacyCodec(buildapiv1.SchemeGroupVersion, legacy.GroupVersion) } diff --git a/pkg/build/buildscheme/scheme.go b/pkg/build/buildscheme/scheme.go index 524bd67988c8..1510e386c4d9 100644 --- a/pkg/build/buildscheme/scheme.go +++ b/pkg/build/buildscheme/scheme.go @@ -6,6 +6,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" buildv1 "github.com/openshift/api/build/v1" + "github.com/openshift/origin/pkg/api/legacy" buildapi "github.com/openshift/origin/pkg/build/apis/build" buildv1helpers "github.com/openshift/origin/pkg/build/apis/build/v1" ) @@ -28,24 +29,16 @@ var ( func init() { annotationDecodingScheme := runtime.NewScheme() - utilruntime.Must(buildv1.Install(annotationDecodingScheme)) - utilruntime.Must(buildv1helpers.AddToScheme(annotationDecodingScheme)) - utilruntime.Must(buildv1.DeprecatedInstallWithoutGroup(annotationDecodingScheme)) - utilruntime.Must(buildv1helpers.AddToSchemeInCoreGroup(annotationDecodingScheme)) // TODO eventually we shouldn't deal in internal versions, but for now decode into one. - utilruntime.Must(buildapi.AddToScheme(annotationDecodingScheme)) - utilruntime.Must(buildapi.AddToSchemeInCoreGroup(annotationDecodingScheme)) + legacy.InstallInternalLegacyBuild(annotationDecodingScheme) + utilruntime.Must(buildv1helpers.Install(annotationDecodingScheme)) annotationDecoderCodecFactory := serializer.NewCodecFactory(annotationDecodingScheme) Decoder = annotationDecoderCodecFactory.UniversalDecoder(buildapi.SchemeGroupVersion) - utilruntime.Must(buildv1.Install(EncoderScheme)) // TODO eventually we shouldn't deal in internal versions, but for now encode from one. - utilruntime.Must(buildv1helpers.AddToScheme(EncoderScheme)) - utilruntime.Must(buildapi.AddToScheme(EncoderScheme)) + utilruntime.Must(buildv1helpers.Install(EncoderScheme)) annotationEncoderCodecFactory := serializer.NewCodecFactory(EncoderScheme) Encoder = annotationEncoderCodecFactory.LegacyCodec(buildv1.SchemeGroupVersion) - utilruntime.Must(buildv1.Install(InternalExternalScheme)) - utilruntime.Must(buildv1helpers.AddToScheme(InternalExternalScheme)) - utilruntime.Must(buildapi.AddToScheme(InternalExternalScheme)) + utilruntime.Must(buildv1helpers.Install(InternalExternalScheme)) } diff --git a/pkg/build/controller/strategy/custom.go b/pkg/build/controller/strategy/custom.go index f853b50c9bab..a95ef9ac9228 100644 --- a/pkg/build/controller/strategy/custom.go +++ b/pkg/build/controller/strategy/custom.go @@ -14,6 +14,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" buildv1 "github.com/openshift/api/build/v1" + "github.com/openshift/origin/pkg/api/legacy" buildapi "github.com/openshift/origin/pkg/build/apis/build" buildv1helpers "github.com/openshift/origin/pkg/build/apis/build/v1" buildutil "github.com/openshift/origin/pkg/build/util" @@ -25,13 +26,9 @@ var ( ) func init() { - utilruntime.Must(buildv1.Install(customBuildEncodingScheme)) - utilruntime.Must(buildv1helpers.AddToScheme(customBuildEncodingScheme)) - utilruntime.Must(buildv1.DeprecatedInstallWithoutGroup(customBuildEncodingScheme)) - utilruntime.Must(buildv1helpers.AddToSchemeInCoreGroup(customBuildEncodingScheme)) + legacy.InstallInternalLegacyBuild(customBuildEncodingScheme) // TODO eventually we shouldn't deal in internal versions, but for now decode into one. - utilruntime.Must(buildapi.AddToScheme(customBuildEncodingScheme)) - utilruntime.Must(buildapi.AddToSchemeInCoreGroup(customBuildEncodingScheme)) + utilruntime.Must(buildv1helpers.Install(customBuildEncodingScheme)) customBuildEncodingCodecFactory = serializer.NewCodecFactory(customBuildEncodingScheme) } diff --git a/pkg/build/generator/generator.go b/pkg/build/generator/generator.go index 3f6b8d070aa3..cf143856ce9d 100644 --- a/pkg/build/generator/generator.go +++ b/pkg/build/generator/generator.go @@ -19,6 +19,7 @@ import ( kapi "k8s.io/kubernetes/pkg/apis/core" kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion" + buildgroup "github.com/openshift/api/build" buildapiv1 "github.com/openshift/api/build/v1" "github.com/openshift/origin/pkg/api/apihelpers" buildapi "github.com/openshift/origin/pkg/build/apis/build" @@ -443,7 +444,7 @@ func (g *BuildGenerator) clone(ctx context.Context, request *buildapi.BuildReque // createBuild is responsible for validating build object and saving it and returning newly created object func (g *BuildGenerator) createBuild(ctx context.Context, build *buildapi.Build) (*buildapi.Build, error) { if !rest.ValidNamespace(ctx, &build.ObjectMeta) { - return nil, errors.NewConflict(buildapi.Resource("build"), build.Namespace, fmt.Errorf("Build.Namespace does not match the provided context")) + return nil, errors.NewConflict(buildgroup.Resource("build"), build.Namespace, fmt.Errorf("Build.Namespace does not match the provided context")) } rest.FillObjectMetaSystemFields(&build.ObjectMeta) err := g.Client.CreateBuild(ctx, build) diff --git a/pkg/build/generator/generator_test.go b/pkg/build/generator/generator_test.go index cd79cfc1f1a7..4870f660c44b 100644 --- a/pkg/build/generator/generator_test.go +++ b/pkg/build/generator/generator_test.go @@ -17,6 +17,7 @@ import ( kapi "k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake" + "github.com/openshift/api/image" buildapi "github.com/openshift/origin/pkg/build/apis/build" "github.com/openshift/origin/pkg/build/apis/build/validation" mocks "github.com/openshift/origin/pkg/build/generator/test" @@ -610,7 +611,7 @@ func TestInstantiateWithMissingImageStream(t *testing.T) { g := mockBuildGenerator(nil, nil, nil, nil, nil, nil, nil) c := g.Client.(TestingClient) c.GetImageStreamFunc = func(ctx context.Context, name string, options *metav1.GetOptions) (*imageapi.ImageStream, error) { - return nil, errors.NewNotFound(imageapi.Resource("imagestreams"), "testRepo") + return nil, errors.NewNotFound(image.Resource("imagestreams"), "testRepo") } g.Client = c diff --git a/pkg/build/registry/build/etcd/etcd.go b/pkg/build/registry/build/etcd/etcd.go index 638a250f93dd..9341931c5b13 100644 --- a/pkg/build/registry/build/etcd/etcd.go +++ b/pkg/build/registry/build/etcd/etcd.go @@ -11,8 +11,9 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/build" buildapi "github.com/openshift/origin/pkg/build/apis/build" - "github.com/openshift/origin/pkg/build/registry/build" + buildregistry "github.com/openshift/origin/pkg/build/registry/build" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" "github.com/openshift/origin/pkg/util/restoptions" ) @@ -34,13 +35,13 @@ func NewREST(optsGetter restoptions.Getter) (*REST, *DetailsREST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &buildapi.Build{} }, NewListFunc: func() runtime.Object { return &buildapi.BuildList{} }, - DefaultQualifiedResource: buildapi.Resource("builds"), + DefaultQualifiedResource: build.Resource("builds"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, - CreateStrategy: build.Strategy, - UpdateStrategy: build.Strategy, - DeleteStrategy: build.Strategy, + CreateStrategy: buildregistry.Strategy, + UpdateStrategy: buildregistry.Strategy, + DeleteStrategy: buildregistry.Strategy, } options := &generic.StoreOptions{ @@ -52,7 +53,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, *DetailsREST, error) { } detailsStore := *store - detailsStore.UpdateStrategy = build.DetailsStrategy + detailsStore.UpdateStrategy = buildregistry.DetailsStrategy return &REST{store}, &DetailsREST{&detailsStore}, nil } diff --git a/pkg/build/registry/buildconfig/etcd/etcd.go b/pkg/build/registry/buildconfig/etcd/etcd.go index bfb52d5bce8e..2168deaf1c48 100644 --- a/pkg/build/registry/buildconfig/etcd/etcd.go +++ b/pkg/build/registry/buildconfig/etcd/etcd.go @@ -8,6 +8,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/build" buildapi "github.com/openshift/origin/pkg/build/apis/build" "github.com/openshift/origin/pkg/build/registry/buildconfig" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" @@ -37,7 +38,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &buildapi.BuildConfig{} }, NewListFunc: func() runtime.Object { return &buildapi.BuildConfigList{} }, - DefaultQualifiedResource: buildapi.Resource("buildconfigs"), + DefaultQualifiedResource: build.Resource("buildconfigs"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/build/registry/buildconfig/webhook.go b/pkg/build/registry/buildconfig/webhook.go index cf352d3226a7..1ce72c1419a0 100644 --- a/pkg/build/registry/buildconfig/webhook.go +++ b/pkg/build/registry/buildconfig/webhook.go @@ -19,7 +19,8 @@ import ( kapi "k8s.io/kubernetes/pkg/apis/core" kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion" - buildv1 "github.com/openshift/api/build/v1" + "github.com/openshift/api/build" + "github.com/openshift/origin/pkg/api/legacy" buildapi "github.com/openshift/origin/pkg/build/apis/build" buildv1helpers "github.com/openshift/origin/pkg/build/apis/build/v1" "github.com/openshift/origin/pkg/build/client" @@ -34,12 +35,9 @@ var ( func init() { // webhooks need to return legacy build serialization when hit via oapi - utilruntime.Must(buildv1.AddToScheme(webhookEncodingScheme)) - utilruntime.Must(buildv1helpers.AddToScheme(webhookEncodingScheme)) - utilruntime.Must(buildv1.DeprecatedInstallWithoutGroup(webhookEncodingScheme)) - utilruntime.Must(buildv1helpers.AddToSchemeInCoreGroup(webhookEncodingScheme)) - utilruntime.Must(buildapi.AddToScheme(webhookEncodingScheme)) - utilruntime.Must(buildapi.AddToSchemeInCoreGroup(webhookEncodingScheme)) + legacy.InstallInternalLegacyBuild(webhookEncodingScheme) + // TODO eventually we shouldn't deal in internal versions, but for now decode into one. + utilruntime.Must(buildv1helpers.Install(webhookEncodingScheme)) webhookEncodingCodecFactory = serializer.NewCodecFactory(webhookEncodingScheme) } @@ -129,7 +127,7 @@ func (w *WebHookHandler) ProcessWebHook(writer http.ResponseWriter, req *http.Re plugin, ok := w.plugins[hookType] if !ok { - return errors.NewNotFound(buildapi.Resource("buildconfighook"), hookType) + return errors.NewNotFound(build.Resource("buildconfighook"), hookType) } config, err := w.buildConfigClient.BuildConfigs(apirequest.NamespaceValue(ctx)).Get(name, metav1.GetOptions{}) @@ -156,7 +154,7 @@ func (w *WebHookHandler) ProcessWebHook(writer http.ResponseWriter, req *http.Re case webhook.ErrSecretMismatch, webhook.ErrHookNotEnabled: return errors.NewUnauthorized(fmt.Sprintf("the webhook %q for %q did not accept your secret", hookType, name)) case webhook.MethodNotSupported: - return errors.NewMethodNotSupported(buildapi.Resource("buildconfighook"), req.Method) + return errors.NewMethodNotSupported(build.Resource("buildconfighook"), req.Method) } if _, ok := err.(*errors.StatusError); !ok && err != nil { return errors.NewInternalError(fmt.Errorf("hook failed: %v", err)) diff --git a/pkg/build/registry/buildlog/rest.go b/pkg/build/registry/buildlog/rest.go index dc4bb473d803..7f61a8628572 100644 --- a/pkg/build/registry/buildlog/rest.go +++ b/pkg/build/registry/buildlog/rest.go @@ -18,6 +18,7 @@ import ( kapi "k8s.io/kubernetes/pkg/apis/core" kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion" + "github.com/openshift/api/build" apiserverrest "github.com/openshift/origin/pkg/apiserver/rest" buildapi "github.com/openshift/origin/pkg/build/apis/build" "github.com/openshift/origin/pkg/build/apis/build/validation" @@ -61,7 +62,7 @@ func (r *REST) Get(ctx context.Context, name string, opts runtime.Object) (runti return nil, errors.NewBadRequest("did not get an expected options.") } if errs := validation.ValidateBuildLogOptions(buildLogOpts); len(errs) > 0 { - return nil, errors.NewInvalid(buildapi.Kind("BuildLogOptions"), "", errs) + return nil, errors.NewInvalid(build.Kind("BuildLogOptions"), "", errs) } build, err := r.BuildClient.Builds(apirequest.NamespaceValue(ctx)).Get(name, metav1.GetOptions{}) if err != nil { diff --git a/pkg/build/registry/test/buildconfig.go b/pkg/build/registry/test/buildconfig.go index 819a649902ca..5ecdf2a3c07b 100644 --- a/pkg/build/registry/test/buildconfig.go +++ b/pkg/build/registry/test/buildconfig.go @@ -9,6 +9,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/watch" + "github.com/openshift/api/build" buildapi "github.com/openshift/origin/pkg/build/apis/build" ) @@ -32,7 +33,7 @@ func (r *BuildConfigRegistry) GetBuildConfig(ctx context.Context, id string, opt if r.BuildConfig != nil && r.BuildConfig.Name == id { return r.BuildConfig, r.Err } - return nil, kapierrors.NewNotFound(buildapi.Resource("buildconfig"), id) + return nil, kapierrors.NewNotFound(build.Resource("buildconfig"), id) } func (r *BuildConfigRegistry) CreateBuildConfig(ctx context.Context, config *buildapi.BuildConfig) error { diff --git a/pkg/cmd/openshift-apiserver/cmd.go b/pkg/cmd/openshift-apiserver/cmd.go index 1014086dedec..22f6511b4adb 100644 --- a/pkg/cmd/openshift-apiserver/cmd.go +++ b/pkg/cmd/openshift-apiserver/cmd.go @@ -38,7 +38,7 @@ func NewOpenShiftAPIServerCommand(name, basename string, out, errout io.Writer) Short: "Launch OpenShift apiserver", Long: longDescription, Run: func(c *cobra.Command, args []string) { - legacy.LegacyInstallAll(legacyscheme.Scheme) + legacy.InstallLegacyInternalAll(legacyscheme.Scheme) kcmdutil.CheckErr(options.Validate()) diff --git a/pkg/cmd/server/bootstrappolicy/policy.go b/pkg/cmd/server/bootstrappolicy/policy.go index 26b21eb121ba..02c8044cc3ce 100644 --- a/pkg/cmd/server/bootstrappolicy/policy.go +++ b/pkg/cmd/server/bootstrappolicy/policy.go @@ -23,20 +23,23 @@ import ( "k8s.io/kubernetes/pkg/apis/storage" "k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac/bootstrappolicy" + oapps "github.com/openshift/api/apps" + "github.com/openshift/api/authorization" + "github.com/openshift/api/build" + "github.com/openshift/api/image" + "github.com/openshift/api/network" + "github.com/openshift/api/oauth" + "github.com/openshift/api/project" + "github.com/openshift/api/quota" + "github.com/openshift/api/route" + "github.com/openshift/api/security" + "github.com/openshift/api/template" + "github.com/openshift/api/user" oapi "github.com/openshift/origin/pkg/api" "github.com/openshift/origin/pkg/api/legacy" - appsapi "github.com/openshift/origin/pkg/apps/apis/apps" authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization" buildapi "github.com/openshift/origin/pkg/build/apis/build" - imageapi "github.com/openshift/origin/pkg/image/apis/image" - networkapi "github.com/openshift/origin/pkg/network/apis/network" - oauthapi "github.com/openshift/origin/pkg/oauth/apis/oauth" - projectapi "github.com/openshift/origin/pkg/project/apis/project" - quotaapi "github.com/openshift/origin/pkg/quota/apis/quota" - routeapi "github.com/openshift/origin/pkg/route/apis/route" - securityapi "github.com/openshift/origin/pkg/security/apis/security" templateapi "github.com/openshift/origin/pkg/template/apis/template" - userapi "github.com/openshift/origin/pkg/user/apis/user" ) const ( @@ -63,36 +66,36 @@ var ( networkingGroup = "networking.k8s.io" policyGroup = policy.GroupName rbacGroup = rbac.GroupName - securityGroup = securityapi.GroupName - legacySecurityGroup = securityapi.LegacyGroupName storageGroup = storage.GroupName settingsGroup = settings.GroupName schedulingGroup = "scheduling.k8s.io" - - authzGroup = authorizationapi.GroupName - kAuthzGroup = kauthorizationapi.GroupName - kAuthnGroup = kauthenticationapi.GroupName + kAuthzGroup = kauthorizationapi.GroupName + kAuthnGroup = kauthenticationapi.GroupName + + deployGroup = oapps.GroupName + authzGroup = authorization.GroupName + buildGroup = build.GroupName + imageGroup = image.GroupName + networkGroup = network.GroupName + oauthGroup = oauth.GroupName + projectGroup = project.GroupName + quotaGroup = quota.GroupName + routeGroup = route.GroupName + securityGroup = security.GroupName + templateGroup = template.GroupName + userGroup = user.GroupName legacyAuthzGroup = legacy.GroupName - buildGroup = buildapi.GroupName legacyBuildGroup = legacy.GroupName - deployGroup = appsapi.GroupName legacyDeployGroup = legacy.GroupName - imageGroup = imageapi.GroupName legacyImageGroup = legacy.GroupName - projectGroup = projectapi.GroupName legacyProjectGroup = legacy.GroupName - quotaGroup = quotaapi.GroupName legacyQuotaGroup = legacy.GroupName - routeGroup = routeapi.GroupName legacyRouteGroup = legacy.GroupName - templateGroup = templateapi.GroupName legacyTemplateGroup = legacy.GroupName - userGroup = userapi.GroupName legacyUserGroup = legacy.GroupName - oauthGroup = oauthapi.GroupName legacyOauthGroup = legacy.GroupName - networkGroup = networkapi.GroupName legacyNetworkGroup = legacy.GroupName + legacySecurityGroup = legacy.GroupName ) func GetOpenshiftBootstrapClusterRoles() []rbacv1.ClusterRole { diff --git a/pkg/cmd/server/kubernetes/master/master_config.go b/pkg/cmd/server/kubernetes/master/master_config.go index 38c5741543f7..f0acdb09bfea 100644 --- a/pkg/cmd/server/kubernetes/master/master_config.go +++ b/pkg/cmd/server/kubernetes/master/master_config.go @@ -84,10 +84,10 @@ import ( cmdflags "github.com/openshift/origin/pkg/cmd/util/flags" oauthutil "github.com/openshift/origin/pkg/oauth/util" openapigenerated "github.com/openshift/origin/pkg/openapi" - securityapi "github.com/openshift/origin/pkg/security/apis/security" "github.com/openshift/origin/pkg/version" // TODO fix this install, it is required for TestPreferredGroupVersions to pass + "github.com/openshift/api/security" _ "github.com/openshift/origin/pkg/authorization/apis/authorization/install" ) @@ -249,7 +249,7 @@ func BuildStorageFactory(server *kapiserveroptions.ServerRunOptions, enforcedSto storageFactory.AddCohabitatingResources(apps.Resource("daemonsets"), extensions.Resource("daemonsets")) storageFactory.AddCohabitatingResources(apps.Resource("replicasets"), extensions.Resource("replicasets")) storageFactory.AddCohabitatingResources(networking.Resource("networkpolicies"), extensions.Resource("networkpolicies")) - storageFactory.AddCohabitatingResources(securityapi.Resource("securitycontextconstraints"), kapi.Resource("securitycontextconstraints")) + storageFactory.AddCohabitatingResources(security.Resource("securitycontextconstraints"), kapi.Resource("securitycontextconstraints")) // TODO: switch to prefer policy API group in 3.11 storageFactory.AddCohabitatingResources(extensions.Resource("podsecuritypolicies"), policy.Resource("podsecuritypolicies")) diff --git a/pkg/image/admission/admission.go b/pkg/image/admission/admission.go index f0a362a374a8..e9e4919fc42d 100644 --- a/pkg/image/admission/admission.go +++ b/pkg/image/admission/admission.go @@ -15,6 +15,8 @@ import ( kadmission "k8s.io/kubernetes/pkg/kubeapiserver/admission" "k8s.io/kubernetes/plugin/pkg/admission/limitranger" + "github.com/openshift/api/image" + "github.com/openshift/origin/pkg/api/legacy" imageapi "github.com/openshift/origin/pkg/image/apis/image" "github.com/openshift/origin/pkg/image/util" ) @@ -106,7 +108,7 @@ func (a *imageLimitRangerPlugin) SupportsAttributes(attr admission.Attributes) b return false } gk := attr.GetKind().GroupKind() - return imageapi.Kind("ImageStreamMapping") == gk || imageapi.LegacyKind("ImageStreamMapping") == gk + return image.Kind("ImageStreamMapping") == gk || legacy.Kind("ImageStreamMapping") == gk } // SupportsLimit provides a check to see if the limitRange is applicable to image objects. diff --git a/pkg/image/admission/admission_test.go b/pkg/image/admission/admission_test.go index 70eae066e868..0593e9feb34b 100644 --- a/pkg/image/admission/admission_test.go +++ b/pkg/image/admission/admission_test.go @@ -15,6 +15,8 @@ import ( informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion" kubeadmission "k8s.io/kubernetes/pkg/kubeapiserver/admission" + "github.com/openshift/api/image" + "github.com/openshift/origin/pkg/api/legacy" "github.com/openshift/origin/pkg/image/admission/testutil" imageapi "github.com/openshift/origin/pkg/image/apis/image" ) @@ -60,10 +62,10 @@ func TestAdmitImageStreamMapping(t *testing.T) { informerFactory.Start(wait.NeverStop) attrs := kadmission.NewAttributesRecord(v.imageStreamMapping, nil, - imageapi.Kind("ImageStreamMapping").WithVersion("version"), + image.Kind("ImageStreamMapping").WithVersion("version"), v.imageStreamMapping.Namespace, v.imageStreamMapping.Name, - imageapi.Resource("imagestreammappings").WithVersion("version"), + image.Resource("imagestreammappings").WithVersion("version"), "", v.operation, nil) @@ -218,7 +220,7 @@ func TestSupports(t *testing.T) { } ilr := plugin.(*imageLimitRangerPlugin) for _, r := range resources { - attr := kadmission.NewAttributesRecord(nil, nil, imageapi.LegacyKind("ImageStreamMapping").WithVersion(""), "ns", "name", imageapi.LegacyResource(r).WithVersion("version"), "", kadmission.Create, nil) + attr := kadmission.NewAttributesRecord(nil, nil, legacy.Kind("ImageStreamMapping").WithVersion(""), "ns", "name", legacy.Resource(r).WithVersion("version"), "", kadmission.Create, nil) if !ilr.SupportsAttributes(attr) { t.Errorf("plugin is expected to support %#v", r) } @@ -226,7 +228,7 @@ func TestSupports(t *testing.T) { badKinds := []string{"ImageStream", "Image", "Pod", "foo"} for _, k := range badKinds { - attr := kadmission.NewAttributesRecord(nil, nil, imageapi.LegacyKind(k).WithVersion(""), "ns", "name", imageapi.Resource("bar").WithVersion("version"), "", kadmission.Create, nil) + attr := kadmission.NewAttributesRecord(nil, nil, legacy.Kind(k).WithVersion(""), "ns", "name", image.Resource("bar").WithVersion("version"), "", kadmission.Create, nil) if ilr.SupportsAttributes(attr) { t.Errorf("plugin is not expected to support %s", k) } diff --git a/pkg/image/admission/imagepolicy/imagepolicy_test.go b/pkg/image/admission/imagepolicy/imagepolicy_test.go index d2b1a95f0903..fda1d36e4916 100644 --- a/pkg/image/admission/imagepolicy/imagepolicy_test.go +++ b/pkg/image/admission/imagepolicy/imagepolicy_test.go @@ -20,6 +20,7 @@ import ( kapiextensions "k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake" + "github.com/openshift/api/image" buildapi "github.com/openshift/origin/pkg/build/apis/build" configlatest "github.com/openshift/origin/pkg/cmd/server/apis/config/latest" "github.com/openshift/origin/pkg/image/admission/apis/imagepolicy" @@ -106,7 +107,7 @@ func TestDefaultPolicy(t *testing.T) { case badImage.Name: return true, badImage, nil default: - return true, nil, kerrors.NewNotFound(imageapi.Resource("images"), name) + return true, nil, kerrors.NewNotFound(image.Resource("images"), name) } }) client.AddReactor("get", "imagestreamtags", func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) { @@ -117,7 +118,7 @@ func TestDefaultPolicy(t *testing.T) { case badTag.Name: return true, badTag, nil default: - return true, nil, kerrors.NewNotFound(imageapi.Resource("imagestreamtags"), name) + return true, nil, kerrors.NewNotFound(image.Resource("imagestreamtags"), name) } }) diff --git a/pkg/image/admission/imagestream_limits.go b/pkg/image/admission/imagestream_limits.go index bacdf1c9d748..18137fc9f313 100644 --- a/pkg/image/admission/imagestream_limits.go +++ b/pkg/image/admission/imagestream_limits.go @@ -5,6 +5,7 @@ import ( kerrutil "k8s.io/apimachinery/pkg/util/errors" kapi "k8s.io/kubernetes/pkg/apis/core" + "github.com/openshift/api/image" imageapi "github.com/openshift/origin/pkg/image/apis/image" ) @@ -35,7 +36,7 @@ func (v *limitVerifier) VerifyLimits(namespace string, is *imageapi.ImageStream) usage := GetImageStreamUsage(is) if err := verifyImageStreamUsage(usage, limits); err != nil { - return kapierrors.NewForbidden(imageapi.Resource("ImageStream"), is.Name, err) + return kapierrors.NewForbidden(image.Resource("ImageStream"), is.Name, err) } return nil } diff --git a/pkg/image/apis/image/helper.go b/pkg/image/apis/image/helper.go index fd80b1106e34..68fe0bd70605 100644 --- a/pkg/image/apis/image/helper.go +++ b/pkg/image/apis/image/helper.go @@ -16,6 +16,7 @@ import ( "github.com/blang/semver" "github.com/golang/glog" + "github.com/openshift/api/image" "github.com/openshift/origin/pkg/image/apis/image/internal/digest" "github.com/openshift/origin/pkg/image/apis/image/reference" ) @@ -606,9 +607,9 @@ func ResolveImageID(stream *ImageStream, imageID string) (*TagEvent, error) { Image: event.Image, }, nil case 0: - return nil, kerrors.NewNotFound(Resource("imagestreamimage"), imageID) + return nil, kerrors.NewNotFound(image.Resource("imagestreamimage"), imageID) default: - return nil, kerrors.NewConflict(Resource("imagestreamimage"), imageID, fmt.Errorf("multiple images match the prefix %q: %s", imageID, strings.Join(set.List(), ", "))) + return nil, kerrors.NewConflict(image.Resource("imagestreamimage"), imageID, fmt.Errorf("multiple images match the prefix %q: %s", imageID, strings.Join(set.List(), ", "))) } } diff --git a/pkg/image/apis/image/install/install.go b/pkg/image/apis/image/install/install.go index 37206ae34a69..b4e6b7310c57 100644 --- a/pkg/image/apis/image/install/install.go +++ b/pkg/image/apis/image/install/install.go @@ -5,9 +5,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/kubernetes/pkg/api/legacyscheme" - "github.com/openshift/api/image/docker10" - "github.com/openshift/api/image/dockerpre012" - imageapi "github.com/openshift/origin/pkg/image/apis/image" + imagev1 "github.com/openshift/api/image/v1" imageapiv1 "github.com/openshift/origin/pkg/image/apis/image/v1" ) @@ -17,9 +15,6 @@ func init() { // Install registers the API group and adds types to a scheme func Install(scheme *runtime.Scheme) { - utilruntime.Must(docker10.AddToScheme(scheme)) - utilruntime.Must(dockerpre012.AddToScheme(scheme)) - utilruntime.Must(imageapi.AddToScheme(scheme)) - utilruntime.Must(imageapiv1.AddToScheme(scheme)) - utilruntime.Must(scheme.SetVersionPriority(imageapiv1.SchemeGroupVersion)) + utilruntime.Must(imageapiv1.Install(scheme)) + utilruntime.Must(scheme.SetVersionPriority(imagev1.SchemeGroupVersion)) } diff --git a/pkg/image/apis/image/register.go b/pkg/image/apis/image/register.go index 86333f0ffbae..c13b5ea13a14 100644 --- a/pkg/image/apis/image/register.go +++ b/pkg/image/apis/image/register.go @@ -3,62 +3,33 @@ package image import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - kapi "k8s.io/kubernetes/pkg/apis/core" + "k8s.io/kubernetes/pkg/apis/core" ) const ( - GroupName = "image.openshift.io" - LegacyGroupName = "" + GroupName = "image.openshift.io" ) var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: runtime.APIVersionInternal} - - LegacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme + GroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} + schemeBuilder = runtime.NewSchemeBuilder( + addKnownTypes, + core.AddToScheme, + ) + Install = schemeBuilder.AddToScheme - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // DEPRECATED kept for generated code + SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} + // DEPRECATED kept for generated code + AddToScheme = schemeBuilder.AddToScheme ) -// Kind takes an unqualified kind and returns back a Group qualified GroupKind -func Kind(kind string) schema.GroupKind { - return SchemeGroupVersion.WithKind(kind).GroupKind() -} - -func LegacyKind(kind string) schema.GroupKind { - return LegacySchemeGroupVersion.WithKind(kind).GroupKind() -} - -// Resource takes an unqualified resource and returns back a Group qualified GroupResource +// Resource kept for generated code +// DEPRECATED func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } -func LegacyResource(resource string) schema.GroupResource { - return LegacySchemeGroupVersion.WithResource(resource).GroupResource() -} - -// Adds the list of known types to api.Scheme. -func addLegacyKnownTypes(scheme *runtime.Scheme) error { - types := []runtime.Object{ - &Image{}, - &ImageList{}, - &DockerImage{}, - &ImageSignature{}, - &ImageStream{}, - &ImageStreamList{}, - &ImageStreamMapping{}, - &ImageStreamTag{}, - &ImageStreamTagList{}, - &ImageStreamImage{}, - &ImageStreamImport{}, - } - scheme.AddKnownTypes(LegacySchemeGroupVersion, types...) - return nil -} - // Adds the list of known types to api.Scheme. func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, @@ -74,7 +45,7 @@ func addKnownTypes(scheme *runtime.Scheme) error { &ImageStreamImage{}, &ImageStreamLayers{}, &ImageStreamImport{}, - &kapi.SecretList{}, + &core.SecretList{}, ) return nil } diff --git a/pkg/image/apis/image/types.go b/pkg/image/apis/image/types.go index 2e564ed006e3..ef613fbfbeab 100644 --- a/pkg/image/apis/image/types.go +++ b/pkg/image/apis/image/types.go @@ -2,7 +2,7 @@ package image import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - kapi "k8s.io/kubernetes/pkg/apis/core" + "k8s.io/kubernetes/pkg/apis/core" "github.com/openshift/origin/pkg/image/apis/image/reference" ) @@ -61,23 +61,23 @@ const ( DefaultImageTag = "latest" // ResourceImageStreams represents a number of image streams in a project. - ResourceImageStreams kapi.ResourceName = "openshift.io/imagestreams" + ResourceImageStreams core.ResourceName = "openshift.io/imagestreams" // ResourceImageStreamImages represents a number of unique references to images in all image stream // statuses of a project. - ResourceImageStreamImages kapi.ResourceName = "openshift.io/images" + ResourceImageStreamImages core.ResourceName = "openshift.io/images" // ResourceImageStreamTags represents a number of unique references to images in all image stream specs // of a project. - ResourceImageStreamTags kapi.ResourceName = "openshift.io/image-tags" + ResourceImageStreamTags core.ResourceName = "openshift.io/image-tags" // Limit that applies to images. Used with a max["storage"] LimitRangeItem to set // the maximum size of an image. - LimitTypeImage kapi.LimitType = "openshift.io/Image" + LimitTypeImage core.LimitType = "openshift.io/Image" // Limit that applies to image streams. Used with a max[resource] LimitRangeItem to set the maximum number // of resource. Where the resource is one of "openshift.io/images" and "openshift.io/image-tags". - LimitTypeImageStream kapi.LimitType = "openshift.io/ImageStream" + LimitTypeImageStream core.LimitType = "openshift.io/ImageStream" ) // +genclient @@ -185,7 +185,7 @@ type SignatureCondition struct { // Type of signature condition, Complete or Failed. Type SignatureConditionType // Status of the condition, one of True, False, Unknown. - Status kapi.ConditionStatus + Status core.ConditionStatus // Last time the condition was checked. LastProbeTime metav1.Time // Last time the condition transit from one status to another. @@ -278,7 +278,7 @@ type TagReference struct { Annotations map[string]string // Optional; if specified, a reference to another image that this tag should point to. Valid values // are ImageStreamTag, ImageStreamImage, and DockerImage. - From *kapi.ObjectReference + From *core.ObjectReference // Reference states if the tag will be imported. Default value is false, which means the tag will // be imported. Reference bool @@ -378,7 +378,7 @@ type TagEventCondition struct { // Type of tag event condition, currently only ImportSuccess Type TagEventConditionType // Status of the condition, one of True, False, Unknown. - Status kapi.ConditionStatus + Status core.ConditionStatus // LastTransitionTIme is the time the condition transitioned from one status to another. LastTransitionTime metav1.Time // Reason is a brief machine readable explanation for the condition's last transition. @@ -549,7 +549,7 @@ type ImageStreamImportStatus struct { // RepositoryImportSpec indicates to load a set of tags from a given Docker image repository type RepositoryImportSpec struct { // The source of the import, only kind DockerImage is supported - From kapi.ObjectReference + From core.ObjectReference ImportPolicy TagImportPolicy ReferencePolicy TagReferencePolicy @@ -569,8 +569,8 @@ type RepositoryImportStatus struct { // ImageImportSpec defines how an image is imported. type ImageImportSpec struct { - From kapi.ObjectReference - To *kapi.LocalObjectReference + From core.ObjectReference + To *core.LocalObjectReference ImportPolicy TagImportPolicy ReferencePolicy TagReferencePolicy diff --git a/pkg/image/apis/image/v1/conversion.go b/pkg/image/apis/image/v1/conversion.go index 8b97c2cf3a52..0b70cbb09813 100644 --- a/pkg/image/apis/image/v1/conversion.go +++ b/pkg/image/apis/image/v1/conversion.go @@ -12,7 +12,6 @@ import ( "github.com/openshift/api/image/docker10" "github.com/openshift/api/image/dockerpre012" "github.com/openshift/api/image/v1" - "github.com/openshift/origin/pkg/api/apihelpers" newer "github.com/openshift/origin/pkg/image/apis/image" ) @@ -24,12 +23,7 @@ var ( func init() { docker10.AddToSchemeInCoreGroup(dockerImageScheme) dockerpre012.AddToSchemeInCoreGroup(dockerImageScheme) - newer.AddToSchemeInCoreGroup(dockerImageScheme) - AddToSchemeInCoreGroup(dockerImageScheme) - docker10.AddToScheme(dockerImageScheme) - dockerpre012.AddToScheme(dockerImageScheme) - newer.AddToScheme(dockerImageScheme) - AddToScheme(dockerImageScheme) + Install(dockerImageScheme) } // The docker metadata must be cast to a version @@ -278,7 +272,7 @@ func Convert_image_TagReferenceMap_to_v1_TagReferenceArray(in *map[string]newer. return nil } -func addConversionFuncs(scheme *runtime.Scheme) error { +func AddConversionFuncs(scheme *runtime.Scheme) error { err := scheme.AddConversionFuncs( Convert_v1_NamedTagEventListArray_to_api_TagEventListArray, Convert_image_TagEventListArray_to_v1_NamedTagEventListArray, @@ -302,15 +296,8 @@ func addConversionFuncs(scheme *runtime.Scheme) error { return nil } -func addLegacyFieldSelectorKeyConversions(scheme *runtime.Scheme) error { - if err := scheme.AddFieldLabelConversionFunc(LegacySchemeGroupVersion.String(), "ImageStream", legacyImageStreamFieldSelectorKeyConversionFunc); err != nil { - return err - } - return nil -} - func addFieldSelectorKeyConversions(scheme *runtime.Scheme) error { - if err := scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.String(), "ImageStream", imageStreamFieldSelectorKeyConversionFunc); err != nil { + if err := scheme.AddFieldLabelConversionFunc(v1.GroupVersion.String(), "ImageStream", imageStreamFieldSelectorKeyConversionFunc); err != nil { return err } return nil @@ -319,16 +306,6 @@ func addFieldSelectorKeyConversions(scheme *runtime.Scheme) error { // 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 legacyImageStreamFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { - switch label { - case "spec.dockerImageRepository", - "status.dockerImageRepository": - return label, value, nil - default: - return apihelpers.LegacyMetaV1FieldSelectorConversionWithName(label, value) - } -} - func imageStreamFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { switch label { case "spec.dockerImageRepository", diff --git a/pkg/image/apis/image/v1/conversion_test.go b/pkg/image/apis/image/v1/conversion_test.go index b3ba5c342777..fe1ef4656c6e 100644 --- a/pkg/image/apis/image/v1/conversion_test.go +++ b/pkg/image/apis/image/v1/conversion_test.go @@ -10,38 +10,30 @@ import ( "k8s.io/apimachinery/pkg/util/diff" kapi "k8s.io/kubernetes/pkg/apis/core" - "github.com/openshift/api/image/docker10" - "github.com/openshift/api/image/dockerpre012" + v1 "github.com/openshift/api/image/v1" "github.com/openshift/origin/pkg/api/apihelpers/apitesting" - newer "github.com/openshift/origin/pkg/image/apis/image" + internal "github.com/openshift/origin/pkg/image/apis/image" ) func TestRoundTripVersionedObject(t *testing.T) { scheme := runtime.NewScheme() - docker10.AddToSchemeInCoreGroup(scheme) - dockerpre012.AddToSchemeInCoreGroup(scheme) - newer.AddToSchemeInCoreGroup(scheme) - docker10.AddToScheme(scheme) - dockerpre012.AddToScheme(scheme) - AddToSchemeInCoreGroup(scheme) - newer.AddToScheme(scheme) - AddToScheme(scheme) + Install(scheme) codecs := serializer.NewCodecFactory(scheme) - d := &newer.DockerImage{ - Config: &newer.DockerConfig{ + d := &internal.DockerImage{ + Config: &internal.DockerConfig{ Env: []string{"A=1", "B=2"}, }, } - i := &newer.Image{ + i := &internal.Image{ ObjectMeta: metav1.ObjectMeta{Name: "foo"}, - DockerImageLayers: []newer.ImageLayer{{Name: "foo", LayerSize: 10}}, + DockerImageLayers: []internal.ImageLayer{{Name: "foo", LayerSize: 10}}, DockerImageMetadata: *d, DockerImageReference: "foo/bar/baz", } - data, err := runtime.Encode(codecs.LegacyCodec(SchemeGroupVersion), i) + data, err := runtime.Encode(codecs.LegacyCodec(v1.GroupVersion), i) if err != nil { t.Fatalf("unexpected error: %v", err) } @@ -50,7 +42,7 @@ func TestRoundTripVersionedObject(t *testing.T) { if err != nil { t.Fatalf("unexpected error: %v", err) } - image := obj.(*newer.Image) + image := obj.(*internal.Image) if image.DockerImageMetadataVersion != "1.0" { t.Errorf("did not default to correct metadata version: %#v", image) } @@ -62,38 +54,27 @@ func TestRoundTripVersionedObject(t *testing.T) { func TestFieldSelectors(t *testing.T) { apitesting.FieldKeyCheck{ - SchemeBuilder: []func(*runtime.Scheme) error{LegacySchemeBuilder.AddToScheme, newer.LegacySchemeBuilder.AddToScheme}, - Kind: LegacySchemeGroupVersion.WithKind("ImageStream"), - // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST - AllowedExternalFieldKeys: []string{"name", "spec.dockerImageRepository", "status.dockerImageRepository"}, - FieldKeyEvaluatorFn: newer.ImageStreamSelector, - }.Check(t) - - apitesting.FieldKeyCheck{ - SchemeBuilder: []func(*runtime.Scheme) error{SchemeBuilder.AddToScheme, newer.SchemeBuilder.AddToScheme}, - Kind: SchemeGroupVersion.WithKind("ImageStream"), + SchemeBuilder: []func(*runtime.Scheme) error{Install}, + Kind: v1.GroupVersion.WithKind("ImageStream"), // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST AllowedExternalFieldKeys: []string{"spec.dockerImageRepository", "status.dockerImageRepository"}, - FieldKeyEvaluatorFn: newer.ImageStreamSelector, + FieldKeyEvaluatorFn: internal.ImageStreamSelector, }.Check(t) } func TestImageImportSpecDefaulting(t *testing.T) { scheme := runtime.NewScheme() codecs := serializer.NewCodecFactory(scheme) - LegacySchemeBuilder.AddToScheme(scheme) - SchemeBuilder.AddToScheme(scheme) - newer.LegacySchemeBuilder.AddToScheme(scheme) - newer.SchemeBuilder.AddToScheme(scheme) + Install(scheme) - i := &newer.ImageStreamImport{ - Spec: newer.ImageStreamImportSpec{ - Images: []newer.ImageImportSpec{ + i := &internal.ImageStreamImport{ + Spec: internal.ImageStreamImportSpec{ + Images: []internal.ImageImportSpec{ {From: kapi.ObjectReference{Name: "something:other"}}, }, }, } - data, err := runtime.Encode(codecs.LegacyCodec(SchemeGroupVersion), i) + data, err := runtime.Encode(codecs.LegacyCodec(v1.GroupVersion), i) if err != nil { t.Fatal(err) } @@ -101,7 +82,7 @@ func TestImageImportSpecDefaulting(t *testing.T) { if err != nil { t.Fatal(err) } - isi := obj.(*newer.ImageStreamImport) + isi := obj.(*internal.ImageStreamImport) if isi.Spec.Images[0].To == nil || isi.Spec.Images[0].To.Name != "other" { t.Errorf("unexpected round trip: %#v", isi) } diff --git a/pkg/image/apis/image/v1/register.go b/pkg/image/apis/image/v1/register.go index 28c816e11fbb..ad47eb72cdf1 100644 --- a/pkg/image/apis/image/v1/register.go +++ b/pkg/image/apis/image/v1/register.go @@ -2,31 +2,25 @@ package v1 import ( "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" + corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1" "github.com/openshift/api/image/docker10" "github.com/openshift/api/image/dockerpre012" "github.com/openshift/api/image/v1" -) - -const ( - GroupName = "image.openshift.io" - LegacyGroupName = "" + "github.com/openshift/origin/pkg/image/apis/image" ) var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: "v1"} - - LegacySchemeBuilder = runtime.NewSchemeBuilder(v1.DeprecatedInstallWithoutGroup, addConversionFuncs, addLegacyFieldSelectorKeyConversions, RegisterDefaults, RegisterConversions, docker10.AddToSchemeInCoreGroup, dockerpre012.AddToSchemeInCoreGroup) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme - - SchemeBuilder = runtime.NewSchemeBuilder(v1.Install, addConversionFuncs, addFieldSelectorKeyConversions, RegisterDefaults, docker10.AddToScheme, dockerpre012.AddToScheme) - AddToScheme = SchemeBuilder.AddToScheme - - localSchemeBuilder = &SchemeBuilder + localSchemeBuilder = runtime.NewSchemeBuilder( + image.Install, + v1.Install, + corev1conversions.AddToScheme, + docker10.AddToScheme, + dockerpre012.AddToScheme, + + addFieldSelectorKeyConversions, + AddConversionFuncs, + RegisterDefaults, + ) + Install = localSchemeBuilder.AddToScheme ) - -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} diff --git a/pkg/image/importer/importer.go b/pkg/image/importer/importer.go index 8de4ae668b1b..875bd9c0022b 100644 --- a/pkg/image/importer/importer.go +++ b/pkg/image/importer/importer.go @@ -24,6 +24,8 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" "k8s.io/client-go/util/flowcontrol" + "github.com/openshift/api/image" + "github.com/openshift/origin/pkg/api/legacy" imageapi "github.com/openshift/origin/pkg/image/apis/image" "github.com/openshift/origin/pkg/image/importer/dockerv1client" "github.com/openshift/origin/pkg/image/util" @@ -335,7 +337,7 @@ func applyErrorToRepository(repository *importRepository, err error) { func formatRepositoryError(ref imageapi.DockerImageReference, err error) error { switch { case isDockerError(err, v2.ErrorCodeManifestUnknown): - err = kapierrors.NewNotFound(imageapi.Resource("dockerimage"), ref.Exact()) + err = kapierrors.NewNotFound(image.Resource("dockerimage"), ref.Exact()) case isDockerError(err, errcode.ErrorCodeUnauthorized): err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q", ref.Exact())) case strings.HasSuffix(err.Error(), "no basic auth credentials"): @@ -466,7 +468,7 @@ func (isi *ImageStreamImporter) importRepositoryFromDocker(ctx gocontext.Context case err == reference.ErrReferenceInvalidFormat: err = field.Invalid(field.NewPath("from", "name"), repository.Name, "the provided repository name is not valid") case isDockerError(err, v2.ErrorCodeNameUnknown): - err = kapierrors.NewNotFound(imageapi.Resource("dockerimage"), repository.Ref.Exact()) + err = kapierrors.NewNotFound(image.Resource("dockerimage"), repository.Ref.Exact()) case isDockerError(err, errcode.ErrorCodeUnauthorized): err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q", repository.Ref.Exact())) case strings.Contains(err.Error(), "tls: oversized record received with length") && !repository.Insecure: @@ -487,7 +489,7 @@ func (isi *ImageStreamImporter) importRepositoryFromDocker(ctx gocontext.Context glog.V(5).Infof("unable to access manifests for repository %#v: %#v", repository, err) switch { case isDockerError(err, v2.ErrorCodeNameUnknown): - err = kapierrors.NewNotFound(imageapi.Resource("dockerimage"), repository.Ref.Exact()) + err = kapierrors.NewNotFound(image.Resource("dockerimage"), repository.Ref.Exact()) case isDockerError(err, errcode.ErrorCodeUnauthorized): err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q", repository.Ref.Exact())) case strings.HasSuffix(err.Error(), "no basic auth credentials"): @@ -507,7 +509,7 @@ func (isi *ImageStreamImporter) importRepositoryFromDocker(ctx gocontext.Context glog.V(5).Infof("unable to access tags for repository %#v: %#v", repository, err) switch { case isDockerError(err, v2.ErrorCodeNameUnknown): - err = kapierrors.NewNotFound(imageapi.Resource("dockerimage"), repository.Ref.Exact()) + err = kapierrors.NewNotFound(image.Resource("dockerimage"), repository.Ref.Exact()) case isDockerError(err, errcode.ErrorCodeUnauthorized): err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q", repository.Ref.Exact())) } @@ -590,14 +592,14 @@ func (isi *ImageStreamImporter) importRepositoryFromDocker(ctx gocontext.Context func importRepositoryFromDockerV1(ctx gocontext.Context, repository *importRepository, limiter flowcontrol.RateLimiter) { value := ctx.Value(ContextKeyV1RegistryClient) if value == nil { - err := kapierrors.NewForbidden(imageapi.Resource(""), "", fmt.Errorf("registry %q does not support the v2 Registry API", repository.Registry.Host)) + err := kapierrors.NewForbidden(image.Resource(""), "", fmt.Errorf("registry %q does not support the v2 Registry API", repository.Registry.Host)) err.ErrStatus.Reason = "NotV2Registry" applyErrorToRepository(repository, err) return } client, ok := value.(dockerv1client.Client) if !ok { - err := kapierrors.NewForbidden(imageapi.Resource(""), "", fmt.Errorf("registry %q does not support the v2 Registry API", repository.Registry.Host)) + err := kapierrors.NewForbidden(image.Resource(""), "", fmt.Errorf("registry %q does not support the v2 Registry API", repository.Registry.Host)) err.ErrStatus.Reason = "NotV2Registry" return } @@ -732,7 +734,7 @@ func imageImportStatus(err error, kind, position string) metav1.Status { case kapierrors.APIStatus: return t.Status() case *field.Error: - return kapierrors.NewInvalid(imageapi.Kind(kind), position, field.ErrorList{t}).ErrStatus + return kapierrors.NewInvalid(image.Kind(kind), position, field.ErrorList{t}).ErrStatus default: return kapierrors.NewInternalError(err).ErrStatus } @@ -744,5 +746,5 @@ func setImageImportStatus(images *imageapi.ImageStreamImport, i int, tag string, } func invalidStatus(position string, errs ...*field.Error) metav1.Status { - return kapierrors.NewInvalid(imageapi.LegacyKind(""), position, errs).ErrStatus + return kapierrors.NewInvalid(legacy.Kind(""), position, errs).ErrStatus } diff --git a/pkg/image/registry/image/etcd/etcd.go b/pkg/image/registry/image/etcd/etcd.go index 525e2a00c256..b66dff521f73 100644 --- a/pkg/image/registry/image/etcd/etcd.go +++ b/pkg/image/registry/image/etcd/etcd.go @@ -8,8 +8,9 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/image" imageapi "github.com/openshift/origin/pkg/image/apis/image" - "github.com/openshift/origin/pkg/image/registry/image" + imageregistry "github.com/openshift/origin/pkg/image/registry/image" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" "github.com/openshift/origin/pkg/util/restoptions" ) @@ -26,13 +27,13 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &imageapi.Image{} }, NewListFunc: func() runtime.Object { return &imageapi.ImageList{} }, - DefaultQualifiedResource: imageapi.Resource("images"), + DefaultQualifiedResource: image.Resource("images"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, - CreateStrategy: image.Strategy, - UpdateStrategy: image.Strategy, - DeleteStrategy: image.Strategy, + CreateStrategy: imageregistry.Strategy, + UpdateStrategy: imageregistry.Strategy, + DeleteStrategy: imageregistry.Strategy, } options := &generic.StoreOptions{RESTOptions: optsGetter} diff --git a/pkg/image/registry/imagesignature/rest.go b/pkg/image/registry/imagesignature/rest.go index 2bdf462cc5ed..d22c9bc2b368 100644 --- a/pkg/image/registry/imagesignature/rest.go +++ b/pkg/image/registry/imagesignature/rest.go @@ -9,6 +9,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apiserver/pkg/registry/rest" + imagegroup "github.com/openshift/api/image" imageapi "github.com/openshift/origin/pkg/image/apis/image" imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset/typed/image/internalversion" ) @@ -62,7 +63,7 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation // ensure that given signature already doesn't exist - either by its name or type:content if byName, byContent := imageapi.IndexOfImageSignatureByName(image.Signatures, signature.Name), imageapi.IndexOfImageSignature(image.Signatures, signature.Type, signature.Content); byName >= 0 || byContent >= 0 { - return nil, kapierrors.NewAlreadyExists(imageapi.Resource("imageSignatures"), signature.Name) + return nil, kapierrors.NewAlreadyExists(imagegroup.Resource("imageSignatures"), signature.Name) } image.Signatures = append(image.Signatures, *signature) @@ -93,7 +94,7 @@ func (r *REST) Delete(ctx context.Context, name string, options *metav1.DeleteOp index := imageapi.IndexOfImageSignatureByName(image.Signatures, name) if index < 0 { - return nil, false, kapierrors.NewNotFound(imageapi.Resource("imageSignatures"), name) + return nil, false, kapierrors.NewNotFound(imagegroup.Resource("imageSignatures"), name) } size := len(image.Signatures) diff --git a/pkg/image/registry/imagestream/etcd/etcd.go b/pkg/image/registry/imagestream/etcd/etcd.go index f3fa49203a49..9dec16caaaa7 100644 --- a/pkg/image/registry/imagestream/etcd/etcd.go +++ b/pkg/image/registry/imagestream/etcd/etcd.go @@ -14,6 +14,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/image" imageadmission "github.com/openshift/origin/pkg/image/admission" imageapi "github.com/openshift/origin/pkg/image/apis/image" "github.com/openshift/origin/pkg/image/apis/image/validation/whitelist" @@ -53,7 +54,7 @@ func NewREST( store := registry.Store{ NewFunc: func() runtime.Object { return &imageapi.ImageStream{} }, NewListFunc: func() runtime.Object { return &imageapi.ImageStreamList{} }, - DefaultQualifiedResource: imageapi.Resource("imagestreams"), + DefaultQualifiedResource: image.Resource("imagestreams"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, } diff --git a/pkg/image/registry/imagestream/strategy_test.go b/pkg/image/registry/imagestream/strategy_test.go index e941174b913b..c80127e33c35 100644 --- a/pkg/image/registry/imagestream/strategy_test.go +++ b/pkg/image/registry/imagestream/strategy_test.go @@ -21,6 +21,7 @@ import ( kapi "k8s.io/kubernetes/pkg/apis/core" kquota "k8s.io/kubernetes/pkg/quota" + "github.com/openshift/api/image" oauthorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization" "github.com/openshift/origin/pkg/image/admission" admfake "github.com/openshift/origin/pkg/image/admission/fake" @@ -398,7 +399,7 @@ func TestLimitVerifier(t *testing.T) { err := fmt.Errorf("exceeded %s", strings.Join(exceededStrings, ",")) - return kapierrors.NewForbidden(imageapi.Resource("ImageStream"), isName, err) + return kapierrors.NewForbidden(image.Resource("ImageStream"), isName, err) } makeISEvaluator := func(maxImages, maxImageTags int64) func(string, *imageapi.ImageStream) error { diff --git a/pkg/image/registry/imagestreamimage/rest.go b/pkg/image/registry/imagestreamimage/rest.go index 2f2ce4c09528..0aa5339a48e3 100644 --- a/pkg/image/registry/imagestreamimage/rest.go +++ b/pkg/image/registry/imagestreamimage/rest.go @@ -11,6 +11,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + imagegroup "github.com/openshift/api/image" imageapi "github.com/openshift/origin/pkg/image/apis/image" "github.com/openshift/origin/pkg/image/registry/image" "github.com/openshift/origin/pkg/image/registry/imagestream" @@ -79,7 +80,7 @@ func (r *REST) Get(ctx context.Context, id string, options *metav1.GetOptions) ( } if repo.Status.Tags == nil { - return nil, errors.NewNotFound(imageapi.Resource("imagestreamimage"), id) + return nil, errors.NewNotFound(imagegroup.Resource("imagestreamimage"), id) } event, err := imageapi.ResolveImageID(repo, imageID) diff --git a/pkg/image/registry/imagestreamimport/rest.go b/pkg/image/registry/imagestreamimport/rest.go index 1c6dbd87b6b5..474fe487ac6b 100644 --- a/pkg/image/registry/imagestreamimport/rest.go +++ b/pkg/image/registry/imagestreamimport/rest.go @@ -24,6 +24,7 @@ import ( kapihelper "k8s.io/kubernetes/pkg/apis/core/helper" authorizationclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/authorization/internalversion" + "github.com/openshift/api/image" imageapiv1 "github.com/openshift/api/image/v1" imageclientv1 "github.com/openshift/client-go/image/clientset/versioned/typed/image/v1" authorizationutil "github.com/openshift/origin/pkg/authorization/util" @@ -148,7 +149,7 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation if !isCreateImage.Status.Allowed && !isCreateImageStreamMapping.Status.Allowed { if errs := r.strategy.ValidateAllowedRegistries(isi); len(errs) != 0 { - return nil, kapierrors.NewInvalid(imageapi.Kind("ImageStreamImport"), isi.Name, errs) + return nil, kapierrors.NewInvalid(image.Kind("ImageStreamImport"), isi.Name, errs) } } @@ -184,11 +185,11 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation } else { if len(inputMeta.ResourceVersion) > 0 && inputMeta.ResourceVersion != stream.ResourceVersion { glog.V(4).Infof("DEBUG: mismatch between requested ResourceVersion %s and located ResourceVersion %s", inputMeta.ResourceVersion, stream.ResourceVersion) - return nil, kapierrors.NewConflict(imageapi.Resource("imagestream"), inputMeta.Name, fmt.Errorf("the image stream was updated from %q to %q", inputMeta.ResourceVersion, stream.ResourceVersion)) + return nil, kapierrors.NewConflict(image.Resource("imagestream"), inputMeta.Name, fmt.Errorf("the image stream was updated from %q to %q", inputMeta.ResourceVersion, stream.ResourceVersion)) } if len(inputMeta.UID) > 0 && inputMeta.UID != stream.UID { glog.V(4).Infof("DEBUG: mismatch between requested UID %s and located UID %s", inputMeta.UID, stream.UID) - return nil, kapierrors.NewNotFound(imageapi.Resource("imagestream"), inputMeta.Name) + return nil, kapierrors.NewNotFound(image.Resource("imagestream"), inputMeta.Name) } } @@ -342,7 +343,7 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation return nil, err } legacyscheme.Scheme.Default(external) - internal, err := legacyscheme.Scheme.ConvertToVersion(external, imageapi.SchemeGroupVersion) + internal, err := legacyscheme.Scheme.ConvertToVersion(external, imageapi.GroupVersion) if err != nil { return nil, err } diff --git a/pkg/image/registry/imagestreammapping/rest.go b/pkg/image/registry/imagestreammapping/rest.go index be7ea3d1e47c..99cafffdbeed 100644 --- a/pkg/image/registry/imagestreammapping/rest.go +++ b/pkg/image/registry/imagestreammapping/rest.go @@ -14,6 +14,7 @@ import ( "k8s.io/apiserver/pkg/registry/rest" kapihelper "k8s.io/kubernetes/pkg/apis/core/helper" + imagegroup "github.com/openshift/api/image" imageapi "github.com/openshift/origin/pkg/image/apis/image" "github.com/openshift/origin/pkg/image/registry/image" "github.com/openshift/origin/pkg/image/registry/imagestream" @@ -169,9 +170,9 @@ func (s *REST) findStreamForMapping(ctx context.Context, mapping *imageapi.Image return &list.Items[i], nil } } - return nil, errors.NewInvalid(imageapi.Kind("ImageStreamMapping"), "", field.ErrorList{ + return nil, errors.NewInvalid(imagegroup.Kind("ImageStreamMapping"), "", field.ErrorList{ field.NotFound(field.NewPath("dockerImageStream"), mapping.DockerImageRepository), }) } - return nil, errors.NewNotFound(imageapi.Resource("imagestream"), "") + return nil, errors.NewNotFound(imagegroup.Resource("imagestream"), "") } diff --git a/pkg/image/registry/imagestreammapping/rest_test.go b/pkg/image/registry/imagestreammapping/rest_test.go index 0a7fa28dd290..fa282ed7d2eb 100644 --- a/pkg/image/registry/imagestreammapping/rest_test.go +++ b/pkg/image/registry/imagestreammapping/rest_test.go @@ -25,6 +25,7 @@ import ( authorizationapi "k8s.io/kubernetes/pkg/apis/authorization" kapi "k8s.io/kubernetes/pkg/apis/core" + imagegroup "github.com/openshift/api/image" imagev1 "github.com/openshift/api/image/v1" admfake "github.com/openshift/origin/pkg/image/admission/fake" imageapi "github.com/openshift/origin/pkg/image/apis/image" @@ -648,7 +649,7 @@ func TestCreateRetryConflictNoTagDiff(t *testing.T) { // image stream whose tags haven't changed. if firstUpdate { firstUpdate = false - return nil, errors.NewConflict(imageapi.Resource("imagestreams"), repo.Name, fmt.Errorf("resource modified")) + return nil, errors.NewConflict(imagegroup.Resource("imagestreams"), repo.Name, fmt.Errorf("resource modified")) } return repo, nil }, @@ -703,7 +704,7 @@ func TestCreateRetryConflictTagDiff(t *testing.T) { // get/compare is retried. if firstUpdate { firstUpdate = false - return nil, errors.NewConflict(imageapi.Resource("imagestreams"), repo.Name, fmt.Errorf("resource modified")) + return nil, errors.NewConflict(imagegroup.Resource("imagestreams"), repo.Name, fmt.Errorf("resource modified")) } return repo, nil }, diff --git a/pkg/image/registry/imagestreamtag/rest.go b/pkg/image/registry/imagestreamtag/rest.go index c18857024711..80810b3de240 100644 --- a/pkg/image/registry/imagestreamtag/rest.go +++ b/pkg/image/registry/imagestreamtag/rest.go @@ -15,6 +15,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + imagegroup "github.com/openshift/api/image" oapi "github.com/openshift/origin/pkg/api" imageapi "github.com/openshift/origin/pkg/image/apis/image" "github.com/openshift/origin/pkg/image/apis/image/validation/whitelist" @@ -175,7 +176,7 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation // The user wants to symlink a tag. _, exists := target.Spec.Tags[imageTag] if exists { - return nil, kapierrors.NewAlreadyExists(imageapi.Resource("imagestreamtag"), istag.Name) + return nil, kapierrors.NewAlreadyExists(imagegroup.Resource("imagestreamtag"), istag.Name) } if istag.Tag != nil { target.Spec.Tags[imageTag] = *istag.Tag @@ -199,7 +200,7 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation } // We tried to update resource, but we kept conflicting. Inform the client that we couldn't complete // the operation but that they may try again. - return nil, kapierrors.NewServerTimeout(imageapi.Resource("imagestreamtags"), "create", 2) + return nil, kapierrors.NewServerTimeout(imagegroup.Resource("imagestreamtags"), "create", 2) } func (r *REST) Update(ctx context.Context, tagName string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) { @@ -251,10 +252,10 @@ func (r *REST) Update(ctx context.Context, tagName string, objInfo rest.UpdatedO istag.ResourceVersion = imageStream.ResourceVersion case len(imageStream.ResourceVersion) == 0: // image stream did not exist, cannot update - return nil, false, kapierrors.NewNotFound(imageapi.Resource("imagestreamtags"), tagName) + return nil, false, kapierrors.NewNotFound(imagegroup.Resource("imagestreamtags"), tagName) case imageStream.ResourceVersion != istag.ResourceVersion: // conflicting input and output - return nil, false, kapierrors.NewConflict(imageapi.Resource("imagestreamtags"), istag.Name, fmt.Errorf("another caller has updated the resource version to %s", imageStream.ResourceVersion)) + return nil, false, kapierrors.NewConflict(imagegroup.Resource("imagestreamtags"), istag.Name, fmt.Errorf("another caller has updated the resource version to %s", imageStream.ResourceVersion)) } // When we began returning image stream labels in 3.6, old clients that didn't need to send labels would be @@ -336,7 +337,7 @@ func (r *REST) Delete(ctx context.Context, id string, options *metav1.DeleteOpti if options != nil { if pre := options.Preconditions; pre != nil { if pre.UID != nil && *pre.UID != stream.UID { - return nil, false, kapierrors.NewConflict(imageapi.Resource("imagestreamtags"), id, fmt.Errorf("the UID precondition was not met")) + return nil, false, kapierrors.NewConflict(imagegroup.Resource("imagestreamtags"), id, fmt.Errorf("the UID precondition was not met")) } } } @@ -356,7 +357,7 @@ func (r *REST) Delete(ctx context.Context, id string, options *metav1.DeleteOpti } if notFound { - return nil, false, kapierrors.NewNotFound(imageapi.Resource("imagestreamtags"), id) + return nil, false, kapierrors.NewNotFound(imagegroup.Resource("imagestreamtags"), id) } _, err = r.imageStreamRegistry.UpdateImageStream(ctx, stream) @@ -370,14 +371,14 @@ func (r *REST) Delete(ctx context.Context, id string, options *metav1.DeleteOpti } // We tried to update resource, but we kept conflicting. Inform the client that we couldn't complete // the operation but that they may try again. - return nil, false, kapierrors.NewServerTimeout(imageapi.Resource("imagestreamtags"), "delete", 2) + return nil, false, kapierrors.NewServerTimeout(imagegroup.Resource("imagestreamtags"), "delete", 2) } // imageFor retrieves the most recent image for a tag in a given imageStreem. func (r *REST) imageFor(ctx context.Context, tag string, imageStream *imageapi.ImageStream) (*imageapi.Image, error) { event := imageapi.LatestTaggedImage(imageStream, tag) if event == nil || len(event.Image) == 0 { - return nil, kapierrors.NewNotFound(imageapi.Resource("imagestreamtags"), imageapi.JoinImageStreamTag(imageStream.Name, tag)) + return nil, kapierrors.NewNotFound(imagegroup.Resource("imagestreamtags"), imageapi.JoinImageStreamTag(imageStream.Name, tag)) } return r.imageRegistry.GetImage(ctx, event.Image, &metav1.GetOptions{}) @@ -392,7 +393,7 @@ func newISTag(tag string, imageStream *imageapi.ImageStream, image *imageapi.Ima if event == nil || len(event.Image) == 0 { if !allowEmptyEvent { glog.V(4).Infof("did not find tag %s in image stream status tags: %#v", tag, imageStream.Status.Tags) - return nil, kapierrors.NewNotFound(imageapi.Resource("imagestreamtags"), istagName) + return nil, kapierrors.NewNotFound(imagegroup.Resource("imagestreamtags"), istagName) } event = &imageapi.TagEvent{ Created: imageStream.CreationTimestamp, diff --git a/pkg/network/apis/network/install/install.go b/pkg/network/apis/network/install/install.go index 73c78d72ebde..a99abbcb8fb1 100644 --- a/pkg/network/apis/network/install/install.go +++ b/pkg/network/apis/network/install/install.go @@ -5,7 +5,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/kubernetes/pkg/api/legacyscheme" - sdnapi "github.com/openshift/origin/pkg/network/apis/network" + networkv1 "github.com/openshift/api/network/v1" sdnapiv1 "github.com/openshift/origin/pkg/network/apis/network/v1" ) @@ -15,7 +15,6 @@ func init() { // Install registers the API group and adds types to a scheme func Install(scheme *runtime.Scheme) { - utilruntime.Must(sdnapi.AddToScheme(scheme)) - utilruntime.Must(sdnapiv1.AddToScheme(scheme)) - utilruntime.Must(scheme.SetVersionPriority(sdnapiv1.SchemeGroupVersion)) + utilruntime.Must(sdnapiv1.Install(scheme)) + utilruntime.Must(scheme.SetVersionPriority(networkv1.GroupVersion)) } diff --git a/pkg/network/apis/network/register.go b/pkg/network/apis/network/register.go index faf2bf1e4adf..db157b177607 100644 --- a/pkg/network/apis/network/register.go +++ b/pkg/network/apis/network/register.go @@ -6,28 +6,23 @@ import ( ) const ( - GroupName = "network.openshift.io" - LegacyGroupName = "" + GroupName = "network.openshift.io" ) -// SchemeGroupVersion is group version used to register these objects var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: runtime.APIVersionInternal} - - LegacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme + schemeBuilder = runtime.NewSchemeBuilder( + addKnownTypes, + ) + Install = schemeBuilder.AddToScheme - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // DEPRECATED kept for generated code + SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} + // DEPRECATED kept for generated code + AddToScheme = schemeBuilder.AddToScheme ) -// Kind takes an unqualified kind and returns back a Group qualified GroupKind -func Kind(kind string) schema.GroupKind { - return SchemeGroupVersion.WithKind(kind).GroupKind() -} - -// Resource takes an unqualified resource and returns back a Group qualified GroupResource +// Resource kept for generated code +// DEPRECATED func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } @@ -46,19 +41,3 @@ func addKnownTypes(scheme *runtime.Scheme) error { ) return nil } - -// Adds the list of known types to api.Scheme. -func addLegacyKnownTypes(scheme *runtime.Scheme) error { - types := []runtime.Object{ - &ClusterNetwork{}, - &ClusterNetworkList{}, - &HostSubnet{}, - &HostSubnetList{}, - &NetNamespace{}, - &NetNamespaceList{}, - &EgressNetworkPolicy{}, - &EgressNetworkPolicyList{}, - } - scheme.AddKnownTypes(LegacySchemeGroupVersion, types...) - return nil -} diff --git a/pkg/network/apis/network/v1/register.go b/pkg/network/apis/network/v1/register.go index 1b1ade25cdcf..f96b7cb40bb6 100644 --- a/pkg/network/apis/network/v1/register.go +++ b/pkg/network/apis/network/v1/register.go @@ -1,30 +1,17 @@ package v1 import ( - "github.com/openshift/api/network/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) -const ( - GroupName = "network.openshift.io" - LegacyGroupName = "" + "github.com/openshift/api/network/v1" + "github.com/openshift/origin/pkg/network/apis/network" ) -// SchemeGroupVersion is group version used to register these objects var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: "v1"} - - LegacySchemeBuilder = runtime.NewSchemeBuilder(v1.DeprecatedInstallWithoutGroup, RegisterDefaults, RegisterConversions) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme - - SchemeBuilder = runtime.NewSchemeBuilder(v1.Install) - AddToScheme = SchemeBuilder.AddToScheme - - localSchemeBuilder = &SchemeBuilder + localSchemeBuilder = runtime.NewSchemeBuilder( + network.Install, + v1.Install, + RegisterDefaults, + ) + Install = localSchemeBuilder.AddToScheme ) - -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} diff --git a/pkg/network/registry/clusternetwork/etcd/etcd.go b/pkg/network/registry/clusternetwork/etcd/etcd.go index 953123ebf63d..7cea4326edaf 100644 --- a/pkg/network/registry/clusternetwork/etcd/etcd.go +++ b/pkg/network/registry/clusternetwork/etcd/etcd.go @@ -8,6 +8,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/network" networkapi "github.com/openshift/origin/pkg/network/apis/network" "github.com/openshift/origin/pkg/network/registry/clusternetwork" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" @@ -26,7 +27,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &networkapi.ClusterNetwork{} }, NewListFunc: func() runtime.Object { return &networkapi.ClusterNetworkList{} }, - DefaultQualifiedResource: networkapi.Resource("clusternetworks"), + DefaultQualifiedResource: network.Resource("clusternetworks"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/network/registry/egressnetworkpolicy/etcd/etcd.go b/pkg/network/registry/egressnetworkpolicy/etcd/etcd.go index d4146d95cfef..c0cc5b7aceac 100644 --- a/pkg/network/registry/egressnetworkpolicy/etcd/etcd.go +++ b/pkg/network/registry/egressnetworkpolicy/etcd/etcd.go @@ -8,6 +8,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/network" networkapi "github.com/openshift/origin/pkg/network/apis/network" "github.com/openshift/origin/pkg/network/registry/egressnetworkpolicy" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" @@ -26,7 +27,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &networkapi.EgressNetworkPolicy{} }, NewListFunc: func() runtime.Object { return &networkapi.EgressNetworkPolicyList{} }, - DefaultQualifiedResource: networkapi.Resource("egressnetworkpolicies"), + DefaultQualifiedResource: network.Resource("egressnetworkpolicies"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/network/registry/hostsubnet/etcd/etcd.go b/pkg/network/registry/hostsubnet/etcd/etcd.go index b5dc918b5e52..a2cb02d94b5f 100644 --- a/pkg/network/registry/hostsubnet/etcd/etcd.go +++ b/pkg/network/registry/hostsubnet/etcd/etcd.go @@ -8,6 +8,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/network" networkapi "github.com/openshift/origin/pkg/network/apis/network" "github.com/openshift/origin/pkg/network/registry/hostsubnet" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" @@ -26,7 +27,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &networkapi.HostSubnet{} }, NewListFunc: func() runtime.Object { return &networkapi.HostSubnetList{} }, - DefaultQualifiedResource: networkapi.Resource("hostsubnets"), + DefaultQualifiedResource: network.Resource("hostsubnets"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/network/registry/netnamespace/etcd/etcd.go b/pkg/network/registry/netnamespace/etcd/etcd.go index d2014978b47a..d5c8c26a2e62 100644 --- a/pkg/network/registry/netnamespace/etcd/etcd.go +++ b/pkg/network/registry/netnamespace/etcd/etcd.go @@ -8,6 +8,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/network" networkapi "github.com/openshift/origin/pkg/network/apis/network" "github.com/openshift/origin/pkg/network/registry/netnamespace" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" @@ -26,7 +27,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &networkapi.NetNamespace{} }, NewListFunc: func() runtime.Object { return &networkapi.NetNamespaceList{} }, - DefaultQualifiedResource: networkapi.Resource("netnamespaces"), + DefaultQualifiedResource: network.Resource("netnamespaces"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/oauth/apis/oauth/install/install.go b/pkg/oauth/apis/oauth/install/install.go index 21037da39dfa..89f7ac465dbb 100644 --- a/pkg/oauth/apis/oauth/install/install.go +++ b/pkg/oauth/apis/oauth/install/install.go @@ -5,7 +5,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/kubernetes/pkg/api/legacyscheme" - oauthapi "github.com/openshift/origin/pkg/oauth/apis/oauth" + oauthv1 "github.com/openshift/api/oauth/v1" oauthapiv1 "github.com/openshift/origin/pkg/oauth/apis/oauth/v1" ) @@ -15,7 +15,6 @@ func init() { // Install registers the API group and adds types to a scheme func Install(scheme *runtime.Scheme) { - utilruntime.Must(oauthapi.AddToScheme(scheme)) - utilruntime.Must(oauthapiv1.AddToScheme(scheme)) - utilruntime.Must(scheme.SetVersionPriority(oauthapiv1.SchemeGroupVersion)) + utilruntime.Must(oauthapiv1.Install(scheme)) + utilruntime.Must(scheme.SetVersionPriority(oauthv1.GroupVersion)) } diff --git a/pkg/oauth/apis/oauth/register.go b/pkg/oauth/apis/oauth/register.go index 94f9d4fc7f9b..13709c3946b6 100644 --- a/pkg/oauth/apis/oauth/register.go +++ b/pkg/oauth/apis/oauth/register.go @@ -6,28 +6,23 @@ import ( ) const ( - GroupName = "oauth.openshift.io" - LegacyGroupName = "" + GroupName = "oauth.openshift.io" ) -// SchemeGroupVersion is group version used to register these objects var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: runtime.APIVersionInternal} - - LegacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme + schemeBuilder = runtime.NewSchemeBuilder( + addKnownTypes, + ) + Install = schemeBuilder.AddToScheme - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // DEPRECATED kept for generated code + SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} + // DEPRECATED kept for generated code + AddToScheme = schemeBuilder.AddToScheme ) -// Kind takes an unqualified kind and returns back a Group qualified GroupKind -func Kind(kind string) schema.GroupKind { - return SchemeGroupVersion.WithKind(kind).GroupKind() -} - -// Resource takes an unqualified resource and returns back a Group qualified GroupResource +// Resource kept for generated code +// DEPRECATED func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } @@ -47,19 +42,3 @@ func addKnownTypes(scheme *runtime.Scheme) error { ) return nil } - -func addLegacyKnownTypes(scheme *runtime.Scheme) error { - types := []runtime.Object{ - &OAuthAccessToken{}, - &OAuthAccessTokenList{}, - &OAuthAuthorizeToken{}, - &OAuthAuthorizeTokenList{}, - &OAuthClient{}, - &OAuthClientList{}, - &OAuthClientAuthorization{}, - &OAuthClientAuthorizationList{}, - &OAuthRedirectReference{}, - } - scheme.AddKnownTypes(LegacySchemeGroupVersion, types...) - return nil -} diff --git a/pkg/oauth/apis/oauth/v1/conversion.go b/pkg/oauth/apis/oauth/v1/conversion.go index 69cc281d5806..e626d1b178b4 100644 --- a/pkg/oauth/apis/oauth/v1/conversion.go +++ b/pkg/oauth/apis/oauth/v1/conversion.go @@ -2,33 +2,18 @@ package v1 import ( "k8s.io/apimachinery/pkg/runtime" -) - -func addConversionFuncs(scheme *runtime.Scheme) error { - return nil -} -func addLegacyFieldSelectorKeyConversions(scheme *runtime.Scheme) error { - if err := scheme.AddFieldLabelConversionFunc(LegacySchemeGroupVersion.String(), "OAuthAccessToken", legacyOAuthAccessTokenFieldSelectorKeyConversionFunc); err != nil { - return err - } - if err := scheme.AddFieldLabelConversionFunc(LegacySchemeGroupVersion.String(), "OAuthAuthorizeToken", legacyOAuthAuthorizeTokenFieldSelectorKeyConversionFunc); err != nil { - return err - } - if err := scheme.AddFieldLabelConversionFunc(LegacySchemeGroupVersion.String(), "OAuthClientAuthorization", legacyOAuthClientAuthorizationFieldSelectorKeyConversionFunc); err != nil { - return err - } - return nil -} + v1 "github.com/openshift/api/oauth/v1" +) func addFieldSelectorKeyConversions(scheme *runtime.Scheme) error { - if err := scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.String(), "OAuthAccessToken", oauthAccessTokenFieldSelectorKeyConversionFunc); err != nil { + if err := scheme.AddFieldLabelConversionFunc(v1.GroupVersion.String(), "OAuthAccessToken", oauthAccessTokenFieldSelectorKeyConversionFunc); err != nil { return err } - if err := scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.String(), "OAuthAuthorizeToken", oauthAuthorizeTokenFieldSelectorKeyConversionFunc); err != nil { + if err := scheme.AddFieldLabelConversionFunc(v1.GroupVersion.String(), "OAuthAuthorizeToken", oauthAuthorizeTokenFieldSelectorKeyConversionFunc); err != nil { return err } - if err := scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.String(), "OAuthClientAuthorization", oauthClientAuthorizationFieldSelectorKeyConversionFunc); err != nil { + if err := scheme.AddFieldLabelConversionFunc(v1.GroupVersion.String(), "OAuthClientAuthorization", oauthClientAuthorizationFieldSelectorKeyConversionFunc); err != nil { return err } return nil @@ -37,18 +22,6 @@ func addFieldSelectorKeyConversions(scheme *runtime.Scheme) error { // 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 legacyOAuthAccessTokenFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { - switch label { - case "clientName", - "userName", - "userUID", - "authorizeToken": - return label, value, nil - default: - return runtime.DefaultMetaV1FieldSelectorConversion(label, value) - } -} - func oauthAccessTokenFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { switch label { case "clientName", @@ -61,17 +34,6 @@ func oauthAccessTokenFieldSelectorKeyConversionFunc(label, value string) (intern } } -func legacyOAuthAuthorizeTokenFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { - switch label { - case "clientName", - "userName", - "userUID": - return label, value, nil - default: - return runtime.DefaultMetaV1FieldSelectorConversion(label, value) - } -} - func oauthAuthorizeTokenFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { switch label { case "clientName", @@ -83,17 +45,6 @@ func oauthAuthorizeTokenFieldSelectorKeyConversionFunc(label, value string) (int } } -func legacyOAuthClientAuthorizationFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { - switch label { - case "clientName", - "userName", - "userUID": - return label, value, nil - default: - return runtime.DefaultMetaV1FieldSelectorConversion(label, value) - } -} - func oauthClientAuthorizationFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { switch label { case "clientName", diff --git a/pkg/oauth/apis/oauth/v1/conversion_test.go b/pkg/oauth/apis/oauth/v1/conversion_test.go index 63547b80edf2..64629a5ecd6f 100644 --- a/pkg/oauth/apis/oauth/v1/conversion_test.go +++ b/pkg/oauth/apis/oauth/v1/conversion_test.go @@ -5,50 +5,29 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" + v1 "github.com/openshift/api/oauth/v1" "github.com/openshift/origin/pkg/api/apihelpers/apitesting" oauthapi "github.com/openshift/origin/pkg/oauth/apis/oauth" ) func TestFieldSelectorConversions(t *testing.T) { apitesting.FieldKeyCheck{ - SchemeBuilder: []func(*runtime.Scheme) error{LegacySchemeBuilder.AddToScheme, oauthapi.LegacySchemeBuilder.AddToScheme}, - Kind: LegacySchemeGroupVersion.WithKind("OAuthAccessToken"), + SchemeBuilder: []func(*runtime.Scheme) error{Install}, + Kind: v1.GroupVersion.WithKind("OAuthAccessToken"), // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST AllowedExternalFieldKeys: []string{"clientName", "userName", "userUID", "authorizeToken"}, FieldKeyEvaluatorFn: oauthapi.OAuthAccessTokenFieldSelector, }.Check(t) apitesting.FieldKeyCheck{ - SchemeBuilder: []func(*runtime.Scheme) error{LegacySchemeBuilder.AddToScheme, oauthapi.LegacySchemeBuilder.AddToScheme}, - Kind: LegacySchemeGroupVersion.WithKind("OAuthAuthorizeToken"), + SchemeBuilder: []func(*runtime.Scheme) error{Install}, + Kind: v1.GroupVersion.WithKind("OAuthAuthorizeToken"), // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST AllowedExternalFieldKeys: []string{"clientName", "userName", "userUID"}, FieldKeyEvaluatorFn: oauthapi.OAuthAuthorizeTokenFieldSelector, }.Check(t) apitesting.FieldKeyCheck{ - SchemeBuilder: []func(*runtime.Scheme) error{LegacySchemeBuilder.AddToScheme, oauthapi.LegacySchemeBuilder.AddToScheme}, - Kind: LegacySchemeGroupVersion.WithKind("OAuthClientAuthorization"), - // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST - AllowedExternalFieldKeys: []string{"clientName", "userName", "userUID"}, - FieldKeyEvaluatorFn: oauthapi.OAuthClientAuthorizationFieldSelector, - }.Check(t) - - apitesting.FieldKeyCheck{ - SchemeBuilder: []func(*runtime.Scheme) error{SchemeBuilder.AddToScheme, oauthapi.SchemeBuilder.AddToScheme}, - Kind: SchemeGroupVersion.WithKind("OAuthAccessToken"), - // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST - AllowedExternalFieldKeys: []string{"clientName", "userName", "userUID", "authorizeToken"}, - FieldKeyEvaluatorFn: oauthapi.OAuthAccessTokenFieldSelector, - }.Check(t) - apitesting.FieldKeyCheck{ - SchemeBuilder: []func(*runtime.Scheme) error{SchemeBuilder.AddToScheme, oauthapi.SchemeBuilder.AddToScheme}, - Kind: SchemeGroupVersion.WithKind("OAuthAuthorizeToken"), - // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST - AllowedExternalFieldKeys: []string{"clientName", "userName", "userUID"}, - FieldKeyEvaluatorFn: oauthapi.OAuthAuthorizeTokenFieldSelector, - }.Check(t) - apitesting.FieldKeyCheck{ - SchemeBuilder: []func(*runtime.Scheme) error{SchemeBuilder.AddToScheme, oauthapi.SchemeBuilder.AddToScheme}, - Kind: SchemeGroupVersion.WithKind("OAuthClientAuthorization"), + SchemeBuilder: []func(*runtime.Scheme) error{Install}, + Kind: v1.GroupVersion.WithKind("OAuthClientAuthorization"), // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST AllowedExternalFieldKeys: []string{"clientName", "userName", "userUID"}, FieldKeyEvaluatorFn: oauthapi.OAuthClientAuthorizationFieldSelector, diff --git a/pkg/oauth/apis/oauth/v1/register.go b/pkg/oauth/apis/oauth/v1/register.go index 958d70642a06..c2f66dc993f6 100644 --- a/pkg/oauth/apis/oauth/v1/register.go +++ b/pkg/oauth/apis/oauth/v1/register.go @@ -1,30 +1,19 @@ package v1 import ( - "github.com/openshift/api/oauth/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) -const ( - GroupName = "oauth.openshift.io" - LegacyGroupName = "" + "github.com/openshift/api/oauth/v1" + "github.com/openshift/origin/pkg/oauth/apis/oauth" ) -// SchemeGroupVersion is group version used to register these objects var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: "v1"} + localSchemeBuilder = runtime.NewSchemeBuilder( + oauth.Install, + v1.Install, - LegacySchemeBuilder = runtime.NewSchemeBuilder(v1.DeprecatedInstallWithoutGroup, addConversionFuncs, addLegacyFieldSelectorKeyConversions, RegisterDefaults, RegisterConversions) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme - - SchemeBuilder = runtime.NewSchemeBuilder(v1.Install, addConversionFuncs, addFieldSelectorKeyConversions, RegisterDefaults) - AddToScheme = SchemeBuilder.AddToScheme - - localSchemeBuilder = &SchemeBuilder + addFieldSelectorKeyConversions, + RegisterDefaults, + ) + Install = localSchemeBuilder.AddToScheme ) - -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} diff --git a/pkg/oauth/registry/oauthaccesstoken/etcd/etcd.go b/pkg/oauth/registry/oauthaccesstoken/etcd/etcd.go index 5e7fcbef9057..4f21e313b741 100644 --- a/pkg/oauth/registry/oauthaccesstoken/etcd/etcd.go +++ b/pkg/oauth/registry/oauthaccesstoken/etcd/etcd.go @@ -9,6 +9,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/oauth" oauthapi "github.com/openshift/origin/pkg/oauth/apis/oauth" "github.com/openshift/origin/pkg/oauth/registry/oauthaccesstoken" "github.com/openshift/origin/pkg/oauth/registry/oauthclient" @@ -29,7 +30,7 @@ func NewREST(optsGetter restoptions.Getter, clientGetter oauthclient.Getter) (*R store := ®istry.Store{ NewFunc: func() runtime.Object { return &oauthapi.OAuthAccessToken{} }, NewListFunc: func() runtime.Object { return &oauthapi.OAuthAccessTokenList{} }, - DefaultQualifiedResource: oauthapi.Resource("oauthaccesstokens"), + DefaultQualifiedResource: oauth.Resource("oauthaccesstokens"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/oauth/registry/oauthauthorizetoken/etcd/etcd.go b/pkg/oauth/registry/oauthauthorizetoken/etcd/etcd.go index d80d1d64e0a9..8cf5ae33174d 100644 --- a/pkg/oauth/registry/oauthauthorizetoken/etcd/etcd.go +++ b/pkg/oauth/registry/oauthauthorizetoken/etcd/etcd.go @@ -9,6 +9,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/oauth" oauthapi "github.com/openshift/origin/pkg/oauth/apis/oauth" "github.com/openshift/origin/pkg/oauth/registry/oauthauthorizetoken" "github.com/openshift/origin/pkg/oauth/registry/oauthclient" @@ -29,7 +30,7 @@ func NewREST(optsGetter restoptions.Getter, clientGetter oauthclient.Getter) (*R store := ®istry.Store{ NewFunc: func() runtime.Object { return &oauthapi.OAuthAuthorizeToken{} }, NewListFunc: func() runtime.Object { return &oauthapi.OAuthAuthorizeTokenList{} }, - DefaultQualifiedResource: oauthapi.Resource("oauthauthorizetokens"), + DefaultQualifiedResource: oauth.Resource("oauthauthorizetokens"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/oauth/registry/oauthclient/etcd/etcd.go b/pkg/oauth/registry/oauthclient/etcd/etcd.go index 7bef02568579..dbd4384cc872 100644 --- a/pkg/oauth/registry/oauthclient/etcd/etcd.go +++ b/pkg/oauth/registry/oauthclient/etcd/etcd.go @@ -8,6 +8,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/oauth" oauthapi "github.com/openshift/origin/pkg/oauth/apis/oauth" "github.com/openshift/origin/pkg/oauth/registry/oauthclient" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" @@ -26,7 +27,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &oauthapi.OAuthClient{} }, NewListFunc: func() runtime.Object { return &oauthapi.OAuthClientList{} }, - DefaultQualifiedResource: oauthapi.Resource("oauthclients"), + DefaultQualifiedResource: oauth.Resource("oauthclients"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/oauth/registry/oauthclientauthorization/etcd/etcd.go b/pkg/oauth/registry/oauthclientauthorization/etcd/etcd.go index 94c2c34bb853..a79378801204 100644 --- a/pkg/oauth/registry/oauthclientauthorization/etcd/etcd.go +++ b/pkg/oauth/registry/oauthclientauthorization/etcd/etcd.go @@ -9,6 +9,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/oauth" oauthapi "github.com/openshift/origin/pkg/oauth/apis/oauth" "github.com/openshift/origin/pkg/oauth/registry/oauthclient" "github.com/openshift/origin/pkg/oauth/registry/oauthclientauthorization" @@ -30,7 +31,7 @@ func NewREST(optsGetter restoptions.Getter, clientGetter oauthclient.Getter) (*R store := ®istry.Store{ NewFunc: func() runtime.Object { return &oauthapi.OAuthClientAuthorization{} }, NewListFunc: func() runtime.Object { return &oauthapi.OAuthClientAuthorizationList{} }, - DefaultQualifiedResource: oauthapi.Resource("oauthclientauthorizations"), + DefaultQualifiedResource: oauth.Resource("oauthclientauthorizations"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/oc/cli/admin/buildchain/buildchain.go b/pkg/oc/cli/admin/buildchain/buildchain.go index 18754c5adcd2..bc988becabc1 100644 --- a/pkg/oc/cli/admin/buildchain/buildchain.go +++ b/pkg/oc/cli/admin/buildchain/buildchain.go @@ -14,6 +14,7 @@ import ( kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" "k8s.io/kubernetes/pkg/kubectl/genericclioptions" + "github.com/openshift/api/image" buildclientinternal "github.com/openshift/origin/pkg/build/generated/internalclientset" buildclient "github.com/openshift/origin/pkg/build/generated/internalclientset/typed/build/internalversion" osutil "github.com/openshift/origin/pkg/cmd/util" @@ -120,13 +121,13 @@ func (o *BuildChainOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, arg if err != nil { return err } - resource, o.name, err = osutil.ResolveResource(imageapi.Resource("imagestreamtags"), args[0], mapper) + resource, o.name, err = osutil.ResolveResource(image.Resource("imagestreamtags"), args[0], mapper) if err != nil { return err } switch resource { - case imageapi.Resource("imagestreamtags"): + case image.Resource("imagestreamtags"): o.name = imageapi.NormalizeImageStreamTag(o.name) glog.V(4).Infof("Using %q as the image stream tag to look dependencies for", o.name) default: diff --git a/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/scc.go b/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/scc.go index f1b1eccb5501..5ddff0e393cc 100644 --- a/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/scc.go +++ b/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/scc.go @@ -9,11 +9,11 @@ import ( "k8s.io/kubernetes/pkg/apis/authorization" authorizationtypedclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/authorization/internalversion" + "github.com/openshift/api/security" "github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" "github.com/openshift/origin/pkg/oc/cli/admin/diagnostics/diagnostics/types" "github.com/openshift/origin/pkg/oc/cli/admin/diagnostics/diagnostics/util" policycmd "github.com/openshift/origin/pkg/oc/cli/admin/policy" - securityapi "github.com/openshift/origin/pkg/security/apis/security" securitytypedclient "github.com/openshift/origin/pkg/security/generated/internalclientset/typed/security/internalversion" ) @@ -44,7 +44,7 @@ func (d *SCC) CanRun() (bool, error) { return util.UserCan(d.SARClient, &authorization.ResourceAttributes{ Verb: "list", - Group: securityapi.GroupName, + Group: security.GroupName, Resource: "securitycontextconstraints", }) } diff --git a/pkg/oc/cli/cancelbuild/cancelbuild.go b/pkg/oc/cli/cancelbuild/cancelbuild.go index 7e167a344934..665ecde5246e 100644 --- a/pkg/oc/cli/cancelbuild/cancelbuild.go +++ b/pkg/oc/cli/cancelbuild/cancelbuild.go @@ -17,6 +17,7 @@ import ( "k8s.io/kubernetes/pkg/kubectl/genericclioptions" "k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers" + "github.com/openshift/api/build" buildapi "github.com/openshift/origin/pkg/build/apis/build" buildclient "github.com/openshift/origin/pkg/build/client" buildinternal "github.com/openshift/origin/pkg/build/client/internalversion" @@ -148,13 +149,13 @@ func (o *CancelBuildOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, ar } for _, item := range args { - resource, name, err := cmdutil.ResolveResource(buildapi.Resource("builds"), item, o.Mapper) + resource, name, err := cmdutil.ResolveResource(build.Resource("builds"), item, o.Mapper) if err != nil { return err } switch resource { - case buildapi.Resource("buildconfigs"): + case build.Resource("buildconfigs"): list, err := buildutil.BuildConfigBuilds(o.BuildLister, o.Namespace, name, nil) if err != nil { return err @@ -162,7 +163,7 @@ func (o *CancelBuildOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, ar for _, b := range list { o.BuildNames = append(o.BuildNames, b.Name) } - case buildapi.Resource("builds"): + case build.Resource("builds"): o.BuildNames = append(o.BuildNames, strings.TrimSpace(name)) default: return fmt.Errorf("invalid resource provided: %v", resource) diff --git a/pkg/oc/cli/importimage/importimage.go b/pkg/oc/cli/importimage/importimage.go index 01614b961adc..f1132fc6681e 100644 --- a/pkg/oc/cli/importimage/importimage.go +++ b/pkg/oc/cli/importimage/importimage.go @@ -268,7 +268,7 @@ func (o *ImportImageOptions) createImageImport() (*imageapi.ImageStream, *imagea return nil, nil, err } legacyscheme.Scheme.Default(external) - internal, err := legacyscheme.Scheme.ConvertToVersion(external, imageapi.SchemeGroupVersion) + internal, err := legacyscheme.Scheme.ConvertToVersion(external, imageapi.GroupVersion) if err != nil { return nil, nil, err } diff --git a/pkg/oc/cli/logs/logs.go b/pkg/oc/cli/logs/logs.go index 561991b7091d..9f5a64e477bb 100644 --- a/pkg/oc/cli/logs/logs.go +++ b/pkg/oc/cli/logs/logs.go @@ -15,6 +15,7 @@ import ( "k8s.io/kubernetes/pkg/kubectl/genericclioptions" "github.com/openshift/api/apps" + "github.com/openshift/api/build" appsapi "github.com/openshift/origin/pkg/apps/apis/apps" buildapi "github.com/openshift/origin/pkg/build/apis/build" buildclientinternal "github.com/openshift/origin/pkg/build/generated/internalclientset" @@ -156,8 +157,8 @@ func (o *LogsOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []st // TODO: podLogOptions should be included in our own logOptions objects. switch gr := infos[0].Mapping.Resource.GroupResource(); gr { - case buildapi.Resource("builds"), - buildapi.Resource("buildconfigs"): + case build.Resource("builds"), + build.Resource("buildconfigs"): bopts := &buildapi.BuildLogOptions{ Follow: podLogOptions.Follow, Previous: podLogOptions.Previous, diff --git a/pkg/oc/cli/newapp/newapp.go b/pkg/oc/cli/newapp/newapp.go index 74eab5367692..9062f17f25df 100644 --- a/pkg/oc/cli/newapp/newapp.go +++ b/pkg/oc/cli/newapp/newapp.go @@ -37,10 +37,10 @@ import ( "k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers" "k8s.io/kubernetes/pkg/kubectl/polymorphichelpers" + "github.com/openshift/api/build" buildv1 "github.com/openshift/api/build/v1" imagev1 "github.com/openshift/api/image/v1" routev1 "github.com/openshift/api/route/v1" - buildapi "github.com/openshift/origin/pkg/build/apis/build" "github.com/openshift/origin/pkg/bulk" cmdutil "github.com/openshift/origin/pkg/cmd/util" "github.com/openshift/origin/pkg/cmd/util/print" @@ -825,7 +825,7 @@ func retryBuildConfig(obj *unstructured.Unstructured, err error) *unstructured.U buildv1.GitLabWebHookBuildTriggerType: {}, buildv1.BitbucketWebHookBuildTriggerType: {}, } - if buildapi.Kind("BuildConfig") == obj.GroupVersionKind().GroupKind() && isInvalidTriggerError(err) { + if build.Kind("BuildConfig") == obj.GroupVersionKind().GroupKind() && isInvalidTriggerError(err) { var bc *buildv1.BuildConfig err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, bc) if err != nil { diff --git a/pkg/oc/cli/process/process.go b/pkg/oc/cli/process/process.go index e6d400ca62e1..284dbe069f2b 100644 --- a/pkg/oc/cli/process/process.go +++ b/pkg/oc/cli/process/process.go @@ -24,6 +24,7 @@ import ( "k8s.io/kubernetes/pkg/kubectl/genericclioptions" "k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource" + "github.com/openshift/api/template" cmdutil "github.com/openshift/origin/pkg/cmd/util" "github.com/openshift/origin/pkg/oc/lib/describe" "github.com/openshift/origin/pkg/oc/lib/newapp/app" @@ -356,13 +357,13 @@ func injectUserVars(values app.Environment, t *templateapi.Template, ignoreUnkno // connection to the server. func processTemplateLocally(tpl *templateapi.Template) error { if errs := templatevalidation.ValidateProcessedTemplate(tpl); len(errs) > 0 { - return errors.NewInvalid(templateapi.Kind("Template"), tpl.Name, errs) + return errors.NewInvalid(template.Kind("Template"), tpl.Name, errs) } processor := templateprocessing.NewProcessor(map[string]generator.Generator{ "expression": generator.NewExpressionValueGenerator(rand.New(rand.NewSource(time.Now().UnixNano()))), }) if errs := processor.Process(tpl); len(errs) > 0 { - return errors.NewInvalid(templateapi.Kind("Template"), tpl.Name, errs) + return errors.NewInvalid(template.Kind("Template"), tpl.Name, errs) } return nil } diff --git a/pkg/oc/cli/startbuild/startbuild.go b/pkg/oc/cli/startbuild/startbuild.go index 28a349703a66..b15a83eb2ba8 100644 --- a/pkg/oc/cli/startbuild/startbuild.go +++ b/pkg/oc/cli/startbuild/startbuild.go @@ -35,6 +35,7 @@ import ( kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" "k8s.io/kubernetes/pkg/kubectl/genericclioptions" + "github.com/openshift/api/build" buildapiv1 "github.com/openshift/api/build/v1" buildapi "github.com/openshift/origin/pkg/build/apis/build" buildclientinternalmanual "github.com/openshift/origin/pkg/build/client/internalversion" @@ -253,7 +254,7 @@ func (o *StartBuildOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, cmd var ( name = buildName - resource = buildapi.Resource("builds") + resource = build.Resource("builds") ) if len(name) == 0 && len(args) > 0 && len(args[0]) > 0 { @@ -261,14 +262,14 @@ func (o *StartBuildOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, cmd if err != nil { return err } - resource, name, err = cmdutil.ResolveResource(buildapi.Resource("buildconfigs"), args[0], mapper) + resource, name, err = cmdutil.ResolveResource(build.Resource("buildconfigs"), args[0], mapper) if err != nil { return err } switch resource { - case buildapi.Resource("buildconfigs"): + case build.Resource("buildconfigs"): // no special handling required - case buildapi.Resource("builds"): + case build.Resource("builds"): if len(o.ListWebhooks) == 0 { return fmt.Errorf("use --from-build to rerun your builds") } @@ -278,7 +279,7 @@ func (o *StartBuildOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, cmd } // when listing webhooks, allow --from-build to lookup a build config - if buildapi.Resource("builds") == resource && len(o.ListWebhooks) > 0 { + if build.Resource("builds") == resource && len(o.ListWebhooks) > 0 { build, err := o.BuildClient.Builds(namespace).Get(name, metav1.GetOptions{}) if err != nil { return err diff --git a/pkg/oc/cli/tag/tag_test.go b/pkg/oc/cli/tag/tag_test.go index f4850c89a57e..092c7dfaf9ac 100644 --- a/pkg/oc/cli/tag/tag_test.go +++ b/pkg/oc/cli/tag/tag_test.go @@ -12,6 +12,7 @@ import ( api "k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/pkg/kubectl/genericclioptions" + "github.com/openshift/api/image" imageapi "github.com/openshift/origin/pkg/image/apis/image" imagefake "github.com/openshift/origin/pkg/image/generated/internalclientset/fake" ) @@ -167,10 +168,10 @@ func TestTag(t *testing.T) { for name, test := range testCases { client := imagefake.NewSimpleClientset(test.data...) client.PrependReactor("create", "imagestreamtags", func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) { - return true, nil, kapierrors.NewMethodNotSupported(imageapi.Resource("imagestreamtags"), "create") + return true, nil, kapierrors.NewMethodNotSupported(image.Resource("imagestreamtags"), "create") }) client.PrependReactor("update", "imagestreamtags", func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) { - return true, nil, kapierrors.NewMethodNotSupported(imageapi.Resource("imagestreamtags"), "update") + return true, nil, kapierrors.NewMethodNotSupported(image.Resource("imagestreamtags"), "update") }) test.opts.IOStreams = genericclioptions.IOStreams{Out: os.Stdout, ErrOut: os.Stderr} @@ -207,7 +208,7 @@ func TestRunTag_DeleteOld(t *testing.T) { streams := testData() client := imagefake.NewSimpleClientset(streams[1]) client.PrependReactor("delete", "imagestreamtags", func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) { - return true, nil, kapierrors.NewForbidden(imageapi.Resource("imagestreamtags"), "rails:tip", fmt.Errorf("dne")) + return true, nil, kapierrors.NewForbidden(image.Resource("imagestreamtags"), "rails:tip", fmt.Errorf("dne")) }) client.PrependReactor("get", "imagestreams", func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) { return true, testData()[1], nil @@ -306,7 +307,7 @@ func TestRunTag_AddRestricted(t *testing.T) { return true, action.(clientgotesting.CreateAction).GetObject(), nil }) client.PrependReactor("update", "imagestreamtags", func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) { - return true, nil, kapierrors.NewForbidden(imageapi.Resource("imagestreamtags"), "rails:tip", fmt.Errorf("dne")) + return true, nil, kapierrors.NewForbidden(image.Resource("imagestreamtags"), "rails:tip", fmt.Errorf("dne")) }) test := struct { diff --git a/pkg/oc/lib/describe/describer.go b/pkg/oc/lib/describe/describer.go index c082b6b1929f..500458b6a255 100644 --- a/pkg/oc/lib/describe/describer.go +++ b/pkg/oc/lib/describe/describer.go @@ -28,6 +28,16 @@ import ( oapps "github.com/openshift/api/apps" authorization "github.com/openshift/api/authorization" + "github.com/openshift/api/build" + "github.com/openshift/api/image" + "github.com/openshift/api/network" + "github.com/openshift/api/oauth" + "github.com/openshift/api/project" + "github.com/openshift/api/quota" + "github.com/openshift/api/route" + "github.com/openshift/api/security" + "github.com/openshift/api/template" + "github.com/openshift/api/user" oapi "github.com/openshift/origin/pkg/api" appsclient "github.com/openshift/origin/pkg/apps/generated/internalclientset/typed/apps/internalversion" authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization" @@ -36,9 +46,7 @@ import ( buildclient "github.com/openshift/origin/pkg/build/generated/internalclientset/typed/build/internalversion" imageapi "github.com/openshift/origin/pkg/image/apis/image" imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset/typed/image/internalversion" - networkapi "github.com/openshift/origin/pkg/network/apis/network" onetworkclient "github.com/openshift/origin/pkg/network/generated/internalclientset/typed/network/internalversion" - oauthapi "github.com/openshift/origin/pkg/oauth/apis/oauth" oauthclient "github.com/openshift/origin/pkg/oauth/generated/internalclientset/typed/oauth/internalversion" projectapi "github.com/openshift/origin/pkg/project/apis/project" projectclient "github.com/openshift/origin/pkg/project/generated/internalclientset/typed/project/internalversion" @@ -50,7 +58,6 @@ import ( securityclient "github.com/openshift/origin/pkg/security/generated/internalclientset/typed/security/internalversion" templateapi "github.com/openshift/origin/pkg/template/apis/template" templateclient "github.com/openshift/origin/pkg/template/generated/internalclientset/typed/template/internalversion" - userapi "github.com/openshift/origin/pkg/user/apis/user" userclient "github.com/openshift/origin/pkg/user/generated/internalclientset/typed/user/internalversion" ) @@ -107,34 +114,34 @@ func describerMap(clientConfig *rest.Config, kclient kclientset.Interface, host } m := map[schema.GroupKind]kprinters.Describer{ - buildapi.Kind("Build"): &BuildDescriber{buildClient, kclient}, - buildapi.Kind("BuildConfig"): &BuildConfigDescriber{buildClient, kclient, host}, - oapps.Kind("DeploymentConfig"): &DeploymentConfigDescriber{appsClient, kclient, nil}, - imageapi.Kind("Image"): &ImageDescriber{imageClient}, - imageapi.Kind("ImageStream"): &ImageStreamDescriber{imageClient}, - imageapi.Kind("ImageStreamTag"): &ImageStreamTagDescriber{imageClient}, - imageapi.Kind("ImageStreamImage"): &ImageStreamImageDescriber{imageClient}, - routeapi.Kind("Route"): &RouteDescriber{routeClient, kclient}, - projectapi.Kind("Project"): &ProjectDescriber{projectClient, kclient}, - templateapi.Kind("Template"): &TemplateDescriber{templateClient, meta.NewAccessor(), legacyscheme.Scheme, nil}, - templateapi.Kind("TemplateInstance"): &TemplateInstanceDescriber{kclient, templateClient, nil}, - authorization.Kind("RoleBinding"): &RoleBindingDescriber{oauthorizationClient}, - authorization.Kind("Role"): &RoleDescriber{oauthorizationClient}, - authorization.Kind("ClusterRoleBinding"): &ClusterRoleBindingDescriber{oauthorizationClient}, - authorization.Kind("ClusterRole"): &ClusterRoleDescriber{oauthorizationClient}, - authorization.Kind("RoleBindingRestriction"): &RoleBindingRestrictionDescriber{oauthorizationClient}, - oauthapi.Kind("OAuthAccessToken"): &OAuthAccessTokenDescriber{oauthClient}, - userapi.Kind("Identity"): &IdentityDescriber{userClient}, - userapi.Kind("User"): &UserDescriber{userClient}, - userapi.Kind("Group"): &GroupDescriber{userClient}, - userapi.Kind("UserIdentityMapping"): &UserIdentityMappingDescriber{userClient}, - quotaapi.Kind("ClusterResourceQuota"): &ClusterQuotaDescriber{quotaClient}, - quotaapi.Kind("AppliedClusterResourceQuota"): &AppliedClusterQuotaDescriber{quotaClient}, - networkapi.Kind("ClusterNetwork"): &ClusterNetworkDescriber{onetworkClient}, - networkapi.Kind("HostSubnet"): &HostSubnetDescriber{onetworkClient}, - networkapi.Kind("NetNamespace"): &NetNamespaceDescriber{onetworkClient}, - networkapi.Kind("EgressNetworkPolicy"): &EgressNetworkPolicyDescriber{onetworkClient}, - securityapi.Kind("SecurityContextConstraints"): &SecurityContextConstraintsDescriber{securityClient}, + oapps.Kind("DeploymentConfig"): &DeploymentConfigDescriber{appsClient, kclient, nil}, + build.Kind("Build"): &BuildDescriber{buildClient, kclient}, + build.Kind("BuildConfig"): &BuildConfigDescriber{buildClient, kclient, host}, + image.Kind("Image"): &ImageDescriber{imageClient}, + image.Kind("ImageStream"): &ImageStreamDescriber{imageClient}, + image.Kind("ImageStreamTag"): &ImageStreamTagDescriber{imageClient}, + image.Kind("ImageStreamImage"): &ImageStreamImageDescriber{imageClient}, + route.Kind("Route"): &RouteDescriber{routeClient, kclient}, + project.Kind("Project"): &ProjectDescriber{projectClient, kclient}, + template.Kind("Template"): &TemplateDescriber{templateClient, meta.NewAccessor(), legacyscheme.Scheme, nil}, + template.Kind("TemplateInstance"): &TemplateInstanceDescriber{kclient, templateClient, nil}, + authorization.Kind("RoleBinding"): &RoleBindingDescriber{oauthorizationClient}, + authorization.Kind("Role"): &RoleDescriber{oauthorizationClient}, + authorization.Kind("ClusterRoleBinding"): &ClusterRoleBindingDescriber{oauthorizationClient}, + authorization.Kind("ClusterRole"): &ClusterRoleDescriber{oauthorizationClient}, + authorization.Kind("RoleBindingRestriction"): &RoleBindingRestrictionDescriber{oauthorizationClient}, + oauth.Kind("OAuthAccessToken"): &OAuthAccessTokenDescriber{oauthClient}, + user.Kind("Identity"): &IdentityDescriber{userClient}, + user.Kind("User"): &UserDescriber{userClient}, + user.Kind("Group"): &GroupDescriber{userClient}, + user.Kind("UserIdentityMapping"): &UserIdentityMappingDescriber{userClient}, + quota.Kind("ClusterResourceQuota"): &ClusterQuotaDescriber{quotaClient}, + quota.Kind("AppliedClusterResourceQuota"): &AppliedClusterQuotaDescriber{quotaClient}, + network.Kind("ClusterNetwork"): &ClusterNetworkDescriber{onetworkClient}, + network.Kind("HostSubnet"): &HostSubnetDescriber{onetworkClient}, + network.Kind("NetNamespace"): &NetNamespaceDescriber{onetworkClient}, + network.Kind("EgressNetworkPolicy"): &EgressNetworkPolicyDescriber{onetworkClient}, + security.Kind("SecurityContextConstraints"): &SecurityContextConstraintsDescriber{securityClient}, } // Register the legacy ("core") API group for all kinds as well. diff --git a/pkg/oc/lib/newapp/app/pipeline.go b/pkg/oc/lib/newapp/app/pipeline.go index 14bbe2a181be..51051323613b 100644 --- a/pkg/oc/lib/newapp/app/pipeline.go +++ b/pkg/oc/lib/newapp/app/pipeline.go @@ -17,6 +17,9 @@ import ( "k8s.io/kubernetes/pkg/apis/core/validation" extensions "k8s.io/kubernetes/pkg/apis/extensions" + "github.com/openshift/api/build" + "github.com/openshift/api/image" + "github.com/openshift/origin/pkg/api/legacy" appsapi "github.com/openshift/origin/pkg/apps/apis/apps" buildapi "github.com/openshift/origin/pkg/build/apis/build" imageapi "github.com/openshift/origin/pkg/image/apis/image" @@ -486,7 +489,7 @@ func (a *acceptNonExistentImageStream) Accept(from interface{}) bool { return false } gk := gvk[0].GroupKind() - if !(imageapi.Kind("ImageStream") == gk || imageapi.LegacyKind("ImageStream") == gk) { + if !(image.Kind("ImageStream") == gk || legacy.Kind("ImageStream") == gk) { return true } is, ok := from.(*imageapi.ImageStream) @@ -531,7 +534,7 @@ func (a *acceptNonExistentImageStreamTag) Accept(from interface{}) bool { return false } gk := gvk[0].GroupKind() - if !(imageapi.Kind("ImageStreamTag") == gk || imageapi.LegacyKind("ImageStreamTag") == gk) { + if !(image.Kind("ImageStreamTag") == gk || legacy.Kind("ImageStreamTag") == gk) { return true } ist, ok := from.(*imageapi.ImageStreamTag) @@ -585,7 +588,7 @@ func (a *acceptBuildConfigs) Accept(from interface{}) bool { return false } gk := gvk[0].GroupKind() - return buildapi.Kind("BuildConfig") == gk || imageapi.Kind("ImageStream") == gk + return build.Kind("BuildConfig") == gk || image.Kind("ImageStream") == gk } // NewAcceptBuildConfigs creates an acceptor accepting BuildConfig objects diff --git a/pkg/oc/util/ocscheme/read_internal.go b/pkg/oc/util/ocscheme/read_internal.go index b91fb5b2cf81..953f5e0b25e5 100644 --- a/pkg/oc/util/ocscheme/read_internal.go +++ b/pkg/oc/util/ocscheme/read_internal.go @@ -34,7 +34,7 @@ var ReadingInternalScheme = runtime.NewScheme() func init() { install.InstallAll(ReadingInternalScheme) - legacy.LegacyInstallAll(ReadingInternalScheme) + legacy.InstallLegacyInternalAll(ReadingInternalScheme) kadmissioninstall.Install(ReadingInternalScheme) kadmissionregistrationinstall.Install(ReadingInternalScheme) diff --git a/pkg/project/admission/requestlimit/admission.go b/pkg/project/admission/requestlimit/admission.go index c6324b68633f..73dc13a11c3c 100644 --- a/pkg/project/admission/requestlimit/admission.go +++ b/pkg/project/admission/requestlimit/admission.go @@ -12,8 +12,10 @@ import ( "k8s.io/apiserver/pkg/authentication/serviceaccount" kapi "k8s.io/kubernetes/pkg/apis/core" + "github.com/openshift/api/project" userclient "github.com/openshift/client-go/user/clientset/versioned" usertypedclient "github.com/openshift/client-go/user/clientset/versioned/typed/user/v1" + "github.com/openshift/origin/pkg/api/legacy" oadmission "github.com/openshift/origin/pkg/cmd/server/admission" configlatest "github.com/openshift/origin/pkg/cmd/server/apis/config/latest" requestlimitapi "github.com/openshift/origin/pkg/project/admission/apis/requestlimit" @@ -78,7 +80,7 @@ func (o *projectRequestLimit) Admit(a admission.Attributes) (err error) { return nil } switch a.GetResource().GroupResource() { - case projectapi.Resource("projectrequests"), projectapi.LegacyResource("projectrequests"): + case project.Resource("projectrequests"), legacy.Resource("projectrequests"): default: return nil } diff --git a/pkg/project/admission/requestlimit/admission_test.go b/pkg/project/admission/requestlimit/admission_test.go index 653533cd5517..b342823f6265 100644 --- a/pkg/project/admission/requestlimit/admission_test.go +++ b/pkg/project/admission/requestlimit/admission_test.go @@ -14,6 +14,7 @@ import ( kapi "k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake" + "github.com/openshift/api/project" userapi "github.com/openshift/api/user/v1" fakeuserclient "github.com/openshift/client-go/user/clientset/versioned/fake" oadmission "github.com/openshift/origin/pkg/cmd/server/admission" @@ -285,10 +286,10 @@ func TestAdmit(t *testing.T) { err = reqLimit.(admission.MutationInterface).Admit(admission.NewAttributesRecord( &projectapi.ProjectRequest{}, nil, - projectapi.Kind("ProjectRequest").WithVersion("version"), + project.Kind("ProjectRequest").WithVersion("version"), "foo", "name", - projectapi.Resource("projectrequests").WithVersion("version"), + project.Resource("projectrequests").WithVersion("version"), "", "CREATE", &user.DefaultInfo{Name: tc.user})) diff --git a/pkg/project/apis/project/install/install.go b/pkg/project/apis/project/install/install.go index 3383740346f4..051ca4ca12d7 100644 --- a/pkg/project/apis/project/install/install.go +++ b/pkg/project/apis/project/install/install.go @@ -5,7 +5,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/kubernetes/pkg/api/legacyscheme" - projectapi "github.com/openshift/origin/pkg/project/apis/project" + projectv1 "github.com/openshift/api/project/v1" projectapiv1 "github.com/openshift/origin/pkg/project/apis/project/v1" ) @@ -15,7 +15,6 @@ func init() { // Install registers the API group and adds types to a scheme func Install(scheme *runtime.Scheme) { - utilruntime.Must(projectapi.AddToScheme(scheme)) - utilruntime.Must(projectapiv1.AddToScheme(scheme)) - utilruntime.Must(scheme.SetVersionPriority(projectapiv1.SchemeGroupVersion)) + utilruntime.Must(projectapiv1.Install(scheme)) + utilruntime.Must(scheme.SetVersionPriority(projectv1.GroupVersion)) } diff --git a/pkg/project/apis/project/register.go b/pkg/project/apis/project/register.go index 8e4837927b08..ecc1032fc4ab 100644 --- a/pkg/project/apis/project/register.go +++ b/pkg/project/apis/project/register.go @@ -3,39 +3,32 @@ package project import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/kubernetes/pkg/apis/core" ) const ( - GroupName = "project.openshift.io" - LegacyGroupName = "" + GroupName = "project.openshift.io" ) -// SchemeGroupVersion is group version used to register these objects var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: runtime.APIVersionInternal} - - LegacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme + schemeBuilder = runtime.NewSchemeBuilder( + addKnownTypes, + core.AddToScheme, + ) + Install = schemeBuilder.AddToScheme - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // DEPRECATED kept for generated code + SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} + // DEPRECATED kept for generated code + AddToScheme = schemeBuilder.AddToScheme ) -// Kind takes an unqualified kind and returns back a Group qualified GroupKind -func Kind(kind string) schema.GroupKind { - return SchemeGroupVersion.WithKind(kind).GroupKind() -} - -// Resource takes an unqualified resource and returns back a Group qualified GroupResource +// Resource kept for generated code +// DEPRECATED func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } -func LegacyResource(resource string) schema.GroupResource { - return LegacySchemeGroupVersion.WithResource(resource).GroupResource() -} - // Adds the list of known types to api.Scheme. func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, @@ -45,13 +38,3 @@ func addKnownTypes(scheme *runtime.Scheme) error { ) return nil } - -func addLegacyKnownTypes(scheme *runtime.Scheme) error { - types := []runtime.Object{ - &Project{}, - &ProjectList{}, - &ProjectRequest{}, - } - scheme.AddKnownTypes(LegacySchemeGroupVersion, types...) - return nil -} diff --git a/pkg/project/apis/project/types.go b/pkg/project/apis/project/types.go index 17168b3455a8..087e35fe1497 100644 --- a/pkg/project/apis/project/types.go +++ b/pkg/project/apis/project/types.go @@ -2,7 +2,7 @@ package project import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - kapi "k8s.io/kubernetes/pkg/apis/core" + "k8s.io/kubernetes/pkg/apis/core" ) // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object @@ -16,18 +16,18 @@ type ProjectList struct { const ( // These are internal finalizer values to Origin - FinalizerOrigin kapi.FinalizerName = "openshift.io/origin" + FinalizerOrigin core.FinalizerName = "openshift.io/origin" ) // ProjectSpec describes the attributes on a Project type ProjectSpec struct { // Finalizers is an opaque list of values that must be empty to permanently remove object from storage - Finalizers []kapi.FinalizerName + Finalizers []core.FinalizerName } // ProjectStatus is information about the current status of a Project type ProjectStatus struct { - Phase kapi.NamespacePhase + Phase core.NamespacePhase } // +genclient diff --git a/pkg/project/apis/project/v1/conversion.go b/pkg/project/apis/project/v1/conversion.go index 000de0246867..b4a47c438bb2 100644 --- a/pkg/project/apis/project/v1/conversion.go +++ b/pkg/project/apis/project/v1/conversion.go @@ -1,23 +1,12 @@ package v1 import ( - "github.com/openshift/origin/pkg/api/apihelpers" + v1 "github.com/openshift/api/project/v1" "k8s.io/apimachinery/pkg/runtime" ) -func addConversionFuncs(scheme *runtime.Scheme) error { - return nil -} - -func addLegacyFieldSelectorKeyConversions(scheme *runtime.Scheme) error { - if err := scheme.AddFieldLabelConversionFunc(LegacySchemeGroupVersion.String(), "Project", legacyProjectFieldSelectorKeyConversionFunc); err != nil { - return err - } - return nil -} - func addFieldSelectorKeyConversions(scheme *runtime.Scheme) error { - if err := scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.String(), "Project", projectFieldSelectorKeyConversionFunc); err != nil { + if err := scheme.AddFieldLabelConversionFunc(v1.GroupVersion.String(), "Project", projectFieldSelectorKeyConversionFunc); err != nil { return err } return nil @@ -28,15 +17,6 @@ func addFieldSelectorKeyConversions(scheme *runtime.Scheme) error { // we don't actually do any evaluation, only passing through, so we don't have our own field selector to test. The upstream // cannot remove the field selectors or they break compatibility, so we're fine. -func legacyProjectFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { - switch label { - case "status.phase": - return label, value, nil - default: - return apihelpers.LegacyMetaV1FieldSelectorConversionWithName(label, value) - } -} - func projectFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { switch label { case "status.phase": diff --git a/pkg/project/apis/project/v1/register.go b/pkg/project/apis/project/v1/register.go index ad8536962cf9..29fab2874b35 100644 --- a/pkg/project/apis/project/v1/register.go +++ b/pkg/project/apis/project/v1/register.go @@ -1,30 +1,21 @@ package v1 import ( - "github.com/openshift/api/project/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) + corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1" -const ( - GroupName = "project.openshift.io" - LegacyGroupName = "" + "github.com/openshift/api/project/v1" + "github.com/openshift/origin/pkg/project/apis/project" ) -// SchemeGroupVersion is group version used to register these objects var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: "v1"} + localSchemeBuilder = runtime.NewSchemeBuilder( + project.Install, + v1.Install, + corev1conversions.AddToScheme, - LegacySchemeBuilder = runtime.NewSchemeBuilder(v1.DeprecatedInstallWithoutGroup, addConversionFuncs, addLegacyFieldSelectorKeyConversions, RegisterDefaults, RegisterConversions) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme - - SchemeBuilder = runtime.NewSchemeBuilder(v1.Install, addConversionFuncs, addFieldSelectorKeyConversions) - AddToScheme = SchemeBuilder.AddToScheme - - localSchemeBuilder = &SchemeBuilder + addFieldSelectorKeyConversions, + RegisterDefaults, + ) + Install = localSchemeBuilder.AddToScheme ) - -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} diff --git a/pkg/project/registry/project/proxy/proxy.go b/pkg/project/registry/project/proxy/proxy.go index c6ec6ab796f7..49bae17a62e1 100644 --- a/pkg/project/registry/project/proxy/proxy.go +++ b/pkg/project/registry/project/proxy/proxy.go @@ -19,6 +19,7 @@ import ( printerstorage "k8s.io/kubernetes/pkg/printers/storage" nsregistry "k8s.io/kubernetes/pkg/registry/core/namespace" + "github.com/openshift/api/project" oapi "github.com/openshift/origin/pkg/api" authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization" "github.com/openshift/origin/pkg/authorization/authorizer/scope" @@ -86,7 +87,7 @@ func (s *REST) NamespaceScoped() bool { func (s *REST) List(ctx context.Context, options *metainternal.ListOptions) (runtime.Object, error) { user, ok := apirequest.UserFrom(ctx) if !ok { - return nil, kerrors.NewForbidden(projectapi.Resource("project"), "", fmt.Errorf("unable to list projects without a user on the context")) + return nil, kerrors.NewForbidden(project.Resource("project"), "", fmt.Errorf("unable to list projects without a user on the context")) } namespaceList, err := s.lister.List(user) if err != nil { @@ -142,20 +143,20 @@ var _ = rest.Creater(&REST{}) // Create registers the given Project. func (s *REST) Create(ctx context.Context, obj runtime.Object, creationValidation rest.ValidateObjectFunc, _ bool) (runtime.Object, error) { - project, ok := obj.(*projectapi.Project) + projectObj, ok := obj.(*projectapi.Project) if !ok { return nil, fmt.Errorf("not a project: %#v", obj) } - rest.FillObjectMetaSystemFields(&project.ObjectMeta) + rest.FillObjectMetaSystemFields(&projectObj.ObjectMeta) s.createStrategy.PrepareForCreate(ctx, obj) if errs := s.createStrategy.Validate(ctx, obj); len(errs) > 0 { - return nil, kerrors.NewInvalid(projectapi.Kind("Project"), project.Name, errs) + return nil, kerrors.NewInvalid(project.Kind("Project"), projectObj.Name, errs) } - if err := creationValidation(project.DeepCopyObject()); err != nil { + if err := creationValidation(projectObj.DeepCopyObject()); err != nil { return nil, err } - namespace, err := s.client.Create(projectutil.ConvertProject(project)) + namespace, err := s.client.Create(projectutil.ConvertProject(projectObj)) if err != nil { return nil, err } @@ -175,20 +176,20 @@ func (s *REST) Update(ctx context.Context, name string, objInfo rest.UpdatedObje return nil, false, err } - project, ok := obj.(*projectapi.Project) + projectObj, ok := obj.(*projectapi.Project) if !ok { return nil, false, fmt.Errorf("not a project: %#v", obj) } s.updateStrategy.PrepareForUpdate(ctx, obj, oldObj) if errs := s.updateStrategy.ValidateUpdate(ctx, obj, oldObj); len(errs) > 0 { - return nil, false, kerrors.NewInvalid(projectapi.Kind("Project"), project.Name, errs) + return nil, false, kerrors.NewInvalid(project.Kind("Project"), projectObj.Name, errs) } if err := updateValidation(obj.DeepCopyObject(), oldObj.DeepCopyObject()); err != nil { return nil, false, err } - namespace, err := s.client.Update(projectutil.ConvertProject(project)) + namespace, err := s.client.Update(projectutil.ConvertProject(projectObj)) if err != nil { return nil, false, err } diff --git a/pkg/project/registry/projectrequest/delegated/delegated.go b/pkg/project/registry/projectrequest/delegated/delegated.go index 10ace1095541..d360328c1ac5 100644 --- a/pkg/project/registry/projectrequest/delegated/delegated.go +++ b/pkg/project/registry/projectrequest/delegated/delegated.go @@ -28,6 +28,7 @@ import ( authorizationclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/authorization/internalversion" rbaclisters "k8s.io/kubernetes/pkg/client/listers/rbac/internalversion" + "github.com/openshift/api/project" projectapiv1 "github.com/openshift/api/project/v1" templatev1 "github.com/openshift/api/template/v1" templateclient "github.com/openshift/client-go/template/clientset/versioned" @@ -115,17 +116,17 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation projectRequest := obj.(*projectapi.ProjectRequest) for _, s := range ForbiddenNames { if projectRequest.Name == s { - return nil, kapierror.NewForbidden(projectapi.Resource("project"), projectRequest.Name, fmt.Errorf("cannot request a project with the name %q", s)) + return nil, kapierror.NewForbidden(project.Resource("project"), projectRequest.Name, fmt.Errorf("cannot request a project with the name %q", s)) } } for _, s := range ForbiddenPrefixes { if strings.HasPrefix(projectRequest.Name, s) { - return nil, kapierror.NewForbidden(projectapi.Resource("project"), projectRequest.Name, fmt.Errorf("cannot request a project starting with %q", s)) + return nil, kapierror.NewForbidden(project.Resource("project"), projectRequest.Name, fmt.Errorf("cannot request a project starting with %q", s)) } } if _, err := r.projectGetter.Projects().Get(projectRequest.Name, metav1.GetOptions{}); err == nil { - return nil, kapierror.NewAlreadyExists(projectapi.Resource("project"), projectRequest.Name) + return nil, kapierror.NewAlreadyExists(project.Resource("project"), projectRequest.Name) } projectName := projectRequest.Name @@ -307,7 +308,7 @@ func (r *REST) List(ctx context.Context, options *metainternal.ListOptions) (run return &metav1.Status{Status: metav1.StatusSuccess}, nil } - forbiddenError := kapierror.NewForbidden(projectapi.Resource("projectrequest"), "", errors.New("you may not request a new project via this API.")) + forbiddenError := kapierror.NewForbidden(project.Resource("projectrequest"), "", errors.New("you may not request a new project via this API.")) if len(r.message) > 0 { forbiddenError.ErrStatus.Message = r.message forbiddenError.ErrStatus.Details = &metav1.StatusDetails{ diff --git a/pkg/quota/apis/quota/install/install.go b/pkg/quota/apis/quota/install/install.go index 9ec9015ce949..fabefb86e600 100644 --- a/pkg/quota/apis/quota/install/install.go +++ b/pkg/quota/apis/quota/install/install.go @@ -5,7 +5,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/kubernetes/pkg/api/legacyscheme" - quotaapi "github.com/openshift/origin/pkg/quota/apis/quota" + quotav1 "github.com/openshift/api/quota/v1" quotaapiv1 "github.com/openshift/origin/pkg/quota/apis/quota/v1" ) @@ -15,7 +15,6 @@ func init() { // Install registers the API group and adds types to a scheme func Install(scheme *runtime.Scheme) { - utilruntime.Must(quotaapi.AddToScheme(scheme)) - utilruntime.Must(quotaapiv1.AddToScheme(scheme)) - utilruntime.Must(scheme.SetVersionPriority(quotaapiv1.SchemeGroupVersion)) + utilruntime.Must(quotaapiv1.Install(scheme)) + utilruntime.Must(scheme.SetVersionPriority(quotav1.GroupVersion)) } diff --git a/pkg/quota/apis/quota/register.go b/pkg/quota/apis/quota/register.go index 9926e016ad19..3ff26835973d 100644 --- a/pkg/quota/apis/quota/register.go +++ b/pkg/quota/apis/quota/register.go @@ -3,31 +3,28 @@ package quota import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/kubernetes/pkg/apis/core" ) const ( - GroupName = "quota.openshift.io" - LegacyGroupName = "" + GroupName = "quota.openshift.io" ) -// SchemeGroupVersion is group version used to register these objects var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: runtime.APIVersionInternal} - - LegacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme + schemeBuilder = runtime.NewSchemeBuilder( + addKnownTypes, + core.AddToScheme, + ) + Install = schemeBuilder.AddToScheme - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // DEPRECATED kept for generated code + SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} + // DEPRECATED kept for generated code + AddToScheme = schemeBuilder.AddToScheme ) -// Kind takes an unqualified kind and returns back a Group qualified GroupKind -func Kind(kind string) schema.GroupKind { - return SchemeGroupVersion.WithKind(kind).GroupKind() -} - -// Resource takes an unqualified resource and returns back a Group qualified GroupResource +// Resource kept for generated code +// DEPRECATED func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } @@ -42,14 +39,3 @@ func addKnownTypes(scheme *runtime.Scheme) error { ) return nil } - -func addLegacyKnownTypes(scheme *runtime.Scheme) error { - types := []runtime.Object{ - &ClusterResourceQuota{}, - &ClusterResourceQuotaList{}, - &AppliedClusterResourceQuota{}, - &AppliedClusterResourceQuotaList{}, - } - scheme.AddKnownTypes(LegacySchemeGroupVersion, types...) - return nil -} diff --git a/pkg/quota/apis/quota/types.go b/pkg/quota/apis/quota/types.go index c1a6d1fe44aa..fba600a805a6 100644 --- a/pkg/quota/apis/quota/types.go +++ b/pkg/quota/apis/quota/types.go @@ -6,7 +6,7 @@ import ( "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - kapi "k8s.io/kubernetes/pkg/apis/core" + "k8s.io/kubernetes/pkg/apis/core" ) // +genclient @@ -36,7 +36,7 @@ type ClusterResourceQuotaSpec struct { Selector ClusterResourceQuotaSelector // Quota defines the desired quota - Quota kapi.ResourceQuotaSpec + Quota core.ResourceQuotaSpec } // ClusterResourceQuotaSelector is used to select projects. At least one of LabelSelector or AnnotationSelector @@ -53,7 +53,7 @@ type ClusterResourceQuotaSelector struct { // ClusterResourceQuotaStatus defines the actual enforced quota and its current usage type ClusterResourceQuotaStatus struct { // Total defines the actual enforced quota and its current usage across all projects - Total kapi.ResourceQuotaStatus + Total core.ResourceQuotaStatus // Namespaces slices the usage by project. This division allows for quick resolution of // deletion reconciliation inside of a single project without requiring a recalculation @@ -109,16 +109,16 @@ type ResourceQuotasStatusByNamespace struct { orderedMap orderedMap } -func (o *ResourceQuotasStatusByNamespace) Insert(key string, value kapi.ResourceQuotaStatus) { +func (o *ResourceQuotasStatusByNamespace) Insert(key string, value core.ResourceQuotaStatus) { o.orderedMap.Insert(key, value) } -func (o *ResourceQuotasStatusByNamespace) Get(key string) (kapi.ResourceQuotaStatus, bool) { +func (o *ResourceQuotasStatusByNamespace) Get(key string) (core.ResourceQuotaStatus, bool) { ret, ok := o.orderedMap.Get(key) if !ok { - return kapi.ResourceQuotaStatus{}, ok + return core.ResourceQuotaStatus{}, ok } - return ret.(kapi.ResourceQuotaStatus), ok + return ret.(core.ResourceQuotaStatus), ok } func (o *ResourceQuotasStatusByNamespace) Remove(key string) { diff --git a/pkg/quota/apis/quota/v1/conversion.go b/pkg/quota/apis/quota/v1/conversion.go index bedb0e7c0c8b..2c7b7dc78b09 100644 --- a/pkg/quota/apis/quota/v1/conversion.go +++ b/pkg/quota/apis/quota/v1/conversion.go @@ -43,7 +43,7 @@ func Convert_quota_ResourceQuotasStatusByNamespace_To_v1_ResourceQuotasStatusByN return nil } -func addConversionFuncs(scheme *runtime.Scheme) error { +func AddConversionFuncs(scheme *runtime.Scheme) error { return scheme.AddConversionFuncs( Convert_quota_ResourceQuotasStatusByNamespace_To_v1_ResourceQuotasStatusByNamespace, Convert_v1_ResourceQuotasStatusByNamespace_To_quota_ResourceQuotasStatusByNamespace, diff --git a/pkg/quota/apis/quota/v1/defaults.go b/pkg/quota/apis/quota/v1/defaults.go deleted file mode 100644 index 515fa3667d57..000000000000 --- a/pkg/quota/apis/quota/v1/defaults.go +++ /dev/null @@ -1,8 +0,0 @@ -package v1 - -import "k8s.io/apimachinery/pkg/runtime" - -func addDefaultingFuncs(scheme *runtime.Scheme) error { - RegisterDefaults(scheme) - return nil -} diff --git a/pkg/quota/apis/quota/v1/register.go b/pkg/quota/apis/quota/v1/register.go index c3e02d83d037..93fdaf938359 100644 --- a/pkg/quota/apis/quota/v1/register.go +++ b/pkg/quota/apis/quota/v1/register.go @@ -1,36 +1,18 @@ package v1 import ( - "github.com/openshift/api/quota/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) -const ( - GroupName = "quota.openshift.io" - LegacyGroupName = "" + "github.com/openshift/api/quota/v1" + "github.com/openshift/origin/pkg/quota/apis/quota" ) -// SchemeGroupVersion is group version used to register these objects var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: "v1"} - - LegacySchemeBuilder = runtime.NewSchemeBuilder(v1.DeprecatedInstallWithoutGroup, addConversionFuncs, RegisterDefaults, RegisterConversions) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme - - SchemeBuilder = runtime.NewSchemeBuilder(v1.Install, addConversionFuncs) - AddToScheme = SchemeBuilder.AddToScheme - - localSchemeBuilder = &SchemeBuilder + localSchemeBuilder = runtime.NewSchemeBuilder( + quota.Install, + v1.Install, + AddConversionFuncs, + RegisterDefaults, + ) + Install = localSchemeBuilder.AddToScheme ) - -// Kind takes an unqualified kind and returns back a Group qualified GroupKind -func Kind(kind string) schema.GroupKind { - return SchemeGroupVersion.WithKind(kind).GroupKind() -} - -// Resource takes an unqualified resource and returns back a Group qualified GroupResource -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} diff --git a/pkg/quota/image/imagestreamimport_evaluator.go b/pkg/quota/image/imagestreamimport_evaluator.go index 929cbaa178fe..0ac719164767 100644 --- a/pkg/quota/image/imagestreamimport_evaluator.go +++ b/pkg/quota/image/imagestreamimport_evaluator.go @@ -13,6 +13,7 @@ import ( kquota "k8s.io/kubernetes/pkg/quota" "k8s.io/kubernetes/pkg/quota/generic" + "github.com/openshift/api/image" imageapi "github.com/openshift/origin/pkg/image/apis/image" imageinternalversion "github.com/openshift/origin/pkg/image/generated/listers/image/internalversion" ) @@ -43,7 +44,7 @@ func (i *imageStreamImportEvaluator) Constraints(required []kapi.ResourceName, o } func (i *imageStreamImportEvaluator) GroupResource() schema.GroupResource { - return imageapi.Resource("imagestreamimports") + return image.Resource("imagestreamimports") } func (i *imageStreamImportEvaluator) Handles(a kadmission.Attributes) bool { diff --git a/pkg/quota/image/imagestreamtag_evaluator.go b/pkg/quota/image/imagestreamtag_evaluator.go index 0ac5f23f8276..4c962313e4f8 100644 --- a/pkg/quota/image/imagestreamtag_evaluator.go +++ b/pkg/quota/image/imagestreamtag_evaluator.go @@ -13,6 +13,7 @@ import ( kquota "k8s.io/kubernetes/pkg/quota" "k8s.io/kubernetes/pkg/quota/generic" + "github.com/openshift/api/image" imageapi "github.com/openshift/origin/pkg/image/apis/image" imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset/typed/image/internalversion" imageinternalversion "github.com/openshift/origin/pkg/image/generated/listers/image/internalversion" @@ -45,7 +46,7 @@ func (i *imageStreamTagEvaluator) Constraints(required []kapi.ResourceName, obje } func (i *imageStreamTagEvaluator) GroupResource() schema.GroupResource { - return imageapi.Resource("imagestreamtags") + return image.Resource("imagestreamtags") } func (i *imageStreamTagEvaluator) Handles(a kadmission.Attributes) bool { diff --git a/pkg/quota/image/registry.go b/pkg/quota/image/registry.go index 0b0f8d43c952..74347e7b6231 100644 --- a/pkg/quota/image/registry.go +++ b/pkg/quota/image/registry.go @@ -8,13 +8,14 @@ import ( "k8s.io/kubernetes/pkg/quota" "k8s.io/kubernetes/pkg/quota/generic" + "github.com/openshift/origin/pkg/api/legacy" imageapi "github.com/openshift/origin/pkg/image/apis/image" imageinternalversion "github.com/openshift/origin/pkg/image/generated/informers/internalversion/image/internalversion" imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset/typed/image/internalversion" ) var legacyObjectCountAliases = map[schema.GroupVersionResource]kapi.ResourceName{ - imageapi.SchemeGroupVersion.WithResource("imagestreams"): imageapi.ResourceImageStreams, + imageapi.GroupVersion.WithResource("imagestreams"): imageapi.ResourceImageStreams, } // NewEvaluators returns the list of static evaluators that manage more than counts @@ -43,11 +44,11 @@ func NewReplenishmentEvaluatorsForAdmission(isInformer imageinternalversion.Imag NewImageStreamImportEvaluator(isInformer.Lister()), &evaluatorForLegacyResource{ Evaluator: NewImageStreamTagEvaluator(isInformer.Lister(), imageClient), - LegacyGroupResource: imageapi.LegacyResource("imagestreamtags"), + LegacyGroupResource: legacy.Resource("imagestreamtags"), }, &evaluatorForLegacyResource{ Evaluator: NewImageStreamImportEvaluator(isInformer.Lister()), - LegacyGroupResource: imageapi.LegacyResource("imagestreamimports"), + LegacyGroupResource: legacy.Resource("imagestreamimports"), }, } // these evaluators require an alias for backwards compatibility @@ -59,8 +60,8 @@ func NewReplenishmentEvaluatorsForAdmission(isInformer imageinternalversion.Imag result = append(result, generic.NewObjectCountEvaluator( false, - imageapi.LegacyResource("imagestreams"), - generic.ListResourceUsingListerFunc(nil, imageapi.SchemeGroupVersion.WithResource("imagestreams")), + legacy.Resource("imagestreams"), + generic.ListResourceUsingListerFunc(nil, imageapi.GroupVersion.WithResource("imagestreams")), imageapi.ResourceImageStreams)) return result diff --git a/pkg/quota/registry/appliedclusterresourcequota/filter.go b/pkg/quota/registry/appliedclusterresourcequota/filter.go index dfc57adce4da..71da621c1a57 100644 --- a/pkg/quota/registry/appliedclusterresourcequota/filter.go +++ b/pkg/quota/registry/appliedclusterresourcequota/filter.go @@ -17,6 +17,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/quota" oapi "github.com/openshift/origin/pkg/api" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" quotaapi "github.com/openshift/origin/pkg/quota/apis/quota" @@ -61,7 +62,7 @@ func (r *AppliedClusterResourceQuotaREST) Get(ctx context.Context, name string, quotaNames, _ := r.quotaMapper.GetClusterQuotasFor(namespace) quotaNamesSet := sets.NewString(quotaNames...) if !quotaNamesSet.Has(name) { - return nil, kapierrors.NewNotFound(quotaapi.Resource("appliedclusterresourcequota"), name) + return nil, kapierrors.NewNotFound(quota.Resource("appliedclusterresourcequota"), name) } clusterQuota, err := r.quotaLister.Get(name) diff --git a/pkg/quota/registry/clusterresourcequota/etcd/etcd.go b/pkg/quota/registry/clusterresourcequota/etcd/etcd.go index 6eeac2170f02..972e617573a8 100644 --- a/pkg/quota/registry/clusterresourcequota/etcd/etcd.go +++ b/pkg/quota/registry/clusterresourcequota/etcd/etcd.go @@ -11,6 +11,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/quota" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" quotaapi "github.com/openshift/origin/pkg/quota/apis/quota" "github.com/openshift/origin/pkg/quota/registry/clusterresourcequota" @@ -34,7 +35,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, *StatusREST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return "aapi.ClusterResourceQuota{} }, NewListFunc: func() runtime.Object { return "aapi.ClusterResourceQuotaList{} }, - DefaultQualifiedResource: quotaapi.Resource("clusterresourcequotas"), + DefaultQualifiedResource: quota.Resource("clusterresourcequotas"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/quota/util/helper_test.go b/pkg/quota/util/helper_test.go index 2c7c4f732ff8..f936daf0a55e 100644 --- a/pkg/quota/util/helper_test.go +++ b/pkg/quota/util/helper_test.go @@ -8,7 +8,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" kapi "k8s.io/kubernetes/pkg/apis/core" - imageapi "github.com/openshift/origin/pkg/image/apis/image" + "github.com/openshift/api/image" ) // TestIsErrorQuotaExceeded verifies that if a resource exceedes allowed usage, the admission will return @@ -37,21 +37,21 @@ func TestIsErrorQuotaExceeded(t *testing.T) { }, { name: "unrelated invalid error", - err: kerrors.NewInvalid(imageapi.Kind("imageStreams"), "is", + err: kerrors.NewInvalid(image.Kind("imageStreams"), "is", field.ErrorList{ field.Required(field.NewPath("imageStream").Child("Spec"), "detail"), }), }, { name: "quota error not recognized with invalid reason", - err: kerrors.NewInvalid(imageapi.Kind("imageStreams"), "is", + err: kerrors.NewInvalid(image.Kind("imageStreams"), "is", field.ErrorList{ field.Forbidden(field.NewPath("imageStreams"), errQuotaMessageString), }), }, { name: "quota unknown error not recognized with invalid reason", - err: kerrors.NewInvalid(imageapi.Kind("imageStreams"), "is", + err: kerrors.NewInvalid(image.Kind("imageStreams"), "is", field.ErrorList{ field.Forbidden(field.NewPath("imageStreams"), errQuotaUnknownMessageString), }), @@ -68,12 +68,12 @@ func TestIsErrorQuotaExceeded(t *testing.T) { }, { name: "limits exceeded error with forbidden reason", - err: kerrors.NewForbidden(imageapi.Resource("imageStream"), "is", errors.New(errLimitsMessageString)), + err: kerrors.NewForbidden(image.Resource("imageStream"), "is", errors.New(errLimitsMessageString)), shouldMatch: true, }, { name: "limits exceeded error with invalid reason", - err: kerrors.NewInvalid(imageapi.Kind("imageStreams"), "is", + err: kerrors.NewInvalid(image.Kind("imageStreams"), "is", field.ErrorList{ field.Forbidden(field.NewPath("imageStream"), errLimitsMessageString), }), @@ -116,21 +116,21 @@ func TestIsErrorLimitExceeded(t *testing.T) { }, { name: "unrelated invalid error", - err: kerrors.NewInvalid(imageapi.Kind("imageStreams"), "is", + err: kerrors.NewInvalid(image.Kind("imageStreams"), "is", field.ErrorList{ field.Required(field.NewPath("imageStream").Child("Spec"), "detail"), }), }, { name: "quota error not recognized with invalid reason", - err: kerrors.NewInvalid(imageapi.Kind("imageStreams"), "is", + err: kerrors.NewInvalid(image.Kind("imageStreams"), "is", field.ErrorList{ field.Forbidden(field.NewPath("imageStreams"), errQuotaMessageString), }), }, { name: "quota unknown error not recognized with invalid reason", - err: kerrors.NewInvalid(imageapi.Kind("imageStreams"), "is", + err: kerrors.NewInvalid(image.Kind("imageStreams"), "is", field.ErrorList{ field.Forbidden(field.NewPath("imageStreams"), errQuotaUnknownMessageString), }), @@ -145,12 +145,12 @@ func TestIsErrorLimitExceeded(t *testing.T) { }, { name: "limits exceeded error with forbidden reason", - err: kerrors.NewForbidden(imageapi.Resource("imageStream"), "is", errors.New(errLimitsMessageString)), + err: kerrors.NewForbidden(image.Resource("imageStream"), "is", errors.New(errLimitsMessageString)), shouldMatch: true, }, { name: "limits exceeded error with invalid reason", - err: kerrors.NewInvalid(imageapi.Kind("imageStreams"), "is", + err: kerrors.NewInvalid(image.Kind("imageStreams"), "is", field.ErrorList{ field.Forbidden(field.NewPath("imageStream"), errLimitsMessageString), }), diff --git a/pkg/route/apis/route/install/install.go b/pkg/route/apis/route/install/install.go index 212df5516153..5f366995a781 100644 --- a/pkg/route/apis/route/install/install.go +++ b/pkg/route/apis/route/install/install.go @@ -5,7 +5,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/kubernetes/pkg/api/legacyscheme" - routeapi "github.com/openshift/origin/pkg/route/apis/route" + routev1 "github.com/openshift/api/route/v1" routeapiv1 "github.com/openshift/origin/pkg/route/apis/route/v1" ) @@ -15,7 +15,6 @@ func init() { // Install registers the API group and adds types to a scheme func Install(scheme *runtime.Scheme) { - utilruntime.Must(routeapi.AddToScheme(scheme)) - utilruntime.Must(routeapiv1.AddToScheme(scheme)) - utilruntime.Must(scheme.SetVersionPriority(routeapiv1.SchemeGroupVersion)) + utilruntime.Must(routeapiv1.Install(scheme)) + utilruntime.Must(scheme.SetVersionPriority(routev1.GroupVersion)) } diff --git a/pkg/route/apis/route/register.go b/pkg/route/apis/route/register.go index 3c764dbb6546..e73d3d48af76 100644 --- a/pkg/route/apis/route/register.go +++ b/pkg/route/apis/route/register.go @@ -3,31 +3,28 @@ package route import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/kubernetes/pkg/apis/core" ) const ( - GroupName = "route.openshift.io" - LegacyGroupName = "" + GroupName = "route.openshift.io" ) -// SchemeGroupVersion is group version used to register these objects var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: runtime.APIVersionInternal} - - LegacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme + schemeBuilder = runtime.NewSchemeBuilder( + addKnownTypes, + core.AddToScheme, + ) + Install = schemeBuilder.AddToScheme - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // DEPRECATED kept for generated code + SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} + // DEPRECATED kept for generated code + AddToScheme = schemeBuilder.AddToScheme ) -// Kind takes an unqualified kind and returns back a Group qualified GroupKind -func Kind(kind string) schema.GroupKind { - return SchemeGroupVersion.WithKind(kind).GroupKind() -} - -// Resource takes an unqualified resource and returns back a Group qualified GroupResource +// Resource kept for generated code +// DEPRECATED func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } @@ -40,12 +37,3 @@ func addKnownTypes(scheme *runtime.Scheme) error { ) return nil } - -func addLegacyKnownTypes(scheme *runtime.Scheme) error { - types := []runtime.Object{ - &Route{}, - &RouteList{}, - } - scheme.AddKnownTypes(LegacySchemeGroupVersion, types...) - return nil -} diff --git a/pkg/route/apis/route/types.go b/pkg/route/apis/route/types.go index ca5a3ccea28e..8772a8d873c5 100644 --- a/pkg/route/apis/route/types.go +++ b/pkg/route/apis/route/types.go @@ -3,7 +3,7 @@ package route import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - kapi "k8s.io/kubernetes/pkg/apis/core" + "k8s.io/kubernetes/pkg/apis/core" ) // +genclient @@ -108,7 +108,7 @@ type RouteIngressCondition struct { Type RouteIngressConditionType // Status is the status of the condition. // Can be True, False, Unknown. - Status kapi.ConditionStatus + Status core.ConditionStatus // (brief) reason for the condition's last transition, and is usually a machine and human // readable constant Reason string diff --git a/pkg/route/apis/route/v1/conversion.go b/pkg/route/apis/route/v1/conversion.go index 854d599f77c6..481a01f47bc9 100644 --- a/pkg/route/apis/route/v1/conversion.go +++ b/pkg/route/apis/route/v1/conversion.go @@ -1,18 +1,12 @@ package v1 import ( + v1 "github.com/openshift/api/route/v1" "k8s.io/apimachinery/pkg/runtime" ) -func addLegacyFieldSelectorKeyConversions(scheme *runtime.Scheme) error { - if err := scheme.AddFieldLabelConversionFunc(LegacySchemeGroupVersion.String(), "Route", legacyRouteFieldSelectorKeyConversionFunc); err != nil { - return err - } - return nil -} - func addFieldSelectorKeyConversions(scheme *runtime.Scheme) error { - if err := scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.String(), "Route", routeFieldSelectorKeyConversionFunc); err != nil { + if err := scheme.AddFieldLabelConversionFunc(v1.GroupVersion.String(), "Route", routeFieldSelectorKeyConversionFunc); err != nil { return err } return nil @@ -21,17 +15,6 @@ func addFieldSelectorKeyConversions(scheme *runtime.Scheme) error { // 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 legacyRouteFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { - switch label { - case "spec.path", - "spec.host", - "spec.to.name": - return label, value, nil - default: - return runtime.DefaultMetaV1FieldSelectorConversion(label, value) - } -} - func routeFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { switch label { case "spec.path", diff --git a/pkg/route/apis/route/v1/conversion_test.go b/pkg/route/apis/route/v1/conversion_test.go index 453a9696b784..42f6af4e4ebc 100644 --- a/pkg/route/apis/route/v1/conversion_test.go +++ b/pkg/route/apis/route/v1/conversion_test.go @@ -5,6 +5,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" + "github.com/davecgh/go-spew/spew" v1 "github.com/openshift/api/route/v1" "github.com/openshift/origin/pkg/api/apihelpers/apitesting" "github.com/openshift/origin/pkg/route/apis/route" @@ -12,16 +13,8 @@ import ( func TestFieldSelectorConversions(t *testing.T) { apitesting.FieldKeyCheck{ - SchemeBuilder: []func(*runtime.Scheme) error{LegacySchemeBuilder.AddToScheme, route.LegacySchemeBuilder.AddToScheme}, - Kind: LegacySchemeGroupVersion.WithKind("Route"), - // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST - AllowedExternalFieldKeys: []string{"spec.host", "spec.path", "spec.to.name"}, - FieldKeyEvaluatorFn: route.RouteFieldSelector, - }.Check(t) - - apitesting.FieldKeyCheck{ - SchemeBuilder: []func(*runtime.Scheme) error{SchemeBuilder.AddToScheme, route.SchemeBuilder.AddToScheme}, - Kind: SchemeGroupVersion.WithKind("Route"), + SchemeBuilder: []func(*runtime.Scheme) error{Install}, + Kind: v1.GroupVersion.WithKind("Route"), // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST AllowedExternalFieldKeys: []string{"spec.host", "spec.path", "spec.to.name"}, FieldKeyEvaluatorFn: route.RouteFieldSelector, @@ -30,7 +23,7 @@ func TestFieldSelectorConversions(t *testing.T) { func TestSupportingCamelConstants(t *testing.T) { scheme := runtime.NewScheme() - LegacySchemeBuilder.AddToScheme(scheme) + Install(scheme) for k, v := range map[v1.TLSTerminationType]v1.TLSTerminationType{ "Reencrypt": v1.TLSTerminationReencrypt, @@ -44,7 +37,7 @@ func TestSupportingCamelConstants(t *testing.T) { } scheme.Default(obj) if obj.Spec.TLS.Termination != v { - t.Errorf("%s: did not default termination: %#v", k, obj) + t.Errorf("%s: did not default termination: %#v", k, spew.Sdump(obj)) } } } diff --git a/pkg/route/apis/route/v1/defaults_test.go b/pkg/route/apis/route/v1/defaults_test.go index 89d605baf4f9..02a4d67b51dd 100644 --- a/pkg/route/apis/route/v1/defaults_test.go +++ b/pkg/route/apis/route/v1/defaults_test.go @@ -7,16 +7,15 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer" + "github.com/davecgh/go-spew/spew" v1 "github.com/openshift/api/route/v1" - "github.com/openshift/origin/pkg/route/apis/route" ) var scheme = runtime.NewScheme() var codecs = serializer.NewCodecFactory(scheme) func init() { - SchemeBuilder.AddToScheme(scheme) - route.SchemeBuilder.AddToScheme(scheme) + Install(scheme) } func TestDefaults(t *testing.T) { @@ -38,7 +37,7 @@ func TestDefaults(t *testing.T) { } if out.Spec.TLS.Termination != v1.TLSTerminationEdge { - t.Errorf("did not default termination: %#v", out) + t.Errorf("did not default termination: %#v", spew.Sdump(out.Spec.TLS)) } if out.Spec.WildcardPolicy != v1.WildcardPolicyNone { t.Errorf("did not default wildcard policy: %#v", out) @@ -52,7 +51,7 @@ func TestDefaults(t *testing.T) { } func roundTrip(t *testing.T, obj runtime.Object) runtime.Object { - data, err := runtime.Encode(codecs.LegacyCodec(SchemeGroupVersion), obj) + data, err := runtime.Encode(codecs.LegacyCodec(v1.GroupVersion), obj) if err != nil { t.Errorf("%v\n %#v", err, obj) return nil diff --git a/pkg/route/apis/route/v1/register.go b/pkg/route/apis/route/v1/register.go index 1b60a26698d8..863132d867a3 100644 --- a/pkg/route/apis/route/v1/register.go +++ b/pkg/route/apis/route/v1/register.go @@ -1,30 +1,21 @@ package v1 import ( - "github.com/openshift/api/route/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) + corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1" -const ( - GroupName = "route.openshift.io" - LegacyGroupName = "" + "github.com/openshift/api/route/v1" + "github.com/openshift/origin/pkg/route/apis/route" ) -// SchemeGroupVersion is group version used to register these objects var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: "v1"} + localSchemeBuilder = runtime.NewSchemeBuilder( + route.Install, + v1.Install, + corev1conversions.AddToScheme, - LegacySchemeBuilder = runtime.NewSchemeBuilder(v1.DeprecatedInstallWithoutGroup, addLegacyFieldSelectorKeyConversions, RegisterDefaults, RegisterConversions) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme - - SchemeBuilder = runtime.NewSchemeBuilder(v1.Install, addFieldSelectorKeyConversions, RegisterDefaults) - AddToScheme = SchemeBuilder.AddToScheme - - localSchemeBuilder = &SchemeBuilder + addFieldSelectorKeyConversions, + RegisterDefaults, + ) + Install = localSchemeBuilder.AddToScheme ) - -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} diff --git a/pkg/route/registry/route/etcd/etcd.go b/pkg/route/registry/route/etcd/etcd.go index 4d6ad16df5e0..9e23fcdc0bf0 100644 --- a/pkg/route/registry/route/etcd/etcd.go +++ b/pkg/route/registry/route/etcd/etcd.go @@ -13,6 +13,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + routegroup "github.com/openshift/api/route" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" "github.com/openshift/origin/pkg/route" routeapi "github.com/openshift/origin/pkg/route/apis/route" @@ -39,7 +40,7 @@ func NewREST(optsGetter restoptions.Getter, allocator route.RouteAllocator, sarC store := ®istry.Store{ NewFunc: func() runtime.Object { return &routeapi.Route{} }, NewListFunc: func() runtime.Object { return &routeapi.RouteList{} }, - DefaultQualifiedResource: routeapi.Resource("routes"), + DefaultQualifiedResource: routegroup.Resource("routes"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/router/controller/status_test.go b/pkg/router/controller/status_test.go index 647a01ee2fb9..259fbe4e48d7 100644 --- a/pkg/router/controller/status_test.go +++ b/pkg/router/controller/status_test.go @@ -16,6 +16,7 @@ import ( "k8s.io/client-go/tools/cache" kapi "k8s.io/kubernetes/pkg/apis/core" + "github.com/openshift/api/route" routeapi "github.com/openshift/origin/pkg/route/apis/route" "github.com/openshift/origin/pkg/route/generated/internalclientset/fake" routelisters "github.com/openshift/origin/pkg/route/generated/listers/route/internalversion" @@ -102,7 +103,7 @@ func (l routeNamespaceLister) Get(name string) (*routeapi.Route, error) { return item, nil } } - return nil, errors.NewNotFound(routeapi.Resource("route"), name) + return nil, errors.NewNotFound(route.Resource("route"), name) } type recorded struct { diff --git a/pkg/scheduler/admission/podnodeconstraints/admission_test.go b/pkg/scheduler/admission/podnodeconstraints/admission_test.go index 3bad4b7c39b4..7901318bbf20 100644 --- a/pkg/scheduler/admission/podnodeconstraints/admission_test.go +++ b/pkg/scheduler/admission/podnodeconstraints/admission_test.go @@ -19,6 +19,7 @@ import ( "k8s.io/kubernetes/pkg/serviceaccount" oapps "github.com/openshift/api/apps" + "github.com/openshift/api/security" _ "github.com/openshift/origin/pkg/api/install" appsapi "github.com/openshift/origin/pkg/apps/apis/apps" authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization" @@ -238,20 +239,20 @@ func TestPodNodeConstraintsResources(t *testing.T) { }, { resource: podSecurityPolicySubjectReview, - kind: securityapi.Kind("PodSecurityPolicySubjectReview"), - groupresource: securityapi.Resource("podsecuritypolicysubjectreviews"), + kind: security.Kind("PodSecurityPolicySubjectReview"), + groupresource: security.Resource("podsecuritypolicysubjectreviews"), prefix: "PodSecurityPolicy", }, { resource: podSecurityPolicySelfSubjectReview, - kind: securityapi.Kind("PodSecurityPolicySelfSubjectReview"), - groupresource: securityapi.Resource("podsecuritypolicyselfsubjectreviews"), + kind: security.Kind("PodSecurityPolicySelfSubjectReview"), + groupresource: security.Resource("podsecuritypolicyselfsubjectreviews"), prefix: "PodSecurityPolicy", }, { resource: podSecurityPolicyReview, - kind: securityapi.Kind("PodSecurityPolicyReview"), - groupresource: securityapi.Resource("podsecuritypolicyreviews"), + kind: security.Kind("PodSecurityPolicyReview"), + groupresource: security.Resource("podsecuritypolicyreviews"), prefix: "PodSecurityPolicy", }, } diff --git a/pkg/security/apis/security/install/install.go b/pkg/security/apis/security/install/install.go index 72f1bd01c23c..9937d397ecee 100644 --- a/pkg/security/apis/security/install/install.go +++ b/pkg/security/apis/security/install/install.go @@ -5,7 +5,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/kubernetes/pkg/api/legacyscheme" - securityapi "github.com/openshift/origin/pkg/security/apis/security" + securityv1 "github.com/openshift/api/security/v1" securityapiv1 "github.com/openshift/origin/pkg/security/apis/security/v1" ) @@ -15,7 +15,6 @@ func init() { // Install registers the API group and adds types to a scheme func Install(scheme *runtime.Scheme) { - utilruntime.Must(securityapi.AddToScheme(scheme)) - utilruntime.Must(securityapiv1.AddToScheme(scheme)) - utilruntime.Must(scheme.SetVersionPriority(securityapiv1.SchemeGroupVersion)) + utilruntime.Must(securityapiv1.Install(scheme)) + utilruntime.Must(scheme.SetVersionPriority(securityv1.GroupVersion)) } diff --git a/pkg/security/apis/security/register.go b/pkg/security/apis/security/register.go index f017cb2bda28..8ccb0fdc1134 100644 --- a/pkg/security/apis/security/register.go +++ b/pkg/security/apis/security/register.go @@ -3,31 +3,28 @@ package security import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/kubernetes/pkg/apis/core" ) const ( - GroupName = "security.openshift.io" - LegacyGroupName = "" + GroupName = "security.openshift.io" ) -// SchemeGroupVersion is group version used to register these objects var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: runtime.APIVersionInternal} - - LegacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme + schemeBuilder = runtime.NewSchemeBuilder( + addKnownTypes, + core.AddToScheme, + ) + Install = schemeBuilder.AddToScheme - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // DEPRECATED kept for generated code + SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} + // DEPRECATED kept for generated code + AddToScheme = schemeBuilder.AddToScheme ) -// Kind takes an unqualified kind and returns back a Group qualified GroupKind -func Kind(kind string) schema.GroupKind { - return SchemeGroupVersion.WithKind(kind).GroupKind() -} - -// Resource takes an unqualified resource and returns back a Group qualified GroupResource +// Resource kept for generated code +// DEPRECATED func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } @@ -45,15 +42,3 @@ func addKnownTypes(scheme *runtime.Scheme) error { ) return nil } - -func addLegacyKnownTypes(scheme *runtime.Scheme) error { - types := []runtime.Object{ - &SecurityContextConstraints{}, - &SecurityContextConstraintsList{}, - &PodSecurityPolicySubjectReview{}, - &PodSecurityPolicySelfSubjectReview{}, - &PodSecurityPolicyReview{}, - } - scheme.AddKnownTypes(LegacySchemeGroupVersion, types...) - return nil -} diff --git a/pkg/security/apis/security/types.go b/pkg/security/apis/security/types.go index 8bc90ddff238..c7ce11691b9e 100644 --- a/pkg/security/apis/security/types.go +++ b/pkg/security/apis/security/types.go @@ -2,13 +2,13 @@ package security import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - kapi "k8s.io/kubernetes/pkg/apis/core" + "k8s.io/kubernetes/pkg/apis/core" ) // AllowAllCapabilities can be used as a value for the // SecurityContextConstraints.AllowAllCapabilities field and means that any // capabilities are allowed to be requested. -var AllowAllCapabilities kapi.Capability = "*" +var AllowAllCapabilities core.Capability = "*" // +genclient // +genclient:nonNamespaced @@ -33,15 +33,15 @@ type SecurityContextConstraints struct { // DefaultAddCapabilities is the default set of capabilities that will be added to the container // unless the pod spec specifically drops the capability. You may not list a capabiility in both // DefaultAddCapabilities and RequiredDropCapabilities. - DefaultAddCapabilities []kapi.Capability + DefaultAddCapabilities []core.Capability // RequiredDropCapabilities are the capabilities that will be dropped from the container. These // are required to be dropped and cannot be added. - RequiredDropCapabilities []kapi.Capability + RequiredDropCapabilities []core.Capability // AllowedCapabilities is a list of capabilities that can be requested to add to the container. // Capabilities in this field maybe added at the pod author's discretion. // You must not list a capability in both AllowedCapabilities and RequiredDropCapabilities. // To allow all capabilities you may use '*'. - AllowedCapabilities []kapi.Capability + AllowedCapabilities []core.Capability // Volumes is a white list of allowed volume plugins. FSType corresponds directly with the field names // of a VolumeSource (azureFile, configMap, emptyDir). To allow all volumes you may use "*". // To allow no volumes, set to ["none"]. @@ -140,7 +140,7 @@ type SELinuxContextStrategyOptions struct { // Type is the strategy that will dictate what SELinux context is used in the SecurityContext. Type SELinuxContextStrategyType // seLinuxOptions required to run as; required for MustRunAs - SELinuxOptions *kapi.SELinuxOptions + SELinuxOptions *core.SELinuxOptions } // RunAsUserStrategyOptions defines the strategy type and any options used to create the strategy. @@ -254,7 +254,7 @@ type PodSecurityPolicySubjectReview struct { type PodSecurityPolicySubjectReviewSpec struct { // Template is the PodTemplateSpec to check. If PodTemplateSpec.Spec.ServiceAccountName is empty it will not be defaulted. // If its non-empty, it will be checked. - Template kapi.PodTemplateSpec + Template core.PodTemplateSpec // User is the user you're testing for. // If you specify "User" but not "Group", then is it interpreted as "What if User were not a member of any groups. @@ -270,7 +270,7 @@ type PodSecurityPolicySubjectReviewStatus struct { // AllowedBy is a reference to the rule that allows the PodTemplateSpec. // A rule can be a SecurityContextConstraint or a PodSecurityPolicy // A `nil`, indicates that it was denied. - AllowedBy *kapi.ObjectReference + AllowedBy *core.ObjectReference // A machine-readable description of why this operation is in the // "Failure" status. If this value is empty there @@ -278,7 +278,7 @@ type PodSecurityPolicySubjectReviewStatus struct { Reason string // Template is the PodTemplateSpec after the defaulting is applied. - Template kapi.PodTemplateSpec + Template core.PodTemplateSpec } // +genclient @@ -299,7 +299,7 @@ type PodSecurityPolicySelfSubjectReview struct { // PodSecurityPolicySelfSubjectReviewSpec contains specification for PodSecurityPolicySelfSubjectReview. type PodSecurityPolicySelfSubjectReviewSpec struct { // Template is the PodTemplateSpec to check. - Template kapi.PodTemplateSpec + Template core.PodTemplateSpec } // +genclient @@ -323,7 +323,7 @@ type PodSecurityPolicyReviewSpec struct { // if ServiceAccountNames is empty, unless the PodTemplateSpec.Spec.ServiceAccountName is empty, // in which case "default" is used. // If ServiceAccountNames is specified, PodTemplateSpec.Spec.ServiceAccountName is ignored. - Template kapi.PodTemplateSpec + Template core.PodTemplateSpec // ServiceAccountNames is an optional set of ServiceAccounts to run the check with. // If ServiceAccountNames is empty, the PodTemplateSpec.Spec.ServiceAccountName is used, diff --git a/pkg/security/apis/security/v1/conversion.go b/pkg/security/apis/security/v1/conversion.go index 40cff3b627e9..dbb774795019 100644 --- a/pkg/security/apis/security/v1/conversion.go +++ b/pkg/security/apis/security/v1/conversion.go @@ -8,7 +8,7 @@ import ( securityapi "github.com/openshift/origin/pkg/security/apis/security" ) -func addConversionFuncs(scheme *runtime.Scheme) error { +func AddConversionFuncs(scheme *runtime.Scheme) error { err := scheme.AddConversionFuncs( Convert_v1_SecurityContextConstraints_To_security_SecurityContextConstraints, Convert_security_SecurityContextConstraints_To_v1_SecurityContextConstraints, diff --git a/pkg/security/apis/security/v1/defaults.go b/pkg/security/apis/security/v1/defaults.go index 266ac78ef342..00760ab5047f 100644 --- a/pkg/security/apis/security/v1/defaults.go +++ b/pkg/security/apis/security/v1/defaults.go @@ -8,7 +8,7 @@ import ( sccutil "github.com/openshift/origin/pkg/security/securitycontextconstraints/util" ) -func addDefaultingFuncs(scheme *runtime.Scheme) error { +func AddDefaultingFuncs(scheme *runtime.Scheme) error { RegisterDefaults(scheme) scheme.AddTypeDefaultingFunc(&v1.SecurityContextConstraints{}, func(obj interface{}) { SetDefaults_SCC(obj.(*v1.SecurityContextConstraints)) }) return nil diff --git a/pkg/security/apis/security/v1/register.go b/pkg/security/apis/security/v1/register.go index d68e680fa6d1..3205a36706e7 100644 --- a/pkg/security/apis/security/v1/register.go +++ b/pkg/security/apis/security/v1/register.go @@ -1,30 +1,22 @@ package v1 import ( - "github.com/openshift/api/security/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) + corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1" -const ( - GroupName = "security.openshift.io" - LegacyGroupName = "" + "github.com/openshift/api/security/v1" + "github.com/openshift/origin/pkg/security/apis/security" ) -// SchemeGroupVersion is group version used to register these objects var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: "v1"} + localSchemeBuilder = runtime.NewSchemeBuilder( + security.Install, + v1.Install, + corev1conversions.AddToScheme, - LegacySchemeBuilder = runtime.NewSchemeBuilder(v1.DeprecatedInstallWithoutGroup, addConversionFuncs, addDefaultingFuncs, RegisterDefaults, RegisterConversions) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme - - SchemeBuilder = runtime.NewSchemeBuilder(v1.Install, addConversionFuncs, addDefaultingFuncs) - AddToScheme = SchemeBuilder.AddToScheme - - localSchemeBuilder = &SchemeBuilder + AddConversionFuncs, + AddDefaultingFuncs, + RegisterDefaults, + ) + Install = localSchemeBuilder.AddToScheme ) - -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} diff --git a/pkg/security/registry/rangeallocations/etcd.go b/pkg/security/registry/rangeallocations/etcd.go index 02731911a3b4..f7d9b6efa4e3 100644 --- a/pkg/security/registry/rangeallocations/etcd.go +++ b/pkg/security/registry/rangeallocations/etcd.go @@ -8,6 +8,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/security" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" securityapi "github.com/openshift/origin/pkg/security/apis/security" ) @@ -22,7 +23,7 @@ func NewREST(optsGetter generic.RESTOptionsGetter) *REST { store := &genericregistry.Store{ NewFunc: func() runtime.Object { return &securityapi.RangeAllocation{} }, NewListFunc: func() runtime.Object { return &securityapi.RangeAllocationList{} }, - DefaultQualifiedResource: securityapi.Resource("rangeallocations"), + DefaultQualifiedResource: security.Resource("rangeallocations"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/security/registry/securitycontextconstraints/etcd/etcd.go b/pkg/security/registry/securitycontextconstraints/etcd/etcd.go index ebcda86673ba..8930796e3334 100644 --- a/pkg/security/registry/securitycontextconstraints/etcd/etcd.go +++ b/pkg/security/registry/securitycontextconstraints/etcd/etcd.go @@ -8,6 +8,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/security" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" securityapi "github.com/openshift/origin/pkg/security/apis/security" "github.com/openshift/origin/pkg/security/registry/securitycontextconstraints" @@ -35,7 +36,7 @@ func NewREST(optsGetter generic.RESTOptionsGetter) *REST { return obj.(*securityapi.SecurityContextConstraints).Name, nil }, PredicateFunc: securitycontextconstraints.Matcher, - DefaultQualifiedResource: securityapi.Resource("securitycontextconstraints"), + DefaultQualifiedResource: security.Resource("securitycontextconstraints"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/security/securitycontextconstraints/matcher.go b/pkg/security/securitycontextconstraints/matcher.go index 16805ad8dde4..22087a28c980 100644 --- a/pkg/security/securitycontextconstraints/matcher.go +++ b/pkg/security/securitycontextconstraints/matcher.go @@ -15,6 +15,7 @@ import ( kapi "k8s.io/kubernetes/pkg/apis/core" clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" + "github.com/openshift/api/security" allocator "github.com/openshift/origin/pkg/security" securityapi "github.com/openshift/origin/pkg/security/apis/security" securitylisters "github.com/openshift/origin/pkg/security/generated/listers/security/internalversion" @@ -57,7 +58,7 @@ func authorizedForSCC(constraint *securityapi.SecurityContextConstraints, info u Verb: "use", Namespace: namespace, Name: constraint.Name, - APIGroup: securityapi.GroupName, + APIGroup: security.GroupName, Resource: "securitycontextconstraints", ResourceRequest: true, } diff --git a/pkg/template/apis/template/install/install.go b/pkg/template/apis/template/install/install.go index 31ac503eeb06..8c0cabc06b6a 100644 --- a/pkg/template/apis/template/install/install.go +++ b/pkg/template/apis/template/install/install.go @@ -5,7 +5,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/kubernetes/pkg/api/legacyscheme" - templateapi "github.com/openshift/origin/pkg/template/apis/template" + templatev1 "github.com/openshift/api/template/v1" templateapiv1 "github.com/openshift/origin/pkg/template/apis/template/v1" ) @@ -15,7 +15,6 @@ func init() { // Install registers the API group and adds types to a scheme func Install(scheme *runtime.Scheme) { - utilruntime.Must(templateapi.AddToScheme(scheme)) - utilruntime.Must(templateapiv1.AddToScheme(scheme)) - utilruntime.Must(scheme.SetVersionPriority(templateapiv1.SchemeGroupVersion)) + utilruntime.Must(templateapiv1.Install(scheme)) + utilruntime.Must(scheme.SetVersionPriority(templatev1.GroupVersion)) } diff --git a/pkg/template/apis/template/register.go b/pkg/template/apis/template/register.go index 11da3786d042..3b80af1045a2 100644 --- a/pkg/template/apis/template/register.go +++ b/pkg/template/apis/template/register.go @@ -3,31 +3,28 @@ package template import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/kubernetes/pkg/apis/core" ) const ( - GroupName = "template.openshift.io" - LegacyGroupName = "" + GroupName = "template.openshift.io" ) -// SchemeGroupVersion is group version used to register these objects var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: runtime.APIVersionInternal} - - LegacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme + schemeBuilder = runtime.NewSchemeBuilder( + addKnownTypes, + core.AddToScheme, + ) + Install = schemeBuilder.AddToScheme - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // DEPRECATED kept for generated code + SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} + // DEPRECATED kept for generated code + AddToScheme = schemeBuilder.AddToScheme ) -// Kind takes an unqualified kind and returns back a Group qualified GroupKind -func Kind(kind string) schema.GroupKind { - return SchemeGroupVersion.WithKind(kind).GroupKind() -} - -// Resource takes an unqualified resource and returns back a Group qualified GroupResource +// Resource kept for generated code +// DEPRECATED func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } @@ -44,14 +41,3 @@ func addKnownTypes(scheme *runtime.Scheme) error { ) return nil } - -func addLegacyKnownTypes(scheme *runtime.Scheme) error { - types := []runtime.Object{ - &Template{}, - &TemplateList{}, - } - scheme.AddKnownTypes(LegacySchemeGroupVersion, types...) - scheme.AddKnownTypeWithName(LegacySchemeGroupVersion.WithKind("TemplateConfig"), &Template{}) - scheme.AddKnownTypeWithName(LegacySchemeGroupVersion.WithKind("ProcessedTemplate"), &Template{}) - return nil -} diff --git a/pkg/template/apis/template/types.go b/pkg/template/apis/template/types.go index f5251d02c3a2..cba224a48ad5 100644 --- a/pkg/template/apis/template/types.go +++ b/pkg/template/apis/template/types.go @@ -3,7 +3,7 @@ package template import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - kapi "k8s.io/kubernetes/pkg/apis/core" + "k8s.io/kubernetes/pkg/apis/core" ) // +genclient @@ -102,7 +102,7 @@ type TemplateInstanceSpec struct { // Secret is a reference to a Secret object containing the necessary // template parameters. - Secret *kapi.LocalObjectReference + Secret *core.LocalObjectReference // Requester holds the identity of the agent requesting the template // instantiation. @@ -146,7 +146,7 @@ type TemplateInstanceCondition struct { // Type of the condition, currently Ready or InstantiateFailure. Type TemplateInstanceConditionType // Status of the condition, one of True, False or Unknown. - Status kapi.ConditionStatus + Status core.ConditionStatus // LastTransitionTime is the last time a condition status transitioned from // one state to another. LastTransitionTime metav1.Time @@ -174,7 +174,7 @@ const ( // TemplateInstanceObject references an object created by a TemplateInstance. type TemplateInstanceObject struct { // ref is a reference to the created object. - Ref kapi.ObjectReference + Ref core.ObjectReference } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object @@ -206,11 +206,11 @@ type BrokerTemplateInstance struct { type BrokerTemplateInstanceSpec struct { // TemplateInstance is a reference to a TemplateInstance object residing // in a namespace. - TemplateInstance kapi.ObjectReference + TemplateInstance core.ObjectReference // Secret is a reference to a Secret object residing in a namespace, // containing the necessary template parameters. - Secret kapi.ObjectReference + Secret core.ObjectReference // BindingIDs is a list of 'binding_id's provided during successive bind // calls to the template service broker. diff --git a/pkg/template/apis/template/v1/register.go b/pkg/template/apis/template/v1/register.go index a442b74323ec..63ba95d1b920 100644 --- a/pkg/template/apis/template/v1/register.go +++ b/pkg/template/apis/template/v1/register.go @@ -1,30 +1,20 @@ package v1 import ( - "github.com/openshift/api/template/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) + corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1" -const ( - GroupName = "template.openshift.io" - LegacyGroupName = "" + "github.com/openshift/api/template/v1" + "github.com/openshift/origin/pkg/template/apis/template" ) -// SchemeGroupVersion is group version used to register these objects var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: "v1"} + localSchemeBuilder = runtime.NewSchemeBuilder( + template.Install, + v1.Install, + corev1conversions.AddToScheme, - LegacySchemeBuilder = runtime.NewSchemeBuilder(v1.DeprecatedInstallWithoutGroup, RegisterDefaults, RegisterConversions) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme - - SchemeBuilder = runtime.NewSchemeBuilder(v1.Install) - AddToScheme = SchemeBuilder.AddToScheme - - localSchemeBuilder = &SchemeBuilder + RegisterDefaults, + ) + Install = localSchemeBuilder.AddToScheme ) - -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} diff --git a/pkg/template/controller/readiness.go b/pkg/template/controller/readiness.go index b9f21b7b7d1d..294e4215a334 100644 --- a/pkg/template/controller/readiness.go +++ b/pkg/template/controller/readiness.go @@ -15,6 +15,9 @@ import ( deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util" oapps "github.com/openshift/api/apps" + "github.com/openshift/api/build" + "github.com/openshift/api/route" + "github.com/openshift/origin/pkg/api/legacy" appsapi "github.com/openshift/origin/pkg/apps/apis/apps" buildapi "github.com/openshift/origin/pkg/build/apis/build" buildclient "github.com/openshift/origin/pkg/build/generated/internalclientset" @@ -149,22 +152,22 @@ func checkRouteReadiness(obj runtime.Object) (bool, bool, error) { // readinessCheckers maps GroupKinds to the appropriate function. Note that in // some cases more than one GK maps to the same function. var readinessCheckers = map[schema.GroupKind]func(runtime.Object) (bool, bool, error){ - buildapi.Kind("Build"): checkBuildReadiness, - apps.Kind("Deployment"): checkDeploymentReadiness, - extensions.Kind("Deployment"): checkDeploymentReadiness, - oapps.Kind("DeploymentConfig"): checkDeploymentConfigReadiness, - batch.Kind("Job"): checkJobReadiness, - apps.Kind("StatefulSet"): checkStatefulSetReadiness, - routeapi.Kind("Route"): checkRouteReadiness, - {Group: "", Kind: "Build"}: checkBuildReadiness, - {Group: "", Kind: "DeploymentConfig"}: checkDeploymentConfigReadiness, - {Group: "", Kind: "Route"}: checkRouteReadiness, + build.Kind("Build"): checkBuildReadiness, + apps.Kind("Deployment"): checkDeploymentReadiness, + extensions.Kind("Deployment"): checkDeploymentReadiness, + oapps.Kind("DeploymentConfig"): checkDeploymentConfigReadiness, + batch.Kind("Job"): checkJobReadiness, + apps.Kind("StatefulSet"): checkStatefulSetReadiness, + route.Kind("Route"): checkRouteReadiness, + legacy.Kind("Build"): checkBuildReadiness, + legacy.Kind("DeploymentConfig"): checkDeploymentConfigReadiness, + legacy.Kind("Route"): checkRouteReadiness, } // CanCheckReadiness indicates whether a readiness check exists for a GK. func CanCheckReadiness(ref kapi.ObjectReference) bool { switch ref.GroupVersionKind().GroupKind() { - case buildapi.Kind("BuildConfig"), schema.GroupKind{Group: "", Kind: "BuildConfig"}: + case build.Kind("BuildConfig"), schema.GroupKind{Group: "", Kind: "BuildConfig"}: return true } _, found := readinessCheckers[ref.GroupVersionKind().GroupKind()] @@ -191,7 +194,7 @@ func CheckReadiness(oc buildclient.Interface, ref kapi.ObjectReference, obj *uns } switch ref.GroupVersionKind().GroupKind() { - case buildapi.Kind("BuildConfig"), schema.GroupKind{Group: "", Kind: "BuildConfig"}: + case build.Kind("BuildConfig"), schema.GroupKind{Group: "", Kind: "BuildConfig"}: return checkBuildConfigReadiness(oc, internalObj) } return readinessCheckers[ref.GroupVersionKind().GroupKind()](internalObj) diff --git a/pkg/template/controller/readiness_test.go b/pkg/template/controller/readiness_test.go index 7d34e6ee1072..3328acab1638 100644 --- a/pkg/template/controller/readiness_test.go +++ b/pkg/template/controller/readiness_test.go @@ -16,11 +16,13 @@ import ( deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util" oapps "github.com/openshift/api/apps" + "github.com/openshift/api/build" appsapi "github.com/openshift/origin/pkg/apps/apis/apps" buildapi "github.com/openshift/origin/pkg/build/apis/build" fakebuild "github.com/openshift/origin/pkg/build/generated/internalclientset/fake" routeapi "github.com/openshift/origin/pkg/route/apis/route" + "github.com/openshift/api/route" _ "github.com/openshift/origin/pkg/apps/apis/apps/install" _ "github.com/openshift/origin/pkg/route/apis/route/install" ) @@ -37,7 +39,7 @@ func TestCheckReadiness(t *testing.T) { }{ // Build { - groupKind: buildapi.Kind("Build"), + groupKind: build.Kind("Build"), object: &buildapi.Build{ Status: buildapi.BuildStatus{ Phase: buildapi.BuildPhaseNew, @@ -45,7 +47,7 @@ func TestCheckReadiness(t *testing.T) { }, }, { - groupKind: buildapi.Kind("Build"), + groupKind: build.Kind("Build"), object: &buildapi.Build{ Status: buildapi.BuildStatus{ Phase: buildapi.BuildPhaseComplete, @@ -54,7 +56,7 @@ func TestCheckReadiness(t *testing.T) { expectedReady: true, }, { - groupKind: buildapi.Kind("Build"), + groupKind: build.Kind("Build"), object: &buildapi.Build{ Status: buildapi.BuildStatus{ Phase: buildapi.BuildPhaseError, @@ -65,11 +67,11 @@ func TestCheckReadiness(t *testing.T) { // BuildConfig { - groupKind: buildapi.Kind("BuildConfig"), + groupKind: build.Kind("BuildConfig"), object: &buildapi.BuildConfig{}, }, { - groupKind: buildapi.Kind("BuildConfig"), + groupKind: build.Kind("BuildConfig"), object: &buildapi.BuildConfig{ Status: buildapi.BuildConfigStatus{ LastVersion: 1, @@ -91,7 +93,7 @@ func TestCheckReadiness(t *testing.T) { expectedReady: true, }, { - groupKind: buildapi.Kind("BuildConfig"), + groupKind: build.Kind("BuildConfig"), object: &buildapi.BuildConfig{ Status: buildapi.BuildConfigStatus{ LastVersion: 1, @@ -238,7 +240,7 @@ func TestCheckReadiness(t *testing.T) { expectedReady: true, }, { - groupKind: routeapi.Kind("Route"), + groupKind: route.Kind("Route"), object: &routeapi.Route{ Spec: routeapi.RouteSpec{ Host: "", @@ -247,7 +249,7 @@ func TestCheckReadiness(t *testing.T) { expectedReady: false, }, { - groupKind: routeapi.Kind("Route"), + groupKind: route.Kind("Route"), object: &routeapi.Route{ Spec: routeapi.RouteSpec{ Host: "app.example.com", @@ -256,7 +258,7 @@ func TestCheckReadiness(t *testing.T) { expectedReady: true, }, { - groupKind: schema.GroupKind{Group: "route.openshift.io", Kind: "Route"}, + groupKind: route.Kind("Route"), object: &routeapi.Route{ Spec: routeapi.RouteSpec{ Host: "", @@ -265,7 +267,7 @@ func TestCheckReadiness(t *testing.T) { expectedReady: false, }, { - groupKind: schema.GroupKind{Group: "route.openshift.io", Kind: "Route"}, + groupKind: route.Kind("Route"), object: &routeapi.Route{ Spec: routeapi.RouteSpec{ Host: "app.example.com", diff --git a/pkg/template/generated/listers/template/internalversion/template_expansion.go b/pkg/template/generated/listers/template/internalversion/template_expansion.go index d86eae0615d5..6631cadb3cac 100644 --- a/pkg/template/generated/listers/template/internalversion/template_expansion.go +++ b/pkg/template/generated/listers/template/internalversion/template_expansion.go @@ -1,6 +1,7 @@ package internalversion import ( + "github.com/openshift/api/template" templateapi "github.com/openshift/origin/pkg/template/apis/template" "k8s.io/apimachinery/pkg/api/errors" ) @@ -21,7 +22,7 @@ func (s templateLister) GetByUID(uid string) (*templateapi.Template, error) { return nil, err } if len(templates) == 0 { - return nil, errors.NewNotFound(templateapi.Resource("template"), uid) + return nil, errors.NewNotFound(template.Resource("template"), uid) } return templates[0].(*templateapi.Template), nil } diff --git a/pkg/template/registry/brokertemplateinstance/etcd/etcd.go b/pkg/template/registry/brokertemplateinstance/etcd/etcd.go index 803c95e00064..4ffbcd44d26a 100644 --- a/pkg/template/registry/brokertemplateinstance/etcd/etcd.go +++ b/pkg/template/registry/brokertemplateinstance/etcd/etcd.go @@ -8,6 +8,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/template" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" templateapi "github.com/openshift/origin/pkg/template/apis/template" "github.com/openshift/origin/pkg/template/registry/brokertemplateinstance" @@ -26,7 +27,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &templateapi.BrokerTemplateInstance{} }, NewListFunc: func() runtime.Object { return &templateapi.BrokerTemplateInstanceList{} }, - DefaultQualifiedResource: templateapi.Resource("brokertemplateinstances"), + DefaultQualifiedResource: template.Resource("brokertemplateinstances"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/template/registry/template/etcd/etcd.go b/pkg/template/registry/template/etcd/etcd.go index 045cc4bc3490..67effa39271d 100644 --- a/pkg/template/registry/template/etcd/etcd.go +++ b/pkg/template/registry/template/etcd/etcd.go @@ -8,6 +8,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + templategroup "github.com/openshift/api/template" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" templateapi "github.com/openshift/origin/pkg/template/apis/template" "github.com/openshift/origin/pkg/template/registry/template" @@ -26,7 +27,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &templateapi.Template{} }, NewListFunc: func() runtime.Object { return &templateapi.TemplateList{} }, - DefaultQualifiedResource: templateapi.Resource("templates"), + DefaultQualifiedResource: templategroup.Resource("templates"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/template/registry/template/rest.go b/pkg/template/registry/template/rest.go index bc9e51cc63b0..a3b1d14d65fa 100644 --- a/pkg/template/registry/template/rest.go +++ b/pkg/template/registry/template/rest.go @@ -12,6 +12,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apiserver/pkg/registry/rest" + "github.com/openshift/api/template" templateapi "github.com/openshift/origin/pkg/template/apis/template" templatevalidation "github.com/openshift/origin/pkg/template/apis/template/validation" "github.com/openshift/origin/pkg/template/generator" @@ -50,7 +51,7 @@ func (s *REST) Create(ctx context.Context, obj runtime.Object, _ rest.ValidateOb return nil, errors.NewBadRequest("not a template") } if errs := templatevalidation.ValidateProcessedTemplate(tpl); len(errs) > 0 { - return nil, errors.NewInvalid(templateapi.Kind("Template"), tpl.Name, errs) + return nil, errors.NewInvalid(template.Kind("Template"), tpl.Name, errs) } generators := map[string]generator.Generator{ @@ -59,7 +60,7 @@ func (s *REST) Create(ctx context.Context, obj runtime.Object, _ rest.ValidateOb processor := templateprocessing.NewProcessor(generators) if errs := processor.Process(tpl); len(errs) > 0 { glog.V(1).Infof(errs.ToAggregate().Error()) - return nil, errors.NewInvalid(templateapi.Kind("Template"), tpl.Name, errs) + return nil, errors.NewInvalid(template.Kind("Template"), tpl.Name, errs) } // we know that we get back runtime.Unstructured objects from the Process call. We need to encode those diff --git a/pkg/template/registry/templateinstance/etcd/etcd.go b/pkg/template/registry/templateinstance/etcd/etcd.go index c65552cf8f91..0b42d18b1dca 100644 --- a/pkg/template/registry/templateinstance/etcd/etcd.go +++ b/pkg/template/registry/templateinstance/etcd/etcd.go @@ -12,6 +12,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/template" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" templateapi "github.com/openshift/origin/pkg/template/apis/template" "github.com/openshift/origin/pkg/template/registry/templateinstance" @@ -32,7 +33,7 @@ func NewREST(optsGetter restoptions.Getter, authorizationClient authorizationint store := ®istry.Store{ NewFunc: func() runtime.Object { return &templateapi.TemplateInstance{} }, NewListFunc: func() runtime.Object { return &templateapi.TemplateInstanceList{} }, - DefaultQualifiedResource: templateapi.Resource("templateinstances"), + DefaultQualifiedResource: template.Resource("templateinstances"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/templateservicebroker/servicebroker/bind.go b/pkg/templateservicebroker/servicebroker/bind.go index 8a634f04f2ef..33d81022647e 100644 --- a/pkg/templateservicebroker/servicebroker/bind.go +++ b/pkg/templateservicebroker/servicebroker/bind.go @@ -18,13 +18,13 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apiserver/pkg/authentication/user" "k8s.io/client-go/util/jsonpath" "k8s.io/client-go/util/retry" kapi "k8s.io/kubernetes/pkg/apis/core" - routeapi "github.com/openshift/origin/pkg/route/apis/route" + "github.com/openshift/api/route" + "github.com/openshift/origin/pkg/api/legacy" templateapi "github.com/openshift/origin/pkg/template/apis/template" "github.com/openshift/origin/pkg/templateservicebroker/openservicebroker/api" "github.com/openshift/origin/pkg/templateservicebroker/util" @@ -195,8 +195,8 @@ func (b *Broker) Bind(u user.Info, instanceID, bindingID string, breq *api.BindR case kapi.Kind("ConfigMap"), kapi.Kind("Secret"), kapi.Kind("Service"), - routeapi.Kind("Route"), - schema.GroupKind{Group: "", Kind: "Route"}: + route.Kind("Route"), + legacy.Kind("Route"): default: continue } diff --git a/pkg/user/apis/user/install/install.go b/pkg/user/apis/user/install/install.go index f1fb297929c7..b89353439657 100644 --- a/pkg/user/apis/user/install/install.go +++ b/pkg/user/apis/user/install/install.go @@ -5,7 +5,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/kubernetes/pkg/api/legacyscheme" - userapi "github.com/openshift/origin/pkg/user/apis/user" + userv1 "github.com/openshift/api/user/v1" userapiv1 "github.com/openshift/origin/pkg/user/apis/user/v1" ) @@ -15,7 +15,6 @@ func init() { // Install registers the API group and adds types to a scheme func Install(scheme *runtime.Scheme) { - utilruntime.Must(userapi.AddToScheme(scheme)) - utilruntime.Must(userapiv1.AddToScheme(scheme)) - utilruntime.Must(scheme.SetVersionPriority(userapiv1.SchemeGroupVersion)) + utilruntime.Must(userapiv1.Install(scheme)) + utilruntime.Must(scheme.SetVersionPriority(userv1.GroupVersion)) } diff --git a/pkg/user/apis/user/register.go b/pkg/user/apis/user/register.go index b92bfcfc5263..1222c11bea15 100644 --- a/pkg/user/apis/user/register.go +++ b/pkg/user/apis/user/register.go @@ -3,31 +3,28 @@ package user import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/kubernetes/pkg/apis/core" ) const ( - GroupName = "user.openshift.io" - LegacyGroupName = "" + GroupName = "user.openshift.io" ) -// SchemeGroupVersion is group version used to register these objects var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: runtime.APIVersionInternal} - - LegacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme + schemeBuilder = runtime.NewSchemeBuilder( + addKnownTypes, + core.AddToScheme, + ) + Install = schemeBuilder.AddToScheme - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // DEPRECATED kept for generated code + SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} + // DEPRECATED kept for generated code + AddToScheme = schemeBuilder.AddToScheme ) -// Kind takes an unqualified kind and returns back a Group qualified GroupKind -func Kind(kind string) schema.GroupKind { - return SchemeGroupVersion.WithKind(kind).GroupKind() -} - -// Resource takes an unqualified resource and returns back a Group qualified GroupResource +// Resource kept for generated code +// DEPRECATED func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } @@ -45,18 +42,3 @@ func addKnownTypes(scheme *runtime.Scheme) error { ) return nil } - -// Adds the list of known types to api.Scheme. -func addLegacyKnownTypes(scheme *runtime.Scheme) error { - types := []runtime.Object{ - &User{}, - &UserList{}, - &Identity{}, - &IdentityList{}, - &UserIdentityMapping{}, - &Group{}, - &GroupList{}, - } - scheme.AddKnownTypes(LegacySchemeGroupVersion, types...) - return nil -} diff --git a/pkg/user/apis/user/types.go b/pkg/user/apis/user/types.go index 376a12c7e32c..1e2282add68f 100644 --- a/pkg/user/apis/user/types.go +++ b/pkg/user/apis/user/types.go @@ -2,7 +2,7 @@ package user import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - kapi "k8s.io/kubernetes/pkg/apis/core" + "k8s.io/kubernetes/pkg/apis/core" ) // Auth system gets identity name and provider @@ -47,7 +47,7 @@ type Identity struct { // User is a reference to the user this identity is associated with // Both Name and UID must be set - User kapi.ObjectReference + User core.ObjectReference Extra map[string]string } @@ -69,8 +69,8 @@ type UserIdentityMapping struct { metav1.TypeMeta metav1.ObjectMeta - Identity kapi.ObjectReference - User kapi.ObjectReference + Identity core.ObjectReference + User core.ObjectReference } // +genclient diff --git a/pkg/user/apis/user/v1/conversion.go b/pkg/user/apis/user/v1/conversion.go index 462a450eb25e..e94a6b456150 100644 --- a/pkg/user/apis/user/v1/conversion.go +++ b/pkg/user/apis/user/v1/conversion.go @@ -1,22 +1,12 @@ package v1 import ( + v1 "github.com/openshift/api/user/v1" "k8s.io/apimachinery/pkg/runtime" ) -func addConversionFuncs(scheme *runtime.Scheme) error { - return nil -} - -func addLegacyFieldSelectorKeyConversions(scheme *runtime.Scheme) error { - if err := scheme.AddFieldLabelConversionFunc(LegacySchemeGroupVersion.String(), "Identity", legacyIdentityFieldSelectorKeyConversionFunc); err != nil { - return err - } - return nil -} - func addFieldSelectorKeyConversions(scheme *runtime.Scheme) error { - if err := scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.String(), "Identity", identityFieldSelectorKeyConversionFunc); err != nil { + if err := scheme.AddFieldLabelConversionFunc(v1.GroupVersion.String(), "Identity", identityFieldSelectorKeyConversionFunc); err != nil { return err } return nil @@ -25,18 +15,6 @@ func addFieldSelectorKeyConversions(scheme *runtime.Scheme) error { // 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 legacyIdentityFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { - switch label { - case "providerName", - "providerUserName", - "user.name", - "user.uid": - return label, value, nil - default: - return runtime.DefaultMetaV1FieldSelectorConversion(label, value) - } -} - func identityFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) { switch label { case "providerName", diff --git a/pkg/user/apis/user/v1/conversion_test.go b/pkg/user/apis/user/v1/conversion_test.go index 58ee0b30e971..9fc6d75ca3a0 100644 --- a/pkg/user/apis/user/v1/conversion_test.go +++ b/pkg/user/apis/user/v1/conversion_test.go @@ -5,22 +5,15 @@ import ( "k8s.io/apimachinery/pkg/runtime" + v1 "github.com/openshift/api/user/v1" "github.com/openshift/origin/pkg/api/apihelpers/apitesting" userapi "github.com/openshift/origin/pkg/user/apis/user" ) func TestFieldSelectorConversions(t *testing.T) { apitesting.FieldKeyCheck{ - SchemeBuilder: []func(*runtime.Scheme) error{LegacySchemeBuilder.AddToScheme, userapi.LegacySchemeBuilder.AddToScheme}, - Kind: LegacySchemeGroupVersion.WithKind("Identity"), - // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST - AllowedExternalFieldKeys: []string{"providerName", "providerUserName", "user.name", "user.uid"}, - FieldKeyEvaluatorFn: userapi.IdentityFieldSelector, - }.Check(t) - - apitesting.FieldKeyCheck{ - SchemeBuilder: []func(*runtime.Scheme) error{SchemeBuilder.AddToScheme, userapi.SchemeBuilder.AddToScheme}, - Kind: SchemeGroupVersion.WithKind("Identity"), + SchemeBuilder: []func(*runtime.Scheme) error{Install}, + Kind: v1.GroupVersion.WithKind("Identity"), // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST AllowedExternalFieldKeys: []string{"providerName", "providerUserName", "user.name", "user.uid"}, FieldKeyEvaluatorFn: userapi.IdentityFieldSelector, diff --git a/pkg/user/apis/user/v1/register.go b/pkg/user/apis/user/v1/register.go index 06abe07b4c94..65a1f2434abe 100644 --- a/pkg/user/apis/user/v1/register.go +++ b/pkg/user/apis/user/v1/register.go @@ -1,30 +1,21 @@ package v1 import ( - "github.com/openshift/api/user/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) + corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1" -const ( - GroupName = "user.openshift.io" - LegacyGroupName = "" + "github.com/openshift/api/user/v1" + "github.com/openshift/origin/pkg/user/apis/user" ) -// SchemeGroupVersion is group version used to register these objects var ( - SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} - LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: "v1"} + localSchemeBuilder = runtime.NewSchemeBuilder( + user.Install, + v1.Install, + corev1conversions.AddToScheme, - LegacySchemeBuilder = runtime.NewSchemeBuilder(v1.DeprecatedInstallWithoutGroup, addConversionFuncs, addLegacyFieldSelectorKeyConversions, RegisterDefaults, RegisterConversions) - AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme - - SchemeBuilder = runtime.NewSchemeBuilder(v1.Install, addConversionFuncs, addFieldSelectorKeyConversions) - AddToScheme = SchemeBuilder.AddToScheme - - localSchemeBuilder = &SchemeBuilder + addFieldSelectorKeyConversions, + RegisterDefaults, + ) + Install = localSchemeBuilder.AddToScheme ) - -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} diff --git a/pkg/user/registry/group/etcd/etcd.go b/pkg/user/registry/group/etcd/etcd.go index 0affc45a21c7..144e271a6f53 100644 --- a/pkg/user/registry/group/etcd/etcd.go +++ b/pkg/user/registry/group/etcd/etcd.go @@ -7,6 +7,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/user" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" userapi "github.com/openshift/origin/pkg/user/apis/user" "github.com/openshift/origin/pkg/user/registry/group" @@ -23,7 +24,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &userapi.Group{} }, NewListFunc: func() runtime.Object { return &userapi.GroupList{} }, - DefaultQualifiedResource: userapi.Resource("groups"), + DefaultQualifiedResource: user.Resource("groups"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/user/registry/identity/etcd/etcd.go b/pkg/user/registry/identity/etcd/etcd.go index 606f803b5e2a..2263b34f5287 100644 --- a/pkg/user/registry/identity/etcd/etcd.go +++ b/pkg/user/registry/identity/etcd/etcd.go @@ -9,6 +9,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + "github.com/openshift/api/user" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" userapi "github.com/openshift/origin/pkg/user/apis/user" "github.com/openshift/origin/pkg/user/registry/identity" @@ -27,7 +28,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &userapi.Identity{} }, NewListFunc: func() runtime.Object { return &userapi.IdentityList{} }, - DefaultQualifiedResource: userapi.Resource("identities"), + DefaultQualifiedResource: user.Resource("identities"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, diff --git a/pkg/user/registry/user/etcd/etcd.go b/pkg/user/registry/user/etcd/etcd.go index 0ab3694c4e74..8b2efc2deeab 100644 --- a/pkg/user/registry/user/etcd/etcd.go +++ b/pkg/user/registry/user/etcd/etcd.go @@ -18,6 +18,7 @@ import ( "k8s.io/kubernetes/pkg/printers" printerstorage "k8s.io/kubernetes/pkg/printers/storage" + usergroup "github.com/openshift/api/user" "github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" userapi "github.com/openshift/origin/pkg/user/apis/user" @@ -38,7 +39,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &userapi.User{} }, NewListFunc: func() runtime.Object { return &userapi.UserList{} }, - DefaultQualifiedResource: userapi.Resource("users"), + DefaultQualifiedResource: usergroup.Resource("users"), TableConvertor: printerstorage.TableConvertor{TablePrinter: printers.NewTablePrinter().With(printersinternal.AddHandlers)}, @@ -61,7 +62,7 @@ func (r *REST) Get(ctx context.Context, name string, options *metav1.GetOptions) if name == "~" { user, ok := apirequest.UserFrom(ctx) if !ok || user.GetName() == "" { - return nil, kerrs.NewForbidden(userapi.Resource("user"), "~", errors.New("requests to ~ must be authenticated")) + return nil, kerrs.NewForbidden(usergroup.Resource("user"), "~", errors.New("requests to ~ must be authenticated")) } name = user.GetName() diff --git a/pkg/user/registry/useridentitymapping/rest.go b/pkg/user/registry/useridentitymapping/rest.go index 7d1e83d3741a..250445d78eb6 100644 --- a/pkg/user/registry/useridentitymapping/rest.go +++ b/pkg/user/registry/useridentitymapping/rest.go @@ -14,6 +14,7 @@ import ( "k8s.io/apiserver/pkg/registry/rest" kapi "k8s.io/kubernetes/pkg/apis/core" + "github.com/openshift/api/user" userapi "github.com/openshift/api/user/v1" userclient "github.com/openshift/client-go/user/clientset/versioned/typed/user/v1" userinternal "github.com/openshift/origin/pkg/user/apis/user" @@ -132,7 +133,7 @@ func (s *REST) createOrUpdate(ctx context.Context, obj runtime.Object, forceCrea if kerrs.IsNotFound(identityErr) { errs := field.ErrorList{field.Invalid(field.NewPath("identity", "name"), mapping.Identity.Name, "referenced identity does not exist")} // TODO update to openshift/api - return nil, false, kerrs.NewInvalid(userinternal.Kind("UserIdentityMapping"), mapping.Name, errs) + return nil, false, kerrs.NewInvalid(user.Kind("UserIdentityMapping"), mapping.Name, errs) } // GetIdentities new user @@ -140,7 +141,7 @@ func (s *REST) createOrUpdate(ctx context.Context, obj runtime.Object, forceCrea if kerrs.IsNotFound(err) { errs := field.ErrorList{field.Invalid(field.NewPath("user", "name"), mapping.User.Name, "referenced user does not exist")} // TODO update to openshift/api - return nil, false, kerrs.NewInvalid(userinternal.Kind("UserIdentityMapping"), mapping.Name, errs) + return nil, false, kerrs.NewInvalid(user.Kind("UserIdentityMapping"), mapping.Name, errs) } if err != nil { return nil, false, err diff --git a/test/extended/image_ecosystem/mysql_replica.go b/test/extended/image_ecosystem/mysql_replica.go index a8ac17f2eac5..bae22a15e089 100644 --- a/test/extended/image_ecosystem/mysql_replica.go +++ b/test/extended/image_ecosystem/mysql_replica.go @@ -7,7 +7,7 @@ import ( g "github.com/onsi/ginkgo" o "github.com/onsi/gomega" - templateapi "github.com/openshift/origin/pkg/template/apis/template" + "github.com/openshift/api/template" exutil "github.com/openshift/origin/test/extended/util" "github.com/openshift/origin/test/extended/util/db" testutil "github.com/openshift/origin/test/util" @@ -72,7 +72,7 @@ func replicationTestFactory(oc *exutil.CLI, tc testCase, cleanup func()) func() // up prior to the AfterEach processing, to guaranteed deletion order defer cleanup() - err := testutil.WaitForPolicyUpdate(oc.InternalKubeClient().Authorization(), oc.Namespace(), "create", templateapi.Resource("templates"), true) + err := testutil.WaitForPolicyUpdate(oc.InternalKubeClient().Authorization(), oc.Namespace(), "create", template.Resource("templates"), true) o.Expect(err).NotTo(o.HaveOccurred()) exutil.CheckOpenShiftNamespaceImageStreams(oc) diff --git a/test/extended/image_ecosystem/postgresql_replica.go b/test/extended/image_ecosystem/postgresql_replica.go index 098393ee2e30..6d779ad04d4d 100644 --- a/test/extended/image_ecosystem/postgresql_replica.go +++ b/test/extended/image_ecosystem/postgresql_replica.go @@ -7,7 +7,7 @@ import ( g "github.com/onsi/ginkgo" o "github.com/onsi/gomega" - templateapi "github.com/openshift/origin/pkg/template/apis/template" + "github.com/openshift/api/template" exutil "github.com/openshift/origin/test/extended/util" "github.com/openshift/origin/test/extended/util/db" testutil "github.com/openshift/origin/test/util" @@ -119,7 +119,7 @@ func PostgreSQLReplicationTestFactory(oc *exutil.CLI, image string, cleanup func // up prior to the AfterEach processing, to guaranteed deletion order defer cleanup() - err := testutil.WaitForPolicyUpdate(oc.InternalKubeClient().Authorization(), oc.Namespace(), "create", templateapi.Resource("templates"), true) + err := testutil.WaitForPolicyUpdate(oc.InternalKubeClient().Authorization(), oc.Namespace(), "create", template.Resource("templates"), true) o.Expect(err).NotTo(o.HaveOccurred()) exutil.CheckOpenShiftNamespaceImageStreams(oc) diff --git a/test/integration/authorization_test.go b/test/integration/authorization_test.go index 710fb4c37dcf..49ea2bf614d3 100644 --- a/test/integration/authorization_test.go +++ b/test/integration/authorization_test.go @@ -30,6 +30,9 @@ import ( rbacclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/rbac/internalversion" oapps "github.com/openshift/api/apps" + "github.com/openshift/api/build" + "github.com/openshift/api/image" + "github.com/openshift/api/oauth" "github.com/openshift/origin/pkg/api/legacy" appsclient "github.com/openshift/origin/pkg/apps/generated/internalclientset" authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization" @@ -39,8 +42,6 @@ import ( buildapi "github.com/openshift/origin/pkg/build/apis/build" buildclient "github.com/openshift/origin/pkg/build/generated/internalclientset" "github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" - imageapi "github.com/openshift/origin/pkg/image/apis/image" - oauthapi "github.com/openshift/origin/pkg/oauth/apis/oauth" policy "github.com/openshift/origin/pkg/oc/cli/admin/policy" projectclient "github.com/openshift/origin/pkg/project/generated/internalclientset" testutil "github.com/openshift/origin/test/util" @@ -136,20 +137,20 @@ func TestClusterReaderCoverage(t *testing.T) { } escalatingResources := map[schema.GroupResource]bool{ - oauthapi.Resource("oauthauthorizetokens"): true, - oauthapi.Resource("oauthaccesstokens"): true, - oauthapi.Resource("oauthclients"): true, - imageapi.Resource("imagestreams/secrets"): true, - kapi.Resource("secrets"): true, - kapi.Resource("pods/exec"): true, - kapi.Resource("pods/proxy"): true, - kapi.Resource("pods/portforward"): true, - kapi.Resource("nodes/proxy"): true, - kapi.Resource("services/proxy"): true, - {Group: "", Resource: "oauthauthorizetokens"}: true, - {Group: "", Resource: "oauthaccesstokens"}: true, - {Group: "", Resource: "oauthclients"}: true, - {Group: "", Resource: "imagestreams/secrets"}: true, + oauth.Resource("oauthauthorizetokens"): true, + oauth.Resource("oauthaccesstokens"): true, + oauth.Resource("oauthclients"): true, + image.Resource("imagestreams/secrets"): true, + kapi.Resource("secrets"): true, + kapi.Resource("pods/exec"): true, + kapi.Resource("pods/proxy"): true, + kapi.Resource("pods/portforward"): true, + kapi.Resource("nodes/proxy"): true, + kapi.Resource("services/proxy"): true, + legacy.Resource("oauthauthorizetokens"): true, + legacy.Resource("oauthaccesstokens"): true, + legacy.Resource("oauthclients"): true, + legacy.Resource("imagestreams/secrets"): true, } readerRole, err := rbacclient.NewForConfigOrDie(clusterAdminClientConfig).ClusterRoles().Get(bootstrappolicy.ClusterReaderRoleName, metav1.GetOptions{}) @@ -175,15 +176,15 @@ func TestClusterReaderCoverage(t *testing.T) { // remove resources without read APIs nonreadingResources := []schema.GroupResource{ - buildapi.Resource("buildconfigs/instantiatebinary"), - buildapi.Resource("buildconfigs/instantiate"), - buildapi.Resource("builds/clone"), oapps.Resource("deploymentconfigrollbacks"), oapps.Resource("generatedeploymentconfigs"), oapps.Resource("deploymentconfigs/rollback"), oapps.Resource("deploymentconfigs/instantiate"), - imageapi.Resource("imagestreamimports"), - imageapi.Resource("imagestreammappings"), + build.Resource("buildconfigs/instantiatebinary"), + build.Resource("buildconfigs/instantiate"), + build.Resource("builds/clone"), + image.Resource("imagestreamimports"), + image.Resource("imagestreammappings"), extensionsapi.Resource("deployments/rollback"), appsapi.Resource("deployments/rollback"), kapi.Resource("pods/attach"), @@ -1439,7 +1440,7 @@ func TestLegacyLocalRoleBindingEndpoint(t *testing.T) { testBindingName := "testrole" // install the legacy types into the client for decoding - legacy.InstallLegacyAuthorization(authorizationclientscheme.Scheme) + legacy.InstallInternalLegacyAuthorization(authorizationclientscheme.Scheme) // create rolebinding roleBindingToCreate := &authorizationapi.RoleBinding{ @@ -1608,7 +1609,7 @@ func TestLegacyClusterRoleBindingEndpoint(t *testing.T) { clusterAdmin := authorizationclient.NewForConfigOrDie(clusterAdminClientConfig) // install the legacy types into the client for decoding - legacy.InstallLegacyAuthorization(authorizationclientscheme.Scheme) + legacy.InstallInternalLegacyAuthorization(authorizationclientscheme.Scheme) clusterRoleBindingsPath := "/oapi/v1/clusterrolebindings" testBindingName := "testbinding" @@ -1746,7 +1747,7 @@ func TestLegacyClusterRoleEndpoint(t *testing.T) { clusterAdmin := authorizationclient.NewForConfigOrDie(clusterAdminClientConfig) // install the legacy types into the client for decoding - legacy.InstallLegacyAuthorization(authorizationclientscheme.Scheme) + legacy.InstallInternalLegacyAuthorization(authorizationclientscheme.Scheme) clusterRolesPath := "/oapi/v1/clusterroles" testRole := "testrole" @@ -1867,7 +1868,7 @@ func TestLegacyLocalRoleEndpoint(t *testing.T) { } // install the legacy types into the client for decoding - legacy.InstallLegacyAuthorization(authorizationclientscheme.Scheme) + legacy.InstallInternalLegacyAuthorization(authorizationclientscheme.Scheme) rolesPath := "/oapi/v1/namespaces/" + namespace + "/roles" testRole := "testrole" @@ -1994,7 +1995,7 @@ func TestOldLocalAccessReviewEndpoints(t *testing.T) { } // install the legacy types into the client for decoding - legacy.InstallLegacyAuthorization(authorizationclientscheme.Scheme) + legacy.InstallInternalLegacyAuthorization(authorizationclientscheme.Scheme) codecFactory := serializer.NewCodecFactory(authorizationclientscheme.Scheme) sar := &authorizationapi.SubjectAccessReview{ diff --git a/test/integration/build_admission_test.go b/test/integration/build_admission_test.go index 9c51570ac8ec..a56157b687e8 100644 --- a/test/integration/build_admission_test.go +++ b/test/integration/build_admission_test.go @@ -10,6 +10,7 @@ import ( kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" authorizationtypedclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/authorization/internalversion" + "github.com/openshift/api/build" buildapi "github.com/openshift/origin/pkg/build/apis/build" buildclient "github.com/openshift/origin/pkg/build/generated/internalclientset" buildtypedclient "github.com/openshift/origin/pkg/build/generated/internalclientset/typed/build/internalversion" @@ -229,7 +230,7 @@ func setupBuildStrategyTest(t *testing.T, includeControllers bool) (clusterAdmin if err := addJoe.AddRole(); err != nil { t.Fatalf("unexpected error: %v", err) } - if err := testutil.WaitForPolicyUpdate(projectAdminKubeClient.Authorization(), namespace, "create", buildapi.Resource(bootstrappolicy.DockerBuildResource), true); err != nil { + if err := testutil.WaitForPolicyUpdate(projectAdminKubeClient.Authorization(), namespace, "create", build.Resource(bootstrappolicy.DockerBuildResource), true); err != nil { t.Fatalf(err.Error()) } @@ -285,16 +286,16 @@ func removeBuildStrategyRoleResources(t *testing.T, clusterAdminAuthorizationCli } } - if err := testutil.WaitForPolicyUpdate(selfSarClient, testutil.Namespace(), "create", buildapi.Resource(bootstrappolicy.DockerBuildResource), false); err != nil { + if err := testutil.WaitForPolicyUpdate(selfSarClient, testutil.Namespace(), "create", build.Resource(bootstrappolicy.DockerBuildResource), false); err != nil { t.Fatal(err) } - if err := testutil.WaitForPolicyUpdate(selfSarClient, testutil.Namespace(), "create", buildapi.Resource(bootstrappolicy.SourceBuildResource), false); err != nil { + if err := testutil.WaitForPolicyUpdate(selfSarClient, testutil.Namespace(), "create", build.Resource(bootstrappolicy.SourceBuildResource), false); err != nil { t.Fatal(err) } - if err := testutil.WaitForPolicyUpdate(selfSarClient, testutil.Namespace(), "create", buildapi.Resource(bootstrappolicy.CustomBuildResource), false); err != nil { + if err := testutil.WaitForPolicyUpdate(selfSarClient, testutil.Namespace(), "create", build.Resource(bootstrappolicy.CustomBuildResource), false); err != nil { t.Fatal(err) } - if err := testutil.WaitForPolicyUpdate(selfSarClient, testutil.Namespace(), "create", buildapi.Resource(bootstrappolicy.JenkinsPipelineBuildResource), false); err != nil { + if err := testutil.WaitForPolicyUpdate(selfSarClient, testutil.Namespace(), "create", build.Resource(bootstrappolicy.JenkinsPipelineBuildResource), false); err != nil { t.Fatal(err) } } @@ -313,7 +314,7 @@ func grantRestrictedBuildStrategyRoleResources(t *testing.T, clusterAdminAuthori } } - if err := testutil.WaitForPolicyUpdate(selfSarClient, testutil.Namespace(), "create", buildapi.Resource(bootstrappolicy.CustomBuildResource), true); err != nil { + if err := testutil.WaitForPolicyUpdate(selfSarClient, testutil.Namespace(), "create", build.Resource(bootstrappolicy.CustomBuildResource), true); err != nil { t.Fatal(err) } } diff --git a/test/integration/deploy_defaults_test.go b/test/integration/deploy_defaults_test.go index 55fa32c7793d..6335d06db636 100644 --- a/test/integration/deploy_defaults_test.go +++ b/test/integration/deploy_defaults_test.go @@ -120,7 +120,7 @@ func TestDeploymentConfigDefaults(t *testing.T) { t.Fatalf("Failed to create appsClient: %v", err) } // install the legacy types into the client for decoding - legacy.InstallLegacyApps(appsclientscheme.Scheme) + legacy.InstallInternalLegacyApps(appsclientscheme.Scheme) ttLegacy := []struct { obj *appsapi.DeploymentConfig diff --git a/test/integration/front_proxy_test.go b/test/integration/front_proxy_test.go index 08833db81f7f..20e4cc89cb92 100644 --- a/test/integration/front_proxy_test.go +++ b/test/integration/front_proxy_test.go @@ -20,12 +20,12 @@ import ( projectapiv1 "github.com/openshift/api/project/v1" "github.com/openshift/library-go/pkg/crypto" + "github.com/openshift/origin/pkg/api/legacy" authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization" authorizationclient "github.com/openshift/origin/pkg/authorization/generated/internalclientset" "github.com/openshift/origin/pkg/cmd/server/admin" "github.com/openshift/origin/pkg/cmd/server/apis/config" "github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" - projectapi "github.com/openshift/origin/pkg/project/apis/project" projectclient "github.com/openshift/origin/pkg/project/generated/internalclientset" testutil "github.com/openshift/origin/test/util" testserver "github.com/openshift/origin/test/util/server" @@ -98,7 +98,7 @@ func TestFrontProxy(t *testing.T) { &authorizationapi.ClusterRole{ ObjectMeta: metav1.ObjectMeta{Name: listProjectsRoleName}, Rules: []authorizationapi.PolicyRule{ - authorizationapi.NewRule("list").Groups(projectapi.LegacyGroupName).Resources("projects").RuleOrDie(), + authorizationapi.NewRule("list").Groups(legacy.GroupName).Resources("projects").RuleOrDie(), }, }, ); err != nil { diff --git a/test/integration/imagechange_buildtrigger_test.go b/test/integration/imagechange_buildtrigger_test.go index 3c134bb0b81f..a55e1dfa0f06 100644 --- a/test/integration/imagechange_buildtrigger_test.go +++ b/test/integration/imagechange_buildtrigger_test.go @@ -11,6 +11,7 @@ import ( kapi "k8s.io/kubernetes/pkg/apis/core" kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" + "github.com/openshift/api/build" buildapi "github.com/openshift/origin/pkg/build/apis/build" buildclient "github.com/openshift/origin/pkg/build/generated/internalclientset" "github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" @@ -91,7 +92,7 @@ func TestSimpleImageChangeBuildTriggerFromImageStreamTagCustom(t *testing.T) { } options.AddRole() - if err := testutil.WaitForPolicyUpdate(projectAdminKubeClient.Authorization(), testutil.Namespace(), "create", buildapi.Resource(bootstrappolicy.CustomBuildResource), true); err != nil { + if err := testutil.WaitForPolicyUpdate(projectAdminKubeClient.Authorization(), testutil.Namespace(), "create", build.Resource(bootstrappolicy.CustomBuildResource), true); err != nil { t.Fatal(err) } @@ -122,7 +123,7 @@ func TestSimpleImageChangeBuildTriggerFromImageStreamTagCustomWithConfigChange(t } options.AddRole() - if err := testutil.WaitForPolicyUpdate(projectAdminKubeClient.Authorization(), testutil.Namespace(), "create", buildapi.Resource(bootstrappolicy.CustomBuildResource), true); err != nil { + if err := testutil.WaitForPolicyUpdate(projectAdminKubeClient.Authorization(), testutil.Namespace(), "create", build.Resource(bootstrappolicy.CustomBuildResource), true); err != nil { t.Fatal(err) } diff --git a/test/integration/unprivileged_newproject_test.go b/test/integration/unprivileged_newproject_test.go index ad0928799119..8a8501844bbf 100644 --- a/test/integration/unprivileged_newproject_test.go +++ b/test/integration/unprivileged_newproject_test.go @@ -22,6 +22,7 @@ import ( // make sure all generated clients compile // these are only here because it's the spot I chose to use a generated clientset for a test + "github.com/openshift/api/project" _ "github.com/openshift/client-go/apps/clientset/versioned" _ "github.com/openshift/client-go/authorization/clientset/versioned" _ "github.com/openshift/client-go/build/clientset/versioned" @@ -237,7 +238,7 @@ func TestUnprivilegedNewProjectDenied(t *testing.T) { valerieProjectClient := projectclient.NewForConfigOrDie(valerieClientConfig) valerieKubeClient := kclientset.NewForConfigOrDie(valerieClientConfig) - if err := testutil.WaitForClusterPolicyUpdate(valerieKubeClient.Authorization(), "create", projectapi.Resource("projectrequests"), false); err != nil { + if err := testutil.WaitForClusterPolicyUpdate(valerieKubeClient.Authorization(), "create", project.Resource("projectrequests"), false); err != nil { t.Fatalf("unexpected error: %v", err) } diff --git a/test/util/server/server.go b/test/util/server/server.go index c52a0de7f1ac..92d75448c75f 100644 --- a/test/util/server/server.go +++ b/test/util/server/server.go @@ -451,7 +451,7 @@ func StartConfiguredMasterWithOptions(masterConfig *configapi.MasterConfig) (str guardMaster() // openshift apiserver needs its own scheme, but this installs it for now. oc needs it off, openshift apiserver needs it on. awesome. - legacy.LegacyInstallAll(legacyscheme.Scheme) + legacy.InstallLegacyInternalAll(legacyscheme.Scheme) if masterConfig.EtcdConfig != nil && len(masterConfig.EtcdConfig.StorageDir) > 0 { os.RemoveAll(masterConfig.EtcdConfig.StorageDir) diff --git a/tools/etcdhelper/etcdhelper.go b/tools/etcdhelper/etcdhelper.go index 4d93a3ab11f1..0fec22a474cf 100644 --- a/tools/etcdhelper/etcdhelper.go +++ b/tools/etcdhelper/etcdhelper.go @@ -28,7 +28,7 @@ import ( func init() { apiregistration.Install(scheme.Scheme) apiinstall.InstallAll(scheme.Scheme) - apilegacy.LegacyInstallAll(scheme.Scheme) + apilegacy.InstallLegacyInternalAll(scheme.Scheme) } func main() { diff --git a/vendor/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/scheme.go b/vendor/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/scheme.go index b4ce21657bc3..2fce4459a030 100644 --- a/vendor/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/scheme.go +++ b/vendor/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/scheme.go @@ -164,7 +164,7 @@ func (s *Scheme) AddUnversionedTypes(version schema.GroupVersion, types ...Objec gvk := version.WithKind(t.Name()) s.unversionedTypes[t] = gvk if old, ok := s.unversionedKinds[gvk.Kind]; ok && t != old { - panic(fmt.Sprintf("%v.%v has already been registered as unversioned kind %q - kind name must be unique", old.PkgPath(), old.Name(), gvk)) + panic(fmt.Sprintf("%v.%v has already been registered as unversioned kind %q - kind name must be unique in scheme %q", old.PkgPath(), old.Name(), gvk, s.schemeName)) } s.unversionedKinds[gvk.Kind] = t } @@ -205,7 +205,7 @@ func (s *Scheme) AddKnownTypeWithName(gvk schema.GroupVersionKind, obj Object) { } if oldT, found := s.gvkToType[gvk]; found && oldT != t { - panic(fmt.Sprintf("Double registration of different types for %v: old=%v.%v, new=%v.%v", gvk, oldT.PkgPath(), oldT.Name(), t.PkgPath(), t.Name())) + panic(fmt.Sprintf("Double registration of different types for %v: old=%v.%v, new=%v.%v in scheme %q", gvk, oldT.PkgPath(), oldT.Name(), t.PkgPath(), t.Name(), s.schemeName)) } s.gvkToType[gvk] = t