Skip to content

Commit 68507ba

Browse files
event-reporter: fixed issue when if managed resource in degraded state and all of it child nodes in non-degraded state we don't report any error
1 parent 5af7ecc commit 68507ba

File tree

2 files changed

+108
-18
lines changed

2 files changed

+108
-18
lines changed

event_reporter/reporter/application_errors_parser.go

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -135,31 +135,44 @@ func parseAggregativeHealthErrors(rs *appv1.ResourceStatus, apptree *appv1.Appli
135135
childNodes := n.GetAllChildNodes(apptree, "")
136136

137137
for _, cn := range childNodes {
138-
if cn.Health != nil && cn.Health.Status == health.HealthStatusDegraded {
139-
newErr := events.ObjectError{
140-
Type: "health",
141-
Level: "error",
142-
Message: cn.Health.Message,
143-
LastSeen: *cn.CreatedAt,
144-
}
145-
146-
if addReference {
147-
newErr.SourceReference = &events.ErrorSourceReference{
148-
Group: rs.Group,
149-
Version: rs.Version,
150-
Kind: rs.Kind,
151-
Namespace: rs.Namespace,
152-
Name: rs.Name,
153-
}
154-
}
138+
if newErr := getNodeHealthError(cn, rs, addReference); newErr != nil {
139+
errs = append(errs, newErr)
140+
}
141+
}
155142

156-
errs = append(errs, &newErr)
143+
if len(errs) == 0 {
144+
if newErr := getNodeHealthError(*n, rs, addReference); newErr != nil {
145+
errs = append(errs, newErr)
157146
}
158147
}
159148

160149
return errs
161150
}
162151

152+
func getNodeHealthError(node appv1.ResourceNode, managedResource *appv1.ResourceStatus, addReference bool) *events.ObjectError {
153+
if node.Health == nil || node.Health.Status != health.HealthStatusDegraded {
154+
return nil
155+
}
156+
157+
newErr := &events.ObjectError{
158+
Type: "health",
159+
Level: "error",
160+
Message: node.Health.Message,
161+
LastSeen: *node.CreatedAt,
162+
}
163+
164+
if addReference {
165+
newErr.SourceReference = &events.ErrorSourceReference{
166+
Group: managedResource.Group,
167+
Version: managedResource.Version,
168+
Kind: managedResource.Kind,
169+
Namespace: managedResource.Namespace,
170+
Name: managedResource.Name,
171+
}
172+
}
173+
return newErr
174+
}
175+
163176
func parseAggregativeResourcesSyncErrors(resourceResults appv1.ResourceResults) []*events.ObjectError {
164177
var errs []*events.ObjectError
165178

event_reporter/reporter/applications_errors_parser_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,81 @@ func TestParseAggregativeHealthErrors(t *testing.T) {
336336
assert.NotNil(t, errs[0].SourceReference)
337337
assert.Equal(t, deployRef.Name, errs[0].SourceReference.Name)
338338
})
339+
340+
t.Run("should build error from root node if it's degraded while no one of child in degraded health state", func(t *testing.T) {
341+
rsName := "test-deployment"
342+
ns := "test"
343+
errMessage := "backoff pulling image test/test:0.1"
344+
replicaSetRef := v1alpha1.ResourceRef{
345+
Group: "g",
346+
Version: "v",
347+
Kind: "ReplicaSet",
348+
Name: rsName + "1",
349+
Namespace: ns,
350+
}
351+
352+
deploymentRef := v1alpha1.ResourceRef{
353+
Group: "g",
354+
Version: "v",
355+
Kind: "Deployment",
356+
Name: rsName,
357+
Namespace: ns,
358+
}
359+
360+
appTree := v1alpha1.ApplicationTree{
361+
Nodes: []v1alpha1.ResourceNode{
362+
{ // Pod
363+
ResourceRef: v1alpha1.ResourceRef{
364+
Group: "g",
365+
Version: "v",
366+
Kind: "Pod",
367+
Name: rsName + "1-3n235j5",
368+
Namespace: ns,
369+
},
370+
Health: &v1alpha1.HealthStatus{
371+
Status: health.HealthStatusProgressing,
372+
Message: "some error of pod",
373+
},
374+
ParentRefs: []v1alpha1.ResourceRef{replicaSetRef},
375+
CreatedAt: &metav1.Time{
376+
Time: time.Now(),
377+
},
378+
},
379+
{ // ReplicaSet
380+
ResourceRef: replicaSetRef,
381+
Health: &v1alpha1.HealthStatus{
382+
Status: health.HealthStatusProgressing,
383+
Message: "",
384+
},
385+
ParentRefs: []v1alpha1.ResourceRef{deploymentRef},
386+
CreatedAt: &metav1.Time{
387+
Time: time.Now(),
388+
},
389+
},
390+
{ // Deployment
391+
ResourceRef: deploymentRef,
392+
Health: &v1alpha1.HealthStatus{
393+
Status: health.HealthStatusDegraded,
394+
Message: errMessage,
395+
},
396+
ParentRefs: []v1alpha1.ResourceRef{},
397+
CreatedAt: &metav1.Time{
398+
Time: time.Now(),
399+
},
400+
},
401+
},
402+
}
403+
404+
errs := parseAggregativeHealthErrors(&v1alpha1.ResourceStatus{
405+
Group: deploymentRef.Group,
406+
Version: deploymentRef.Version,
407+
Kind: deploymentRef.Kind,
408+
Name: deploymentRef.Name,
409+
Namespace: deploymentRef.Namespace,
410+
}, &appTree, true)
411+
assert.Len(t, errs, 1)
412+
assert.Equal(t, errMessage, errs[0].Message)
413+
assert.NotNil(t, errs[0].SourceReference)
414+
assert.Equal(t, deploymentRef.Name, errs[0].SourceReference.Name)
415+
})
339416
}

0 commit comments

Comments
 (0)