storage_apiserver.go 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
  16. admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1"
  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/admissionregistration"
  23. mutatingwebhookconfigurationstorage "k8s.io/kubernetes/pkg/registry/admissionregistration/mutatingwebhookconfiguration/storage"
  24. validatingwebhookconfigurationstorage "k8s.io/kubernetes/pkg/registry/admissionregistration/validatingwebhookconfiguration/storage"
  25. )
  26. type RESTStorageProvider struct{}
  27. func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (genericapiserver.APIGroupInfo, bool, error) {
  28. apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(admissionregistration.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(admissionregistrationv1beta1.SchemeGroupVersion) {
  32. if storageMap, err := p.v1beta1Storage(apiResourceConfigSource, restOptionsGetter); err != nil {
  33. return genericapiserver.APIGroupInfo{}, false, err
  34. } else {
  35. apiGroupInfo.VersionedResourcesStorageMap[admissionregistrationv1beta1.SchemeGroupVersion.Version] = storageMap
  36. }
  37. }
  38. if apiResourceConfigSource.VersionEnabled(admissionregistrationv1.SchemeGroupVersion) {
  39. if storageMap, err := p.v1Storage(apiResourceConfigSource, restOptionsGetter); err != nil {
  40. return genericapiserver.APIGroupInfo{}, false, err
  41. } else {
  42. apiGroupInfo.VersionedResourcesStorageMap[admissionregistrationv1.SchemeGroupVersion.Version] = storageMap
  43. }
  44. }
  45. return apiGroupInfo, true, nil
  46. }
  47. func (p RESTStorageProvider) v1beta1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (map[string]rest.Storage, error) {
  48. storage := map[string]rest.Storage{}
  49. // validatingwebhookconfigurations
  50. validatingStorage, err := validatingwebhookconfigurationstorage.NewREST(restOptionsGetter)
  51. if err != nil {
  52. return storage, err
  53. }
  54. storage["validatingwebhookconfigurations"] = validatingStorage
  55. // mutatingwebhookconfigurations
  56. mutatingStorage, err := mutatingwebhookconfigurationstorage.NewREST(restOptionsGetter)
  57. if err != nil {
  58. return storage, err
  59. }
  60. storage["mutatingwebhookconfigurations"] = mutatingStorage
  61. return storage, err
  62. }
  63. func (p RESTStorageProvider) v1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (map[string]rest.Storage, error) {
  64. storage := map[string]rest.Storage{}
  65. // validatingwebhookconfigurations
  66. validatingStorage, err := validatingwebhookconfigurationstorage.NewREST(restOptionsGetter)
  67. if err != nil {
  68. return storage, err
  69. }
  70. storage["validatingwebhookconfigurations"] = validatingStorage
  71. // mutatingwebhookconfigurations
  72. mutatingStorage, err := mutatingwebhookconfigurationstorage.NewREST(restOptionsGetter)
  73. if err != nil {
  74. return storage, err
  75. }
  76. storage["mutatingwebhookconfigurations"] = mutatingStorage
  77. return storage, err
  78. }
  79. func (p RESTStorageProvider) GroupName() string {
  80. return admissionregistration.GroupName
  81. }