k8s.io/kubernetes@v1.29.3/pkg/registry/coordination/lease/storage/storage.go (about) 1 /* 2 Copyright 2018 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 coordinationapi "k8s.io/kubernetes/pkg/apis/coordination" 24 "k8s.io/kubernetes/pkg/printers" 25 printersinternal "k8s.io/kubernetes/pkg/printers/internalversion" 26 printerstorage "k8s.io/kubernetes/pkg/printers/storage" 27 "k8s.io/kubernetes/pkg/registry/coordination/lease" 28 ) 29 30 // REST implements a RESTStorage for leases against etcd 31 type REST struct { 32 *genericregistry.Store 33 } 34 35 // NewREST returns a RESTStorage object that will work against leases. 36 func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) { 37 store := &genericregistry.Store{ 38 NewFunc: func() runtime.Object { return &coordinationapi.Lease{} }, 39 NewListFunc: func() runtime.Object { return &coordinationapi.LeaseList{} }, 40 DefaultQualifiedResource: coordinationapi.Resource("leases"), 41 SingularQualifiedResource: coordinationapi.Resource("lease"), 42 43 CreateStrategy: lease.Strategy, 44 UpdateStrategy: lease.Strategy, 45 DeleteStrategy: lease.Strategy, 46 47 TableConvertor: printerstorage.TableConvertor{TableGenerator: printers.NewTableGenerator().With(printersinternal.AddHandlers)}, 48 } 49 options := &generic.StoreOptions{RESTOptions: optsGetter} 50 if err := store.CompleteWithOptions(options); err != nil { 51 return nil, err 52 } 53 54 return &REST{store}, nil 55 }