Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIGOV-23133 - send status update call even if subresource update failed #485

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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