...
1
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 api "k8s.io/kubernetes/pkg/apis/core"
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/core/persistentvolume"
32 "sigs.k8s.io/structured-merge-diff/v4/fieldpath"
33 )
34
35
36 type REST struct {
37 *genericregistry.Store
38 }
39
40
41 func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, *StatusREST, error) {
42 store := &genericregistry.Store{
43 NewFunc: func() runtime.Object { return &api.PersistentVolume{} },
44 NewListFunc: func() runtime.Object { return &api.PersistentVolumeList{} },
45 PredicateFunc: persistentvolume.MatchPersistentVolumes,
46 DefaultQualifiedResource: api.Resource("persistentvolumes"),
47 SingularQualifiedResource: api.Resource("persistentvolume"),
48
49 CreateStrategy: persistentvolume.Strategy,
50 UpdateStrategy: persistentvolume.Strategy,
51 DeleteStrategy: persistentvolume.Strategy,
52 ReturnDeletedObject: true,
53 ResetFieldsStrategy: persistentvolume.Strategy,
54
55 TableConvertor: printerstorage.TableConvertor{TableGenerator: printers.NewTableGenerator().With(printersinternal.AddHandlers)},
56 }
57 options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: persistentvolume.GetAttrs}
58 if err := store.CompleteWithOptions(options); err != nil {
59 return nil, nil, err
60 }
61
62 statusStore := *store
63 statusStore.UpdateStrategy = persistentvolume.StatusStrategy
64 statusStore.ResetFieldsStrategy = persistentvolume.StatusStrategy
65
66 return &REST{store}, &StatusREST{store: &statusStore}, nil
67 }
68
69
70 var _ rest.ShortNamesProvider = &REST{}
71
72
73 func (r *REST) ShortNames() []string {
74 return []string{"pv"}
75 }
76
77
78 type StatusREST struct {
79 store *genericregistry.Store
80 }
81
82
83 func (r *StatusREST) New() runtime.Object {
84 return &api.PersistentVolume{}
85 }
86
87
88 func (r *StatusREST) Destroy() {
89
90
91 }
92
93
94 func (r *StatusREST) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
95 return r.store.Get(ctx, name, options)
96 }
97
98
99 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) {
100
101
102 return r.store.Update(ctx, name, objInfo, createValidation, updateValidation, false, options)
103 }
104
105
106 func (r *StatusREST) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set {
107 return r.store.GetResetFields()
108 }
109
110 func (r *StatusREST) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
111 return r.store.ConvertToTable(ctx, object, tableOptions)
112 }
113
View as plain text