From 1db5990013a4d4f8623d76465b171ad048460283 Mon Sep 17 00:00:00 2001 From: ravisantoshgudimetla Date: Wed, 9 May 2018 11:02:42 -0400 Subject: [PATCH] Move scheduling api to beta --- cmd/kube-apiserver/app/aggregator.go | 1 + hack/.golint_failures | 2 + hack/lib/init.sh | 1 + pkg/apis/scheduling/install/install.go | 4 +- pkg/apis/scheduling/v1beta1/doc.go | 22 +++++++ pkg/apis/scheduling/v1beta1/register.go | 45 +++++++++++++ pkg/master/master.go | 2 + .../scheduling/rest/storage_scheduling.go | 9 ++- staging/src/k8s.io/api/roundtrip_test.go | 2 + .../src/k8s.io/api/scheduling/v1beta1/doc.go | 21 ++++++ .../k8s.io/api/scheduling/v1beta1/register.go | 52 +++++++++++++++ .../k8s.io/api/scheduling/v1beta1/types.go | 66 +++++++++++++++++++ .../etcd/etcd_storage_path_test.go | 8 +++ 13 files changed, 231 insertions(+), 4 deletions(-) create mode 100644 pkg/apis/scheduling/v1beta1/doc.go create mode 100644 pkg/apis/scheduling/v1beta1/register.go create mode 100644 staging/src/k8s.io/api/scheduling/v1beta1/doc.go create mode 100644 staging/src/k8s.io/api/scheduling/v1beta1/register.go create mode 100644 staging/src/k8s.io/api/scheduling/v1beta1/types.go diff --git a/cmd/kube-apiserver/app/aggregator.go b/cmd/kube-apiserver/app/aggregator.go index 864d8099aed..86bcc77ae5d 100644 --- a/cmd/kube-apiserver/app/aggregator.go +++ b/cmd/kube-apiserver/app/aggregator.go @@ -263,6 +263,7 @@ var apiVersionPriorities = map[schema.GroupVersion]priority{ {Group: "admissionregistration.k8s.io", Version: "v1"}: {group: 16700, version: 15}, {Group: "admissionregistration.k8s.io", Version: "v1beta1"}: {group: 16700, version: 12}, {Group: "admissionregistration.k8s.io", Version: "v1alpha1"}: {group: 16700, version: 9}, + {Group: "scheduling.k8s.io", Version: "v1beta1"}: {group: 16600, version: 12}, {Group: "scheduling.k8s.io", Version: "v1alpha1"}: {group: 16600, version: 9}, // Append a new group to the end of the list if unsure. // You can use min(existing group)-100 as the initial value for a group. diff --git a/hack/.golint_failures b/hack/.golint_failures index 40b156e9d03..4b8f61bf4dc 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -65,6 +65,7 @@ pkg/apis/rbac/v1beta1 pkg/apis/rbac/validation pkg/apis/scheduling pkg/apis/scheduling/v1alpha1 +pkg/apis/scheduling/v1beta1 pkg/apis/settings pkg/apis/settings/v1alpha1 pkg/apis/storage @@ -441,6 +442,7 @@ staging/src/k8s.io/api/rbac/v1 staging/src/k8s.io/api/rbac/v1alpha1 staging/src/k8s.io/api/rbac/v1beta1 staging/src/k8s.io/api/scheduling/v1alpha1 +staging/src/k8s.io/api/scheduling/v1beta1 staging/src/k8s.io/api/settings/v1alpha1 staging/src/k8s.io/api/storage/v1 staging/src/k8s.io/api/storage/v1alpha1 diff --git a/hack/lib/init.sh b/hack/lib/init.sh index 8b9cd6b6a53..2f1a33a0b76 100755 --- a/hack/lib/init.sh +++ b/hack/lib/init.sh @@ -81,6 +81,7 @@ rbac.authorization.k8s.io/v1 \ rbac.authorization.k8s.io/v1beta1 \ rbac.authorization.k8s.io/v1alpha1 \ scheduling.k8s.io/v1alpha1 \ +scheduling.k8s.io/v1beta1 \ settings.k8s.io/v1alpha1 \ storage.k8s.io/v1beta1 \ storage.k8s.io/v1 \ diff --git a/pkg/apis/scheduling/install/install.go b/pkg/apis/scheduling/install/install.go index a8cfd8e7e07..ef9cb435f94 100644 --- a/pkg/apis/scheduling/install/install.go +++ b/pkg/apis/scheduling/install/install.go @@ -24,6 +24,7 @@ import ( "k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/apis/scheduling" "k8s.io/kubernetes/pkg/apis/scheduling/v1alpha1" + "k8s.io/kubernetes/pkg/apis/scheduling/v1beta1" ) func init() { @@ -33,6 +34,7 @@ func init() { // Install registers the API group and adds types to a scheme func Install(scheme *runtime.Scheme) { utilruntime.Must(scheduling.AddToScheme(scheme)) + utilruntime.Must(v1beta1.AddToScheme(scheme)) utilruntime.Must(v1alpha1.AddToScheme(scheme)) - utilruntime.Must(scheme.SetVersionPriority(v1alpha1.SchemeGroupVersion)) + utilruntime.Must(scheme.SetVersionPriority(v1beta1.SchemeGroupVersion, v1alpha1.SchemeGroupVersion)) } diff --git a/pkg/apis/scheduling/v1beta1/doc.go b/pkg/apis/scheduling/v1beta1/doc.go new file mode 100644 index 00000000000..117381f65f4 --- /dev/null +++ b/pkg/apis/scheduling/v1beta1/doc.go @@ -0,0 +1,22 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/scheduling +// +k8s:conversion-gen-external-types=k8s.io/api/scheduling/v1beta1 +// +groupName=scheduling.k8s.io +// +k8s:defaulter-gen=TypeMeta +// +k8s:defaulter-gen-input=../../../../vendor/k8s.io/api/scheduling/v1beta1 +package v1beta1 // import "k8s.io/kubernetes/pkg/apis/scheduling/v1beta1" diff --git a/pkg/apis/scheduling/v1beta1/register.go b/pkg/apis/scheduling/v1beta1/register.go new file mode 100644 index 00000000000..45eae937cc0 --- /dev/null +++ b/pkg/apis/scheduling/v1beta1/register.go @@ -0,0 +1,45 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + schedulingv1beta1 "k8s.io/api/scheduling/v1beta1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// GroupName is the group name use in this package +const GroupName = "scheduling.k8s.io" + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta1"} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + localSchemeBuilder = &schedulingv1beta1.SchemeBuilder + AddToScheme = localSchemeBuilder.AddToScheme +) + +func init() { + // We only register manually written functions here. The registration of the + // generated functions takes place in the generated files. The separation + // makes the code compile even when the generated files are missing. + localSchemeBuilder.Register(RegisterDefaults) +} diff --git a/pkg/master/master.go b/pkg/master/master.go index bd146320219..240f631a863 100644 --- a/pkg/master/master.go +++ b/pkg/master/master.go @@ -48,6 +48,7 @@ import ( rbacv1alpha1 "k8s.io/api/rbac/v1alpha1" rbacv1beta1 "k8s.io/api/rbac/v1beta1" schedulingv1alpha1 "k8s.io/api/scheduling/v1alpha1" + schedulingapiv1beta1 "k8s.io/api/scheduling/v1beta1" settingsv1alpha1 "k8s.io/api/settings/v1alpha1" storageapiv1 "k8s.io/api/storage/v1" storageapiv1alpha1 "k8s.io/api/storage/v1alpha1" @@ -484,6 +485,7 @@ func DefaultAPIResourceConfigSource() *serverstorage.ResourceConfig { rbacv1beta1.SchemeGroupVersion, storageapiv1.SchemeGroupVersion, storageapiv1beta1.SchemeGroupVersion, + schedulingapiv1beta1.SchemeGroupVersion, ) // disable alpha versions explicitly so we have a full list of what's possible to serve ret.DisableVersions( diff --git a/pkg/registry/scheduling/rest/storage_scheduling.go b/pkg/registry/scheduling/rest/storage_scheduling.go index 4d6b2e6c982..3010724297f 100644 --- a/pkg/registry/scheduling/rest/storage_scheduling.go +++ b/pkg/registry/scheduling/rest/storage_scheduling.go @@ -33,6 +33,7 @@ import ( "k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/apis/scheduling" schedulingapiv1alpha1 "k8s.io/kubernetes/pkg/apis/scheduling/v1alpha1" + schedulingapiv1beta1 "k8s.io/kubernetes/pkg/apis/scheduling/v1beta1" schedulingclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/scheduling/internalversion" priorityclassstore "k8s.io/kubernetes/pkg/registry/scheduling/priorityclass/storage" ) @@ -47,13 +48,15 @@ func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorag apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(scheduling.GroupName, legacyscheme.Scheme, legacyscheme.ParameterCodec, legacyscheme.Codecs) if apiResourceConfigSource.VersionEnabled(schedulingapiv1alpha1.SchemeGroupVersion) { - apiGroupInfo.VersionedResourcesStorageMap[schedulingapiv1alpha1.SchemeGroupVersion.Version] = p.v1alpha1Storage(apiResourceConfigSource, restOptionsGetter) + apiGroupInfo.VersionedResourcesStorageMap[schedulingapiv1alpha1.SchemeGroupVersion.Version] = p.storage(apiResourceConfigSource, restOptionsGetter) + } + if apiResourceConfigSource.VersionEnabled(schedulingapiv1beta1.SchemeGroupVersion) { + apiGroupInfo.VersionedResourcesStorageMap[schedulingapiv1beta1.SchemeGroupVersion.Version] = p.storage(apiResourceConfigSource, restOptionsGetter) } - return apiGroupInfo, true } -func (p RESTStorageProvider) v1alpha1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) map[string]rest.Storage { +func (p RESTStorageProvider) storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) map[string]rest.Storage { storage := map[string]rest.Storage{} // priorityclasses priorityClassStorage := priorityclassstore.NewREST(restOptionsGetter) diff --git a/staging/src/k8s.io/api/roundtrip_test.go b/staging/src/k8s.io/api/roundtrip_test.go index a7e828feb6a..5b82feb84e4 100644 --- a/staging/src/k8s.io/api/roundtrip_test.go +++ b/staging/src/k8s.io/api/roundtrip_test.go @@ -46,6 +46,7 @@ import ( rbacv1alpha1 "k8s.io/api/rbac/v1alpha1" rbacv1beta1 "k8s.io/api/rbac/v1beta1" schedulingv1alpha1 "k8s.io/api/scheduling/v1alpha1" + schedulingv1beta1 "k8s.io/api/scheduling/v1beta1" settingsv1alpha1 "k8s.io/api/settings/v1alpha1" storagev1 "k8s.io/api/storage/v1" storagev1alpha1 "k8s.io/api/storage/v1alpha1" @@ -87,6 +88,7 @@ var groups = []runtime.SchemeBuilder{ rbacv1beta1.SchemeBuilder, rbacv1.SchemeBuilder, schedulingv1alpha1.SchemeBuilder, + schedulingv1beta1.SchemeBuilder, settingsv1alpha1.SchemeBuilder, storagev1alpha1.SchemeBuilder, storagev1beta1.SchemeBuilder, diff --git a/staging/src/k8s.io/api/scheduling/v1beta1/doc.go b/staging/src/k8s.io/api/scheduling/v1beta1/doc.go new file mode 100644 index 00000000000..f2dd1cfac70 --- /dev/null +++ b/staging/src/k8s.io/api/scheduling/v1beta1/doc.go @@ -0,0 +1,21 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:deepcopy-gen=package +// +k8s:openapi-gen=true + +// +groupName=scheduling.k8s.io +package v1beta1 // import "k8s.io/api/scheduling/v1beta1" diff --git a/staging/src/k8s.io/api/scheduling/v1beta1/register.go b/staging/src/k8s.io/api/scheduling/v1beta1/register.go new file mode 100644 index 00000000000..fb26557bbbb --- /dev/null +++ b/staging/src/k8s.io/api/scheduling/v1beta1/register.go @@ -0,0 +1,52 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// GroupName is the group name use in this package +const GroupName = "scheduling.k8s.io" + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta1"} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + // TODO: move SchemeBuilder with zz_generated.deepcopy.go to k8s.io/api. + // localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes. + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + localSchemeBuilder = &SchemeBuilder + AddToScheme = localSchemeBuilder.AddToScheme +) + +// Adds the list of known types to the given scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &PriorityClass{}, + &PriorityClassList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/staging/src/k8s.io/api/scheduling/v1beta1/types.go b/staging/src/k8s.io/api/scheduling/v1beta1/types.go new file mode 100644 index 00000000000..a9aaa86650d --- /dev/null +++ b/staging/src/k8s.io/api/scheduling/v1beta1/types.go @@ -0,0 +1,66 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +genclient:nonNamespaced +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// PriorityClass defines mapping from a priority class name to the priority +// integer value. The value can be any valid integer. +type PriorityClass struct { + metav1.TypeMeta `json:",inline"` + // Standard object's metadata. + // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata + // +optional + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + // The value of this priority class. This is the actual priority that pods + // receive when they have the name of this class in their pod spec. + Value int32 `json:"value" protobuf:"bytes,2,opt,name=value"` + + // globalDefault specifies whether this PriorityClass should be considered as + // the default priority for pods that do not have any priority class. + // Only one PriorityClass can be marked as `globalDefault`. However, if more than + // one PriorityClasses exists with their `globalDefault` field set to true, + // the smallest value of such global default PriorityClasses will be used as the default priority. + // +optional + GlobalDefault bool `json:"globalDefault,omitempty" protobuf:"bytes,3,opt,name=globalDefault"` + + // description is an arbitrary string that usually provides guidelines on + // when this priority class should be used. + // +optional + Description string `json:"description,omitempty" protobuf:"bytes,4,opt,name=description"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// PriorityClassList is a collection of priority classes. +type PriorityClassList struct { + metav1.TypeMeta `json:",inline"` + // Standard list metadata + // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata + // +optional + metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + // items is the list of PriorityClasses + Items []PriorityClass `json:"items" protobuf:"bytes,2,rep,name=items"` +} diff --git a/test/integration/etcd/etcd_storage_path_test.go b/test/integration/etcd/etcd_storage_path_test.go index eb391d7ca57..b4ea1970c0d 100644 --- a/test/integration/etcd/etcd_storage_path_test.go +++ b/test/integration/etcd/etcd_storage_path_test.go @@ -424,6 +424,14 @@ var etcdStorageData = map[schema.GroupVersionResource]struct { gvr("scheduling.k8s.io", "v1alpha1", "priorityclasses"): { stub: `{"metadata":{"name":"pc1"},"Value":1000}`, expectedEtcdPath: "/registry/priorityclasses/pc1", + expectedGVK: gvkP("scheduling.k8s.io", "v1beta1", "PriorityClass"), + }, + // -- + + // k8s.io/kubernetes/pkg/apis/scheduling/v1beta1 + gvr("scheduling.k8s.io", "v1beta1", "priorityclasses"): { + stub: `{"metadata":{"name":"pc2"},"Value":1000}`, + expectedEtcdPath: "/registry/priorityclasses/pc2", }, // -- }