...

Source file src/k8s.io/kubernetes/pkg/registry/flowcontrol/prioritylevelconfiguration/storage/storage.go

Documentation: k8s.io/kubernetes/pkg/registry/flowcontrol/prioritylevelconfiguration/storage

     1  /*
     2  Copyright 2019 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/flowcontrol"
    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/flowcontrol/prioritylevelconfiguration"
    32  	"sigs.k8s.io/structured-merge-diff/v4/fieldpath"
    33  )
    34  
    35  // PriorityLevelConfigurationStorage implements storage for priority level configuration.
    36  type PriorityLevelConfigurationStorage struct {
    37  	PriorityLevelConfiguration *REST
    38  	Status                     *StatusREST
    39  }
    40  
    41  // REST implements a RESTStorage for priority level configuration against etcd
    42  type REST struct {
    43  	*genericregistry.Store
    44  }
    45  
    46  // NewREST returns a RESTStorage object that will work against priority level configuration.
    47  func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, *StatusREST, error) {
    48  	store := &genericregistry.Store{
    49  		NewFunc:                   func() runtime.Object { return &flowcontrol.PriorityLevelConfiguration{} },
    50  		NewListFunc:               func() runtime.Object { return &flowcontrol.PriorityLevelConfigurationList{} },
    51  		DefaultQualifiedResource:  flowcontrol.Resource("prioritylevelconfigurations"),
    52  		SingularQualifiedResource: flowcontrol.Resource("prioritylevelconfiguration"),
    53  
    54  		CreateStrategy:      prioritylevelconfiguration.Strategy,
    55  		UpdateStrategy:      prioritylevelconfiguration.Strategy,
    56  		DeleteStrategy:      prioritylevelconfiguration.Strategy,
    57  		ResetFieldsStrategy: prioritylevelconfiguration.Strategy,
    58  
    59  		TableConvertor: printerstorage.TableConvertor{TableGenerator: printers.NewTableGenerator().With(printersinternal.AddHandlers)},
    60  	}
    61  	options := &generic.StoreOptions{RESTOptions: optsGetter}
    62  	if err := store.CompleteWithOptions(options); err != nil {
    63  		return nil, nil, err
    64  	}
    65  
    66  	statusStore := *store
    67  	statusStore.CreateStrategy = nil
    68  	statusStore.UpdateStrategy = prioritylevelconfiguration.StatusStrategy
    69  	statusStore.DeleteStrategy = nil
    70  	statusStore.ResetFieldsStrategy = prioritylevelconfiguration.StatusStrategy
    71  
    72  	return &REST{store}, &StatusREST{store: &statusStore}, nil
    73  }
    74  
    75  // StatusREST implements the REST endpoint for changing the status of a priority level configuration.
    76  type StatusREST struct {
    77  	store *genericregistry.Store
    78  }
    79  
    80  // New creates a new priority level configuration object.
    81  func (r *StatusREST) New() runtime.Object {
    82  	return &flowcontrol.PriorityLevelConfiguration{}
    83  }
    84  
    85  // Destroy cleans up resources on shutdown.
    86  func (r *StatusREST) Destroy() {
    87  	// Given that underlying store is shared with REST,
    88  	// we don't destroy it here explicitly.
    89  }
    90  
    91  // Get retrieves the object from the storage. It is required to support Patch.
    92  func (r *StatusREST) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
    93  	return r.store.Get(ctx, name, options)
    94  }
    95  
    96  // Update alters the status subset of an object.
    97  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) {
    98  	// We are explicitly setting forceAllowCreate to false in the call to the underlying storage because
    99  	// subresources should never allow create on update.
   100  	return r.store.Update(ctx, name, objInfo, createValidation, updateValidation, false, options)
   101  }
   102  
   103  // GetResetFields implements rest.ResetFieldsStrategy
   104  func (r *StatusREST) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set {
   105  	return r.store.GetResetFields()
   106  }
   107  
   108  func (r *StatusREST) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
   109  	return r.store.ConvertToTable(ctx, object, tableOptions)
   110  }
   111  

View as plain text