From 05ab993d3da6aaae92b566e25adf3b83db09acd3 Mon Sep 17 00:00:00 2001 From: Artem Chernyshev Date: Tue, 12 Nov 2024 18:42:14 +0300 Subject: [PATCH] fix: properly map config patch requests in the infra provision ctrl The bug was causing missing reconciliations. Signed-off-by: Artem Chernyshev --- client/pkg/infra/controllers/provision.go | 37 +++++++++++++++++++---- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/client/pkg/infra/controllers/provision.go b/client/pkg/infra/controllers/provision.go index eab892e3a..f5beee5c0 100644 --- a/client/pkg/infra/controllers/provision.go +++ b/client/pkg/infra/controllers/provision.go @@ -106,16 +106,41 @@ func (ctrl *ProvisionController[T]) Settings() controller.QSettings { } // MapInput implements controller.QController interface. -func (ctrl *ProvisionController[T]) MapInput(_ context.Context, _ *zap.Logger, - _ controller.QRuntime, ptr resource.Pointer, +func (ctrl *ProvisionController[T]) MapInput(ctx context.Context, _ *zap.Logger, + r controller.QRuntime, ptr resource.Pointer, ) ([]resource.Pointer, error) { - if ptr.Type() == siderolink.ConnectionParamsType { + var t T + + switch ptr.Type() { + case siderolink.ConnectionParamsType: return nil, nil + case infra.ConfigPatchRequestType: + configPatchRequest, err := safe.ReaderGetByID[*infra.ConfigPatchRequest](ctx, r, ptr.ID()) + if err != nil { + if state.IsNotFoundError(err) { + return nil, nil + } + + return nil, err + } + + id, ok := configPatchRequest.Metadata().Labels().Get(omni.LabelMachineRequest) + if !ok { + return nil, err + } + + return []resource.Pointer{ + infra.NewMachineRequest(id).Metadata(), + }, nil + case infra.MachineRequestType, + infra.MachineRequestStatusType, + t.ResourceDefinition().Type: + return []resource.Pointer{ + infra.NewMachineRequest(ptr.ID()).Metadata(), + }, nil } - return []resource.Pointer{ - infra.NewMachineRequest(ptr.ID()).Metadata(), - }, nil + return nil, fmt.Errorf("got unexpected type %s", ptr.Type()) } // Reconcile implements controller.QController interface.