Skip to content

Commit

Permalink
APIGOV-23133 - send status update call even if subresource update fai…
Browse files Browse the repository at this point in the history
…led (#485)
  • Loading branch information
jcollins-axway authored Jul 12, 2022
1 parent c704925 commit dc65c49
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
15 changes: 9 additions & 6 deletions pkg/agent/handler/accessrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -74,21 +75,23 @@ 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 {
log.Trace("processing resource in deleting state")
h.onDeleting(ctx, ar)
}

log.Trace("finished processing request")
return nil
}

Expand Down
15 changes: 11 additions & 4 deletions pkg/agent/handler/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 11 additions & 3 deletions pkg/agent/handler/managedapplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down

0 comments on commit dc65c49

Please sign in to comment.