storage_settings.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. networkingapiv1 "k8s.io/api/networking/v1"
  16. networkingapiv1beta1 "k8s.io/api/networking/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/networking"
  23. ingressstore "k8s.io/kubernetes/pkg/registry/networking/ingress/storage"
  24. networkpolicystore "k8s.io/kubernetes/pkg/registry/networking/networkpolicy/storage"
  25. )
  26. type RESTStorageProvider struct{}
  27. func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (genericapiserver.APIGroupInfo, bool) {
  28. apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(networking.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(networkingapiv1.SchemeGroupVersion) {
  32. apiGroupInfo.VersionedResourcesStorageMap[networkingapiv1.SchemeGroupVersion.Version] = p.v1Storage(apiResourceConfigSource, restOptionsGetter)
  33. }
  34. if apiResourceConfigSource.VersionEnabled(networkingapiv1beta1.SchemeGroupVersion) {
  35. apiGroupInfo.VersionedResourcesStorageMap[networkingapiv1beta1.SchemeGroupVersion.Version] = p.v1beta1Storage(apiResourceConfigSource, restOptionsGetter)
  36. }
  37. return apiGroupInfo, true
  38. }
  39. func (p RESTStorageProvider) v1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) map[string]rest.Storage {
  40. storage := map[string]rest.Storage{}
  41. // networkpolicies
  42. networkPolicyStorage := networkpolicystore.NewREST(restOptionsGetter)
  43. storage["networkpolicies"] = networkPolicyStorage
  44. return storage
  45. }
  46. func (p RESTStorageProvider) v1beta1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) map[string]rest.Storage {
  47. storage := map[string]rest.Storage{}
  48. // ingresses
  49. ingressStorage, ingressStatusStorage := ingressstore.NewREST(restOptionsGetter)
  50. storage["ingresses"] = ingressStorage
  51. storage["ingresses/status"] = ingressStatusStorage
  52. return storage
  53. }
  54. func (p RESTStorageProvider) GroupName() string {
  55. return networking.GroupName
  56. }