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

CR-15989 #207

Open
wants to merge 1 commit into
base: release-2.6
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions server/application/application_errors_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ func parseApplicationSyncResultErrorsFromConditions(status appv1.ApplicationStat
return errs
}

func parseApplicationResourcesControllerSyncErrors(app *appv1.Application) []*events.ObjectError {
var errs []*events.ObjectError
if app.Status.Resources == nil {
return errs
}
for _, rs := range app.Status.Resources {
if rs.GroupVersionKind().String() != appv1.ApplicationSchemaGroupVersionKind.String() && strings.ToLower(rs.GroupVersionKind().String()) != strings.ToLower(appv1.ApplicationSetSchemaGroupVersionKind.String()) {
continue
}

if app.Namespace == rs.Namespace {
continue
}

errs = append(errs, &events.ObjectError{
Type: "sync",
Level: "error",
Message: rs.GroupVersionKind().String() + " resource(" + rs.Name + ") " + " located out of controller's namespace",
LastSeen: metav1.Now(),
})
}
return errs
}

func parseResourceSyncResultErrors(rs *appv1.ResourceStatus, os *appv1.OperationState) []*events.ObjectError {
errors := []*events.ObjectError{}
if os.SyncResult == nil {
Expand Down
10 changes: 9 additions & 1 deletion server/application/application_event_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ func (s *applicationEventReporter) getApplicationEventPayload(ctx context.Contex
syncStarted = metav1.Now()
syncFinished *metav1.Time
logCtx = log.WithField("application", a.Name)
errors = []*events.ObjectError{}
)

obj := appv1.Application{}
Expand Down Expand Up @@ -627,11 +628,18 @@ func (s *applicationEventReporter) getApplicationEventPayload(ctx context.Contex
Cluster: a.Spec.Destination.Server,
}

if a.Status.Conditions != nil {
errors = append(errors, parseApplicationSyncResultErrorsFromConditions(a.Status)...)
}
if a.Status.Resources != nil {
errors = append(errors, parseApplicationResourcesControllerSyncErrors(a)...)
}

payload := events.EventPayload{
Timestamp: ts,
Object: object,
Source: source,
Errors: parseApplicationSyncResultErrorsFromConditions(a.Status),
Errors: errors,
}

payloadBytes, err := json.Marshal(&payload)
Expand Down