k8s.io/kubernetes@v1.29.3/pkg/registry/admissionregistration/validatingwebhookconfiguration/storage/storage.go (about) 1 /* 2 Copyright 2015 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 storage 18 19 import ( 20 "k8s.io/apimachinery/pkg/runtime" 21 "k8s.io/apiserver/pkg/registry/generic" 22 genericregistry "k8s.io/apiserver/pkg/registry/generic/registry" 23 "k8s.io/apiserver/pkg/registry/rest" 24 "k8s.io/kubernetes/pkg/apis/admissionregistration" 25 "k8s.io/kubernetes/pkg/printers" 26 printersinternal "k8s.io/kubernetes/pkg/printers/internalversion" 27 printerstorage "k8s.io/kubernetes/pkg/printers/storage" 28 "k8s.io/kubernetes/pkg/registry/admissionregistration/validatingwebhookconfiguration" 29 ) 30 31 // REST implements a RESTStorage for validatingWebhookConfiguration against etcd 32 type REST struct { 33 *genericregistry.Store 34 } 35 36 // NewREST returns a RESTStorage object that will work against validatingWebhookConfiguration. 37 func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) { 38 store := &genericregistry.Store{ 39 NewFunc: func() runtime.Object { return &admissionregistration.ValidatingWebhookConfiguration{} }, 40 NewListFunc: func() runtime.Object { return &admissionregistration.ValidatingWebhookConfigurationList{} }, 41 ObjectNameFunc: func(obj runtime.Object) (string, error) { 42 return obj.(*admissionregistration.ValidatingWebhookConfiguration).Name, nil 43 }, 44 DefaultQualifiedResource: admissionregistration.Resource("validatingwebhookconfigurations"), 45 SingularQualifiedResource: admissionregistration.Resource("validatingwebhookconfiguration"), 46 47 CreateStrategy: validatingwebhookconfiguration.Strategy, 48 UpdateStrategy: validatingwebhookconfiguration.Strategy, 49 DeleteStrategy: validatingwebhookconfiguration.Strategy, 50 51 TableConvertor: printerstorage.TableConvertor{TableGenerator: printers.NewTableGenerator().With(printersinternal.AddHandlers)}, 52 } 53 options := &generic.StoreOptions{RESTOptions: optsGetter} 54 if err := store.CompleteWithOptions(options); err != nil { 55 return nil, err 56 } 57 return &REST{store}, nil 58 } 59 60 // Implement CategoriesProvider 61 var _ rest.CategoriesProvider = &REST{} 62 63 // Categories implements the CategoriesProvider interface. Returns a list of categories a resource is part of. 64 func (r *REST) Categories() []string { 65 return []string{"api-extensions"} 66 }