Skip to content

Commit 3ee8854

Browse files
committed
BackupDRBackupPlanAssociation: resolve reference fields
1 parent 12ed2ec commit 3ee8854

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

pkg/controller/direct/backupdr/backupplanassociation_controller.go

+29-16
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,6 @@ func (m *modelBackupPlanAssociation) AdapterForObject(ctx context.Context, reade
6565
return nil, err
6666
}
6767

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-
8268
// Get backupdr GCP client
8369
gcpClient, err := newGCPClient(ctx, &m.config)
8470
if err != nil {
@@ -136,8 +122,12 @@ func (a *BackupPlanAssociationAdapter) Find(ctx context.Context) (bool, error) {
136122
func (a *BackupPlanAssociationAdapter) Create(ctx context.Context, createOp *directbase.CreateOperation) error {
137123
log := klog.FromContext(ctx)
138124
log.V(2).Info("creating BackupPlanAssociation", "name", a.id)
139-
mapCtx := &direct.MapContext{}
140125

126+
if err := a.normalizeReferenceFields(ctx); err != nil {
127+
return err
128+
}
129+
130+
mapCtx := &direct.MapContext{}
141131
desired := a.desired.DeepCopy()
142132
resource := BackupDRBackupPlanAssociationSpec_ToProto(mapCtx, &desired.Spec)
143133
if mapCtx.Err() != nil {
@@ -180,8 +170,12 @@ func (a *BackupPlanAssociationAdapter) Create(ctx context.Context, createOp *dir
180170
func (a *BackupPlanAssociationAdapter) Update(ctx context.Context, updateOp *directbase.UpdateOperation) error {
181171
log := klog.FromContext(ctx)
182172
log.V(2).Info("updating BackupPlan", "name", a.id)
183-
mapCtx := &direct.MapContext{}
184173

174+
if err := a.normalizeReferenceFields(ctx); err != nil {
175+
return err
176+
}
177+
178+
mapCtx := &direct.MapContext{}
185179
desired := a.desired.DeepCopy()
186180
resource := BackupDRBackupPlanAssociationSpec_ToProto(mapCtx, &desired.Spec)
187181
if mapCtx.Err() != nil {
@@ -263,3 +257,22 @@ func (a *BackupPlanAssociationAdapter) Delete(ctx context.Context, deleteOp *dir
263257
}
264258
return true, nil
265259
}
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

Comments
 (0)