...
1
16
17 package storageversion
18
19 import (
20 "context"
21
22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23 "k8s.io/apimachinery/pkg/runtime"
24 "k8s.io/apimachinery/pkg/util/validation/field"
25 "k8s.io/apiserver/pkg/storage/names"
26 "k8s.io/kubernetes/pkg/api/legacyscheme"
27 "k8s.io/kubernetes/pkg/apis/apiserverinternal"
28 "k8s.io/kubernetes/pkg/apis/apiserverinternal/validation"
29 "sigs.k8s.io/structured-merge-diff/v4/fieldpath"
30 )
31
32
33 type storageVersionStrategy struct {
34 runtime.ObjectTyper
35 names.NameGenerator
36 }
37
38
39 var Strategy = storageVersionStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
40
41
42 func (storageVersionStrategy) NamespaceScoped() bool {
43 return false
44 }
45
46
47
48 func (storageVersionStrategy) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set {
49 fields := map[fieldpath.APIVersion]*fieldpath.Set{
50 "internal.apiserver.k8s.io/v1alpha1": fieldpath.NewSet(
51 fieldpath.MakePathOrDie("status"),
52 ),
53 }
54
55 return fields
56 }
57
58
59 func (storageVersionStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
60 sv := obj.(*apiserverinternal.StorageVersion)
61 sv.Status = apiserverinternal.StorageVersionStatus{}
62 }
63
64
65 func (storageVersionStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
66 sv := obj.(*apiserverinternal.StorageVersion)
67 sv.Status = old.(*apiserverinternal.StorageVersion).Status
68 }
69
70
71 func (storageVersionStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
72 sv := obj.(*apiserverinternal.StorageVersion)
73 return validation.ValidateStorageVersion(sv)
74 }
75
76
77 func (storageVersionStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
78 return nil
79 }
80
81
82 func (storageVersionStrategy) Canonicalize(obj runtime.Object) {
83 }
84
85
86 func (storageVersionStrategy) AllowCreateOnUpdate() bool {
87 return false
88 }
89
90
91 func (storageVersionStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
92 newStorageVersion := obj.(*apiserverinternal.StorageVersion)
93 oldStorageVersion := old.(*apiserverinternal.StorageVersion)
94 validationErrorList := validation.ValidateStorageVersionUpdate(newStorageVersion, oldStorageVersion)
95 return validationErrorList
96 }
97
98
99 func (storageVersionStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
100 return nil
101 }
102
103
104
105 func (storageVersionStrategy) AllowUnconditionalUpdate() bool {
106 return false
107 }
108
109 type storageVersionStatusStrategy struct {
110 storageVersionStrategy
111 }
112
113
114 var StatusStrategy = storageVersionStatusStrategy{Strategy}
115
116
117
118 func (storageVersionStatusStrategy) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set {
119 fields := map[fieldpath.APIVersion]*fieldpath.Set{
120 "internal.apiserver.k8s.io/v1alpha1": fieldpath.NewSet(
121 fieldpath.MakePathOrDie("metadata"),
122 fieldpath.MakePathOrDie("spec"),
123 ),
124 }
125
126 return fields
127 }
128
129 func (storageVersionStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
130 newSV := obj.(*apiserverinternal.StorageVersion)
131 oldSV := old.(*apiserverinternal.StorageVersion)
132
133 newSV.Spec = oldSV.Spec
134 metav1.ResetObjectMetaForStatus(&newSV.ObjectMeta, &oldSV.ObjectMeta)
135 }
136
137 func (storageVersionStatusStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
138 return validation.ValidateStorageVersionStatusUpdate(obj.(*apiserverinternal.StorageVersion), old.(*apiserverinternal.StorageVersion))
139 }
140
141
142 func (storageVersionStatusStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
143 return nil
144 }
145
View as plain text