...

Source file src/k8s.io/kubernetes/pkg/registry/apiserverinternal/storageversion/storage/storage.go

Documentation: k8s.io/kubernetes/pkg/registry/apiserverinternal/storageversion/storage

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

View as plain text