@@ -32,15 +32,15 @@ func getResourceEventPayload(
3232 logCtx * log.Entry
3333 )
3434
35- if rr .rsAsAppInfo .app != nil {
35+ if rr .rsAsAppInfo != nil && rr . rsAsAppInfo .app != nil {
3636 logCtx = log .WithField ("application" , rr .rsAsAppInfo .app .Name )
3737 } else {
3838 logCtx = log .NewEntry (log .StandardLogger ())
3939 }
4040
4141 object := []byte (* rr .actualState .Manifest )
4242
43- if rr .rsAsAppInfo .revisionsMetadata != nil && len (object ) != 0 {
43+ if rr .rsAsAppInfo != nil && rr . rsAsAppInfo .revisionsMetadata != nil && len (object ) != 0 {
4444 actualObject , err := appv1 .UnmarshalToUnstructured (* rr .actualState .Manifest )
4545
4646 if err != nil {
@@ -69,7 +69,7 @@ func getResourceEventPayload(
6969 makeDesiredAndLiveManifestEmpty (rr .actualState , rr .desiredState )
7070 }
7171
72- if (rr .rsAsAppInfo .app != nil && rr .rsAsAppInfo .app .DeletionTimestamp != nil ) || reportedEntityParentApp .app .ObjectMeta .DeletionTimestamp != nil {
72+ if (rr .rsAsAppInfo != nil && rr . rsAsAppInfo .app != nil && rr .rsAsAppInfo .app .DeletionTimestamp != nil ) || reportedEntityParentApp .app .ObjectMeta .DeletionTimestamp != nil {
7373 // resource should be deleted in case if application in process of deletion
7474 makeDesiredAndLiveManifestEmpty (rr .actualState , rr .desiredState )
7575 }
@@ -92,9 +92,12 @@ func getResourceEventPayload(
9292 syncFinished = & syncStarted
9393 }
9494
95- applicationVersionsEvents , err := utils .RepoAppVersionsToEvent (rr .rsAsAppInfo .applicationVersions )
96- if err != nil {
97- logCtx .Errorf ("failed to convert appVersions: %v" , err )
95+ var applicationVersionsEvents * events.ApplicationVersions
96+ if rr .rsAsAppInfo != nil {
97+ applicationVersionsEvents , err = utils .RepoAppVersionsToEvent (rr .rsAsAppInfo .applicationVersions )
98+ if err != nil {
99+ logCtx .Errorf ("failed to convert appVersions: %v" , err )
100+ }
98101 }
99102
100103 source := events.ObjectSource {
@@ -140,7 +143,9 @@ func getResourceEventPayload(
140143 AppVersions : applicationVersionsEvents ,
141144 }
142145
143- logCtx .Infof ("AppVersion before encoding: %v" , utils .SafeString (payload .AppVersions .AppVersion ))
146+ if payload .AppVersions != nil {
147+ logCtx .Infof ("AppVersion before encoding: %v" , utils .SafeString (payload .AppVersions .AppVersion ))
148+ }
144149
145150 payloadBytes , err := json .Marshal (& payload )
146151 if err != nil {
@@ -161,22 +166,20 @@ func getResourceEventPayloadErrors(
161166 }
162167
163168 // parent application not include errors in application originally was created with broken state, for example in destination missed namespace
164- if rr .rsAsAppInfo .app != nil && rr .rsAsAppInfo .app .Status .OperationState != nil {
165- errors = append (errors , parseApplicationSyncResultErrors (rr .rsAsAppInfo .app .Status .OperationState )... )
166- }
169+ if rr .rsAsAppInfo != nil && rr .rsAsAppInfo .app != nil {
170+ if rr .rsAsAppInfo .app .Status .OperationState != nil {
171+ errors = append (errors , parseApplicationSyncResultErrors (rr .rsAsAppInfo .app .Status .OperationState )... )
172+ }
167173
168- if rr . rsAsAppInfo . app != nil && rr .rsAsAppInfo .app .Status .Conditions != nil {
169- errors = append (errors , parseApplicationSyncResultErrorsFromConditions (rr .rsAsAppInfo .app .Status )... )
170- }
174+ if rr .rsAsAppInfo .app .Status .Conditions != nil {
175+ errors = append (errors , parseApplicationSyncResultErrorsFromConditions (rr .rsAsAppInfo .app .Status )... )
176+ }
171177
172- if rr .rsAsAppInfo .app != nil {
173178 errors = append (errors , parseAggregativeHealthErrorsOfApplication (rr .rsAsAppInfo .app , reportedEntityParentApp .appTree )... )
174179 }
175180
176- if rr .rs .Health != nil {
177- if rr .rs .Health .Status != health .HealthStatusHealthy {
178- errors = append (errors , parseAggregativeHealthErrors (rr .rs , reportedEntityParentApp .appTree , false )... )
179- }
181+ if rr .rs .Health != nil && rr .rs .Health .Status != health .HealthStatusHealthy {
182+ errors = append (errors , parseAggregativeHealthErrors (rr .rs , reportedEntityParentApp .appTree , false )... )
180183 }
181184
182185 return errors
@@ -227,7 +230,7 @@ func addCommitDetailsToUnstructured(
227230 u * unstructured.Unstructured ,
228231 rr * ReportedResource ,
229232) ([]byte , error ) {
230- if rr .rsAsAppInfo .revisionsMetadata != nil {
233+ if rr .rsAsAppInfo != nil && rr . rsAsAppInfo .revisionsMetadata != nil {
231234 u = utils .AddCommitsDetailsToAnnotations (u , rr .rsAsAppInfo .revisionsMetadata )
232235 if rr .rsAsAppInfo .app != nil {
233236 u = utils .AddCommitDetailsToLabels (u , getApplicationLegacyRevisionDetails (rr .rsAsAppInfo .app , rr .rsAsAppInfo .revisionsMetadata ))
0 commit comments