@@ -62,7 +62,7 @@ type LegacyStorage interface {
62
62
// - rest.CollectionDeleter
63
63
type DualWriter struct {
64
64
Storage
65
- legacy LegacyStorage
65
+ Legacy LegacyStorage
66
66
}
67
67
68
68
type DualWriterMode int
@@ -80,15 +80,17 @@ var CurrentMode = Mode2
80
80
81
81
// NewDualWriter returns a new DualWriter.
82
82
func NewDualWriter (legacy LegacyStorage , storage Storage ) * DualWriter {
83
+ //TODO: replace this with
84
+ // SelectDualWriter(CurrentMode, legacy, storage)
83
85
return & DualWriter {
84
86
Storage : storage ,
85
- legacy : legacy ,
87
+ Legacy : legacy ,
86
88
}
87
89
}
88
90
89
91
// Create overrides the default behavior of the Storage and writes to both the LegacyStorage and Storage.
90
92
func (d * DualWriter ) Create (ctx context.Context , obj runtime.Object , createValidation rest.ValidateObjectFunc , options * metav1.CreateOptions ) (runtime.Object , error ) {
91
- if legacy , ok := d .legacy .(rest.Creater ); ok {
93
+ if legacy , ok := d .Legacy .(rest.Creater ); ok {
92
94
created , err := legacy .Create (ctx , obj , createValidation , options )
93
95
if err != nil {
94
96
return nil , err
@@ -113,7 +115,7 @@ func (d *DualWriter) Create(ctx context.Context, obj runtime.Object, createValid
113
115
114
116
// Update overrides the default behavior of the Storage and writes to both the LegacyStorage and Storage.
115
117
func (d * DualWriter ) Update (ctx context.Context , name string , objInfo rest.UpdatedObjectInfo , createValidation rest.ValidateObjectFunc , updateValidation rest.ValidateObjectUpdateFunc , forceAllowCreate bool , options * metav1.UpdateOptions ) (runtime.Object , bool , error ) {
116
- if legacy , ok := d .legacy .(rest.Updater ); ok {
118
+ if legacy , ok := d .Legacy .(rest.Updater ); ok {
117
119
// Get the previous version from k8s storage (the one)
118
120
old , err := d .Get (ctx , name , & metav1.GetOptions {})
119
121
if err != nil {
@@ -168,7 +170,7 @@ func (d *DualWriter) Delete(ctx context.Context, name string, deleteValidation r
168
170
// Delete from storage *first* so the item is still exists if a failure happens
169
171
obj , async , err := d .Storage .Delete (ctx , name , deleteValidation , options )
170
172
if err == nil {
171
- if legacy , ok := d .legacy .(rest.GracefulDeleter ); ok {
173
+ if legacy , ok := d .Legacy .(rest.GracefulDeleter ); ok {
172
174
obj , async , err = legacy .Delete (ctx , name , deleteValidation , options )
173
175
}
174
176
}
@@ -179,7 +181,7 @@ func (d *DualWriter) Delete(ctx context.Context, name string, deleteValidation r
179
181
func (d * DualWriter ) DeleteCollection (ctx context.Context , deleteValidation rest.ValidateObjectFunc , options * metav1.DeleteOptions , listOptions * metainternalversion.ListOptions ) (runtime.Object , error ) {
180
182
out , err := d .Storage .DeleteCollection (ctx , deleteValidation , options , listOptions )
181
183
if err == nil {
182
- if legacy , ok := d .legacy .(rest.CollectionDeleter ); ok {
184
+ if legacy , ok := d .Legacy .(rest.CollectionDeleter ); ok {
183
185
out , err = legacy .DeleteCollection (ctx , deleteValidation , options , listOptions )
184
186
}
185
187
}
0 commit comments