k8s.io/kubernetes@v1.29.3/pkg/registry/policy/rest/storage_policy.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package rest 18 19 import ( 20 policyapiv1 "k8s.io/api/policy/v1" 21 "k8s.io/apiserver/pkg/registry/generic" 22 "k8s.io/apiserver/pkg/registry/rest" 23 genericapiserver "k8s.io/apiserver/pkg/server" 24 serverstorage "k8s.io/apiserver/pkg/server/storage" 25 "k8s.io/kubernetes/pkg/api/legacyscheme" 26 "k8s.io/kubernetes/pkg/apis/policy" 27 poddisruptionbudgetstore "k8s.io/kubernetes/pkg/registry/policy/poddisruptionbudget/storage" 28 ) 29 30 type RESTStorageProvider struct{} 31 32 func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (genericapiserver.APIGroupInfo, error) { 33 apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(policy.GroupName, legacyscheme.Scheme, legacyscheme.ParameterCodec, legacyscheme.Codecs) 34 // 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. 35 // TODO refactor the plumbing to provide the information in the APIGroupInfo 36 37 if storageMap, err := p.v1Storage(apiResourceConfigSource, restOptionsGetter); err != nil { 38 return genericapiserver.APIGroupInfo{}, err 39 } else if len(storageMap) > 0 { 40 apiGroupInfo.VersionedResourcesStorageMap[policyapiv1.SchemeGroupVersion.Version] = storageMap 41 } 42 43 return apiGroupInfo, nil 44 } 45 46 func (p RESTStorageProvider) v1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (map[string]rest.Storage, error) { 47 storage := map[string]rest.Storage{} 48 49 if resource := "poddisruptionbudgets"; apiResourceConfigSource.ResourceEnabled(policyapiv1.SchemeGroupVersion.WithResource(resource)) { 50 poddisruptionbudgetStorage, poddisruptionbudgetStatusStorage, err := poddisruptionbudgetstore.NewREST(restOptionsGetter) 51 if err != nil { 52 return storage, err 53 } 54 storage[resource] = poddisruptionbudgetStorage 55 storage[resource+"/status"] = poddisruptionbudgetStatusStorage 56 } 57 58 return storage, nil 59 } 60 61 func (p RESTStorageProvider) GroupName() string { 62 return policy.GroupName 63 }