@@ -65,20 +65,6 @@ func (m *modelBackupPlanAssociation) AdapterForObject(ctx context.Context, reade
65
65
return nil , err
66
66
}
67
67
68
- // normalize reference fields
69
- if obj .Spec .BackupPlanRef != nil {
70
- if _ , err := obj .Spec .BackupPlanRef .NormalizedExternal (ctx , reader , obj .GetNamespace ()); err != nil {
71
- return nil , err
72
- }
73
- }
74
- if obj .Spec .Resource != nil {
75
- if obj .Spec .Resource .ComputeInstanceRef != nil {
76
- if _ , err := obj .Spec .Resource .ComputeInstanceRef .NormalizedExternal (ctx , reader , obj .GetNamespace ()); err != nil {
77
- return nil , err
78
- }
79
- }
80
- }
81
-
82
68
// Get backupdr GCP client
83
69
gcpClient , err := newGCPClient (ctx , & m .config )
84
70
if err != nil {
@@ -136,8 +122,12 @@ func (a *BackupPlanAssociationAdapter) Find(ctx context.Context) (bool, error) {
136
122
func (a * BackupPlanAssociationAdapter ) Create (ctx context.Context , createOp * directbase.CreateOperation ) error {
137
123
log := klog .FromContext (ctx )
138
124
log .V (2 ).Info ("creating BackupPlanAssociation" , "name" , a .id )
139
- mapCtx := & direct.MapContext {}
140
125
126
+ if err := a .normalizeReferenceFields (ctx ); err != nil {
127
+ return err
128
+ }
129
+
130
+ mapCtx := & direct.MapContext {}
141
131
desired := a .desired .DeepCopy ()
142
132
resource := BackupDRBackupPlanAssociationSpec_ToProto (mapCtx , & desired .Spec )
143
133
if mapCtx .Err () != nil {
@@ -180,8 +170,12 @@ func (a *BackupPlanAssociationAdapter) Create(ctx context.Context, createOp *dir
180
170
func (a * BackupPlanAssociationAdapter ) Update (ctx context.Context , updateOp * directbase.UpdateOperation ) error {
181
171
log := klog .FromContext (ctx )
182
172
log .V (2 ).Info ("updating BackupPlan" , "name" , a .id )
183
- mapCtx := & direct.MapContext {}
184
173
174
+ if err := a .normalizeReferenceFields (ctx ); err != nil {
175
+ return err
176
+ }
177
+
178
+ mapCtx := & direct.MapContext {}
185
179
desired := a .desired .DeepCopy ()
186
180
resource := BackupDRBackupPlanAssociationSpec_ToProto (mapCtx , & desired .Spec )
187
181
if mapCtx .Err () != nil {
@@ -263,3 +257,22 @@ func (a *BackupPlanAssociationAdapter) Delete(ctx context.Context, deleteOp *dir
263
257
}
264
258
return true , nil
265
259
}
260
+
261
+ func (a * BackupPlanAssociationAdapter ) normalizeReferenceFields (ctx context.Context ) error {
262
+ obj := a .desired
263
+
264
+ if obj .Spec .BackupPlanRef != nil {
265
+ if _ , err := obj .Spec .BackupPlanRef .NormalizedExternal (ctx , a .reader , obj .GetNamespace ()); err != nil {
266
+ return err
267
+ }
268
+ }
269
+ if obj .Spec .Resource != nil {
270
+ if obj .Spec .Resource .ComputeInstanceRef != nil {
271
+ if _ , err := obj .Spec .Resource .ComputeInstanceRef .NormalizedExternal (ctx , a .reader , obj .GetNamespace ()); err != nil {
272
+ return err
273
+ }
274
+ }
275
+ }
276
+
277
+ return nil
278
+ }
0 commit comments