storage_autoscaling.go 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package rest
  14. import (
  15. autoscalingapiv1 "k8s.io/api/autoscaling/v1"
  16. autoscalingapiv2beta1 "k8s.io/api/autoscaling/v2beta1"
  17. "k8s.io/apiserver/pkg/registry/generic"
  18. "k8s.io/apiserver/pkg/registry/rest"
  19. genericapiserver "k8s.io/apiserver/pkg/server"
  20. serverstorage "k8s.io/apiserver/pkg/server/storage"
  21. "k8s.io/kubernetes/pkg/api/legacyscheme"
  22. "k8s.io/kubernetes/pkg/apis/autoscaling"
  23. autoscalingapiv2beta2 "k8s.io/kubernetes/pkg/apis/autoscaling/v2beta2"
  24. horizontalpodautoscalerstore "k8s.io/kubernetes/pkg/registry/autoscaling/horizontalpodautoscaler/storage"
  25. )
  26. type RESTStorageProvider struct{}
  27. func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (genericapiserver.APIGroupInfo, bool) {
  28. apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(autoscaling.GroupName, legacyscheme.Scheme, legacyscheme.ParameterCodec, legacyscheme.Codecs)
  29. // If you add a version here, be sure to add an entry in `k8s.io/kubernetes/cmd/kube-apiserver/app/aggregator.go with specific priorities.
  30. // TODO refactor the plumbing to provide the information in the APIGroupInfo
  31. if apiResourceConfigSource.VersionEnabled(autoscalingapiv2beta2.SchemeGroupVersion) {
  32. apiGroupInfo.VersionedResourcesStorageMap[autoscalingapiv2beta2.SchemeGroupVersion.Version] = p.v2beta2Storage(apiResourceConfigSource, restOptionsGetter)
  33. }
  34. if apiResourceConfigSource.VersionEnabled(autoscalingapiv2beta1.SchemeGroupVersion) {
  35. apiGroupInfo.VersionedResourcesStorageMap[autoscalingapiv2beta1.SchemeGroupVersion.Version] = p.v2beta1Storage(apiResourceConfigSource, restOptionsGetter)
  36. }
  37. if apiResourceConfigSource.VersionEnabled(autoscalingapiv1.SchemeGroupVersion) {
  38. apiGroupInfo.VersionedResourcesStorageMap[autoscalingapiv1.SchemeGroupVersion.Version] = p.v1Storage(apiResourceConfigSource, restOptionsGetter)
  39. }
  40. return apiGroupInfo, true
  41. }
  42. func (p RESTStorageProvider) v1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) map[string]rest.Storage {
  43. storage := map[string]rest.Storage{}
  44. // horizontalpodautoscalers
  45. hpaStorage, hpaStatusStorage := horizontalpodautoscalerstore.NewREST(restOptionsGetter)
  46. storage["horizontalpodautoscalers"] = hpaStorage
  47. storage["horizontalpodautoscalers/status"] = hpaStatusStorage
  48. return storage
  49. }
  50. func (p RESTStorageProvider) v2beta1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) map[string]rest.Storage {
  51. storage := map[string]rest.Storage{}
  52. // horizontalpodautoscalers
  53. hpaStorage, hpaStatusStorage := horizontalpodautoscalerstore.NewREST(restOptionsGetter)
  54. storage["horizontalpodautoscalers"] = hpaStorage
  55. storage["horizontalpodautoscalers/status"] = hpaStatusStorage
  56. return storage
  57. }
  58. func (p RESTStorageProvider) v2beta2Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) map[string]rest.Storage {
  59. storage := map[string]rest.Storage{}
  60. // horizontalpodautoscalers
  61. hpaStorage, hpaStatusStorage := horizontalpodautoscalerstore.NewREST(restOptionsGetter)
  62. storage["horizontalpodautoscalers"] = hpaStorage
  63. storage["horizontalpodautoscalers/status"] = hpaStatusStorage
  64. return storage
  65. }
  66. func (p RESTStorageProvider) GroupName() string {
  67. return autoscaling.GroupName
  68. }