Skip to content

Commit

Permalink
fix level count error
Browse files Browse the repository at this point in the history
  • Loading branch information
liangzai006 committed Oct 26, 2023
1 parent c744fff commit 92a4f0e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
7 changes: 5 additions & 2 deletions deploy/rule/kubeeye_v1alpha2_nodeInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ spec:
nodeInfo:
- name: Cpu
rule: cpu > 20
resourcesType: cpu
desc: CPU usage greater than 20%
- name: Memory
rule: memory > 20
resourcesType: memory
desc: memory usage greater than 20%
- name: filesystem
rule: filesystem > 20 or inode > 20
desc: filesystem usage greater than 20% and inode usage greater than 20%
rule: filesystem > 20
resourcesType: filesystem
desc: filesystem usage greater than 20%
19 changes: 13 additions & 6 deletions pkg/controllers/inspectresult_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (r *InspectResultReconciler) Reconcile(ctx context.Context, req ctrl.Reques
result.Finalizers = append(result.Finalizers, Finalizers)
err = r.Client.Update(ctx, result)
if err != nil {
klog.Error("Failed to inspect plan add finalizers", err)
klog.Error("Failed to inspect result add finalizers", err)
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
Expand Down Expand Up @@ -203,13 +203,20 @@ func totalResultLevel(data interface{}, mapLevel map[kubeeyev1alpha2.Level]*int)
for _, m := range maps {
_, exist := m["assert"]
if exist {
s, isOk := m["issues"]
a := 1
if isOk {
a = len(s.([]interface{}))
}
v, ok := m["level"]
if !ok {
mapLevel[kubeeyev1alpha2.DangerLevel] = Autoincrement(kubeeyev1alpha2.DangerLevel)
} else {
l := v.(string)
mapLevel[kubeeyev1alpha2.Level(l)] = Autoincrement(kubeeyev1alpha2.Level(l))
for i := 0; i < a; i++ {
if !ok {
Autoincrement(kubeeyev1alpha2.DangerLevel)
} else {
Autoincrement(kubeeyev1alpha2.Level(v.(string)))
}
}

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/inspect/nodeinfo_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (o *nodeInfoInspect) RunInspect(ctx context.Context, rules []kubeeyev1alpha
}
case constant.Memory:
data := GetMemory(fs)
resultItem.Value = fmt.Sprintf("%.0f%%", data[constant.Cpu])
resultItem.Value = fmt.Sprintf("%.0f%%", data[constant.Memory])
resultItem.ResourcesType.Type = constant.Memory
err, ok = visitor.EventRuleEvaluate(data, *info.Rule)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/output/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func HtmlOut(resultName string) (error, map[string]interface{}) {
}
if results.Spec.NodeInfo != nil {
resultCollection[constant.NodeInfo] = getNodeInfo(results.Spec.NodeInfo)

}

if results.Spec.ComponentResult != nil {
Expand Down

0 comments on commit 92a4f0e

Please sign in to comment.