...
1
16
17 package volumeattachment
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/storage"
28 "k8s.io/kubernetes/pkg/apis/storage/validation"
29 "sigs.k8s.io/structured-merge-diff/v4/fieldpath"
30 )
31
32
33 type volumeAttachmentStrategy struct {
34 runtime.ObjectTyper
35 names.NameGenerator
36 }
37
38
39
40 var Strategy = volumeAttachmentStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
41
42 func (volumeAttachmentStrategy) NamespaceScoped() bool {
43 return false
44 }
45
46
47
48 func (volumeAttachmentStrategy) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set {
49 fields := map[fieldpath.APIVersion]*fieldpath.Set{
50 "storage.k8s.io/v1": fieldpath.NewSet(
51 fieldpath.MakePathOrDie("status"),
52 ),
53 }
54
55 return fields
56 }
57
58
59 func (volumeAttachmentStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
60 volumeAttachment := obj.(*storage.VolumeAttachment)
61 volumeAttachment.Status = storage.VolumeAttachmentStatus{}
62 }
63
64 func (volumeAttachmentStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
65 volumeAttachment := obj.(*storage.VolumeAttachment)
66
67 errs := validation.ValidateVolumeAttachment(volumeAttachment)
68
69
70 errs = append(errs, validation.ValidateVolumeAttachmentV1(volumeAttachment)...)
71 return errs
72 }
73
74
75 func (volumeAttachmentStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
76 return nil
77 }
78
79
80 func (volumeAttachmentStrategy) Canonicalize(obj runtime.Object) {
81 }
82
83 func (volumeAttachmentStrategy) AllowCreateOnUpdate() bool {
84 return false
85 }
86
87
88 func (volumeAttachmentStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
89 newVolumeAttachment := obj.(*storage.VolumeAttachment)
90 oldVolumeAttachment := old.(*storage.VolumeAttachment)
91
92 newVolumeAttachment.Status = oldVolumeAttachment.Status
93
94
95 }
96
97 func (volumeAttachmentStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
98 newVolumeAttachmentObj := obj.(*storage.VolumeAttachment)
99 oldVolumeAttachmentObj := old.(*storage.VolumeAttachment)
100 errorList := validation.ValidateVolumeAttachment(newVolumeAttachmentObj)
101 return append(errorList, validation.ValidateVolumeAttachmentUpdate(newVolumeAttachmentObj, oldVolumeAttachmentObj)...)
102 }
103
104
105 func (volumeAttachmentStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
106 return nil
107 }
108
109 func (volumeAttachmentStrategy) AllowUnconditionalUpdate() bool {
110 return false
111 }
112
113
114 type volumeAttachmentStatusStrategy struct {
115 volumeAttachmentStrategy
116 }
117
118
119
120 var StatusStrategy = volumeAttachmentStatusStrategy{Strategy}
121
122
123
124 func (volumeAttachmentStatusStrategy) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set {
125 fields := map[fieldpath.APIVersion]*fieldpath.Set{
126 "storage.k8s.io/v1": fieldpath.NewSet(
127 fieldpath.MakePathOrDie("metadata"),
128 fieldpath.MakePathOrDie("spec"),
129 ),
130 }
131
132 return fields
133 }
134
135
136 func (volumeAttachmentStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
137 newVolumeAttachment := obj.(*storage.VolumeAttachment)
138 oldVolumeAttachment := old.(*storage.VolumeAttachment)
139
140 newVolumeAttachment.Spec = oldVolumeAttachment.Spec
141 metav1.ResetObjectMetaForStatus(&newVolumeAttachment.ObjectMeta, &oldVolumeAttachment.ObjectMeta)
142 }
143
View as plain text