k8s.io/kubernetes@v1.29.3/pkg/registry/resource/podschedulingcontext/storage/storage.go (about) 1 /* 2 Copyright 2022 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 "context" 21 22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 "k8s.io/apimachinery/pkg/runtime" 24 "k8s.io/apiserver/pkg/registry/generic" 25 genericregistry "k8s.io/apiserver/pkg/registry/generic/registry" 26 "k8s.io/apiserver/pkg/registry/rest" 27 "k8s.io/kubernetes/pkg/apis/resource" 28 "k8s.io/kubernetes/pkg/printers" 29 printersinternal "k8s.io/kubernetes/pkg/printers/internalversion" 30 printerstorage "k8s.io/kubernetes/pkg/printers/storage" 31 "k8s.io/kubernetes/pkg/registry/resource/podschedulingcontext" 32 "sigs.k8s.io/structured-merge-diff/v4/fieldpath" 33 ) 34 35 // REST implements a RESTStorage for PodSchedulingContext. 36 type REST struct { 37 *genericregistry.Store 38 } 39 40 // NewREST returns a RESTStorage object that will work against PodSchedulingContext. 41 func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, *StatusREST, error) { 42 store := &genericregistry.Store{ 43 NewFunc: func() runtime.Object { return &resource.PodSchedulingContext{} }, 44 NewListFunc: func() runtime.Object { return &resource.PodSchedulingContextList{} }, 45 PredicateFunc: podschedulingcontext.Match, 46 DefaultQualifiedResource: resource.Resource("podschedulingcontexts"), 47 SingularQualifiedResource: resource.Resource("podschedulingcontext"), 48 49 CreateStrategy: podschedulingcontext.Strategy, 50 UpdateStrategy: podschedulingcontext.Strategy, 51 DeleteStrategy: podschedulingcontext.Strategy, 52 ReturnDeletedObject: true, 53 ResetFieldsStrategy: podschedulingcontext.Strategy, 54 55 TableConvertor: printerstorage.TableConvertor{TableGenerator: printers.NewTableGenerator().With(printersinternal.AddHandlers)}, 56 } 57 options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: podschedulingcontext.GetAttrs} 58 if err := store.CompleteWithOptions(options); err != nil { 59 return nil, nil, err 60 } 61 62 statusStore := *store 63 statusStore.UpdateStrategy = podschedulingcontext.StatusStrategy 64 statusStore.ResetFieldsStrategy = podschedulingcontext.StatusStrategy 65 66 rest := &REST{store} 67 68 return rest, &StatusREST{store: &statusStore}, nil 69 } 70 71 // StatusREST implements the REST endpoint for changing the status of a PodSchedulingContext. 72 type StatusREST struct { 73 store *genericregistry.Store 74 } 75 76 // New creates a new PodSchedulingContext object. 77 func (r *StatusREST) New() runtime.Object { 78 return &resource.PodSchedulingContext{} 79 } 80 81 func (r *StatusREST) Destroy() { 82 // Given that underlying store is shared with REST, 83 // we don't destroy it here explicitly. 84 } 85 86 // Get retrieves the object from the storage. It is required to support Patch. 87 func (r *StatusREST) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) { 88 return r.store.Get(ctx, name, options) 89 } 90 91 // Update alters the status subset of an object. 92 func (r *StatusREST) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) { 93 // We are explicitly setting forceAllowCreate to false in the call to the underlying storage because 94 // subresources should never allow create on update. 95 return r.store.Update(ctx, name, objInfo, createValidation, updateValidation, false, options) 96 } 97 98 // GetResetFields implements rest.ResetFieldsStrategy 99 func (r *StatusREST) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set { 100 return r.store.GetResetFields() 101 }