storage_certificates.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. certificatesapiv1beta1 "k8s.io/api/certificates/v1beta1"
  16. "k8s.io/apiserver/pkg/registry/generic"
  17. "k8s.io/apiserver/pkg/registry/rest"
  18. genericapiserver "k8s.io/apiserver/pkg/server"
  19. serverstorage "k8s.io/apiserver/pkg/server/storage"
  20. "k8s.io/kubernetes/pkg/api/legacyscheme"
  21. "k8s.io/kubernetes/pkg/apis/certificates"
  22. certificatestore "k8s.io/kubernetes/pkg/registry/certificates/certificates/storage"
  23. )
  24. type RESTStorageProvider struct{}
  25. func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (genericapiserver.APIGroupInfo, bool, error) {
  26. apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(certificates.GroupName, legacyscheme.Scheme, legacyscheme.ParameterCodec, legacyscheme.Codecs)
  27. // 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.
  28. // TODO refactor the plumbing to provide the information in the APIGroupInfo
  29. if apiResourceConfigSource.VersionEnabled(certificatesapiv1beta1.SchemeGroupVersion) {
  30. if storageMap, err := p.v1beta1Storage(apiResourceConfigSource, restOptionsGetter); err != nil {
  31. return genericapiserver.APIGroupInfo{}, false, err
  32. } else {
  33. apiGroupInfo.VersionedResourcesStorageMap[certificatesapiv1beta1.SchemeGroupVersion.Version] = storageMap
  34. }
  35. }
  36. return apiGroupInfo, true, nil
  37. }
  38. func (p RESTStorageProvider) v1beta1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (map[string]rest.Storage, error) {
  39. storage := map[string]rest.Storage{}
  40. // certificatesigningrequests
  41. csrStorage, csrStatusStorage, csrApprovalStorage, err := certificatestore.NewREST(restOptionsGetter)
  42. if err != nil {
  43. return storage, err
  44. }
  45. storage["certificatesigningrequests"] = csrStorage
  46. storage["certificatesigningrequests/status"] = csrStatusStorage
  47. storage["certificatesigningrequests/approval"] = csrApprovalStorage
  48. return storage, err
  49. }
  50. func (p RESTStorageProvider) GroupName() string {
  51. return certificates.GroupName
  52. }