From 82bdd9b7d43191f9d047502e2182516e69d4f4a9 Mon Sep 17 00:00:00 2001 From: Jason Collins Date: Tue, 12 Jul 2022 06:36:49 -0700 Subject: [PATCH] APIGOV-23133 - send status update call even if subresource update failed --- pkg/agent/handler/accessrequest.go | 15 +++++++++------ pkg/agent/handler/credential.go | 15 +++++++++++---- pkg/agent/handler/managedapplication.go | 14 +++++++++++--- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/pkg/agent/handler/accessrequest.go b/pkg/agent/handler/accessrequest.go index cf7f282ff..4863e389a 100644 --- a/pkg/agent/handler/accessrequest.go +++ b/pkg/agent/handler/accessrequest.go @@ -49,6 +49,7 @@ func (h *accessRequestHandler) Handle(ctx context.Context, meta *proto.EventMeta } log := getLoggerFromContext(ctx).WithComponent("accessRequestHandler") + defer log.Trace("finished processing request") ctx = setLoggerInContext(ctx, log) ar := &mv1.AccessRequest{} @@ -74,13 +75,16 @@ func (h *accessRequestHandler) Handle(ctx context.Context, meta *proto.EventMeta err := h.client.CreateSubResource(ar.ResourceMeta, ar.SubResources) if err != nil { log.WithError(err).Error("error creating subresources") - return err } - err = h.client.CreateSubResource(ar.ResourceMeta, map[string]interface{}{"status": ar.Status}) - if err != nil { - log.WithError(err).Error("error creating status subresources") - return err + + // update the status regardless of errors updating the other subresources + statusErr := h.client.CreateSubResource(ar.ResourceMeta, map[string]interface{}{"status": ar.Status}) + if statusErr != nil { + log.WithError(statusErr).Error("error creating status subresources") + return statusErr } + + return err } if ok := shouldProcessDeleting(ar.Status.Level, ar.Metadata.State, len(ar.Finalizers)); ok { @@ -88,7 +92,6 @@ func (h *accessRequestHandler) Handle(ctx context.Context, meta *proto.EventMeta h.onDeleting(ctx, ar) } - log.Trace("finished processing request") return nil } diff --git a/pkg/agent/handler/credential.go b/pkg/agent/handler/credential.go index f5a2b89d3..2b527c6d0 100644 --- a/pkg/agent/handler/credential.go +++ b/pkg/agent/handler/credential.go @@ -69,14 +69,21 @@ func (h *credentials) Handle(ctx context.Context, meta *proto.EventMeta, resourc } if ok := shouldProcessPending(cr.Status.Level, cr.Metadata.State); ok { - logger.Tracef("processing resource in pending status") - cr := h.onPending(ctx, cr) + log.Trace("processing resource in pending status") + ar := h.onPending(ctx, cr) err := h.client.CreateSubResource(cr.ResourceMeta, cr.SubResources) if err != nil { logger.WithError(err).Error("error creating subresources") - return err } - return h.client.CreateSubResource(cr.ResourceMeta, map[string]interface{}{"status": cr.Status}) + + // update the status regardless of errors updating the other subresources + statusErr := h.client.CreateSubResource(ar.ResourceMeta, map[string]interface{}{"status": ar.Status}) + if statusErr != nil { + logger.WithError(statusErr).Error("error creating status subresources") + return statusErr + } + + return err } if ok := shouldProcessDeleting(cr.Status.Level, cr.Metadata.State, len(cr.Finalizers)); ok { diff --git a/pkg/agent/handler/managedapplication.go b/pkg/agent/handler/managedapplication.go index c65c2bd6b..27fc865c5 100644 --- a/pkg/agent/handler/managedapplication.go +++ b/pkg/agent/handler/managedapplication.go @@ -79,7 +79,8 @@ func (h *managedApplication) Handle(ctx context.Context, meta *proto.EventMeta, return nil } -func (h *managedApplication) onPending(_ context.Context, app *mv1.ManagedApplication, pma provManagedApp) error { +func (h *managedApplication) onPending(ctx context.Context, app *mv1.ManagedApplication, pma provManagedApp) error { + log := getLoggerFromContext(ctx) status := h.prov.ApplicationRequestProvision(pma) app.Status = prov.NewStatusReason(status) @@ -100,9 +101,16 @@ func (h *managedApplication) onPending(_ context.Context, app *mv1.ManagedApplic err := h.client.CreateSubResource(app.ResourceMeta, app.SubResources) if err != nil { - return err + log.WithError(err).Error("error creating subresources") + } + + statusErr := h.client.CreateSubResource(app.ResourceMeta, map[string]interface{}{"status": app.Status}) + if statusErr != nil { + log.WithError(statusErr).Error("error creating status subresources") + return statusErr } - return h.client.CreateSubResource(app.ResourceMeta, map[string]interface{}{"status": app.Status}) + + return err } func (h *managedApplication) onDeleting(ctx context.Context, app *mv1.ManagedApplication, pma provManagedApp) {