...
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 policyapi "k8s.io/kubernetes/pkg/apis/policy"
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/policy/poddisruptionbudget"
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 &policyapi.PodDisruptionBudget{} },
44 NewListFunc: func() runtime.Object { return &policyapi.PodDisruptionBudgetList{} },
45 DefaultQualifiedResource: policyapi.Resource("poddisruptionbudgets"),
46 SingularQualifiedResource: policyapi.Resource("poddisruptionbudget"),
47
48 CreateStrategy: poddisruptionbudget.Strategy,
49 UpdateStrategy: poddisruptionbudget.Strategy,
50 DeleteStrategy: poddisruptionbudget.Strategy,
51 ResetFieldsStrategy: poddisruptionbudget.Strategy,
52
53 TableConvertor: printerstorage.TableConvertor{TableGenerator: printers.NewTableGenerator().With(printersinternal.AddHandlers)},
54 }
55 options := &generic.StoreOptions{RESTOptions: optsGetter}
56 if err := store.CompleteWithOptions(options); err != nil {
57 return nil, nil, err
58 }
59
60 statusStore := *store
61 statusStore.UpdateStrategy = poddisruptionbudget.StatusStrategy
62 statusStore.ResetFieldsStrategy = poddisruptionbudget.StatusStrategy
63 return &REST{store}, &StatusREST{store: &statusStore}, nil
64 }
65
66
67 func (r *REST) ShortNames() []string {
68 return []string{"pdb"}
69 }
70
71
72 type StatusREST struct {
73 store *genericregistry.Store
74 }
75
76
77 func (r *StatusREST) New() runtime.Object {
78 return &policyapi.PodDisruptionBudget{}
79 }
80
81
82 func (r *StatusREST) Destroy() {
83
84
85 }
86
87
88 func (r *StatusREST) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
89 return r.store.Get(ctx, name, options)
90 }
91
92
93 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) {
94
95
96 return r.store.Update(ctx, name, objInfo, createValidation, updateValidation, false, options)
97 }
98
99
100 func (r *StatusREST) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set {
101 return r.store.GetResetFields()
102 }
103
104 func (r *StatusREST) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
105 return r.store.ConvertToTable(ctx, object, tableOptions)
106 }
107
View as plain text