Skip to content

Commit

Permalink
optimize nodeinfo inspect and add nodeinfo html out
Browse files Browse the repository at this point in the history
  • Loading branch information
liangzai006 committed Oct 26, 2023
1 parent d7cbfca commit c744fff
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 102 deletions.
15 changes: 8 additions & 7 deletions apis/kubeeye/v1alpha2/inspectresult_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ type PrometheusResult struct {
}

type NodeInfoResultItem struct {
Name string `json:"name,omitempty"`
FileSystem FileSystemLabel `json:",inline"`
Value string `json:"value,omitempty"`
Assert bool `json:"assert,omitempty"`
Level Level `json:"level,omitempty"`
NodeName string `json:"nodeName,omitempty"`
Name string `json:"name,omitempty"`
ResourcesType ResourcesType `json:",inline"`
Value string `json:"value,omitempty"`
Assert bool `json:"assert,omitempty"`
Level Level `json:"level,omitempty"`
NodeName string `json:"nodeName,omitempty"`
}

type FileSystemLabel struct {
type ResourcesType struct {
Mount string `json:"mount,omitempty"`
Type string `json:"type,omitempty"`
}
Expand All @@ -88,6 +88,7 @@ type FileChangeResultItem struct {
Path string `json:"path,omitempty"`
Level Level `json:"level,omitempty"`
NodeName string `json:"nodeName,omitempty"`
Assert bool `json:"assert,omitempty"`
}
type NodeMetricsResultItem struct {
Name string `json:"name,omitempty"`
Expand Down
3 changes: 2 additions & 1 deletion apis/kubeeye/v1alpha2/inspectrule_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ type Node struct {
type NodeInfo struct {
RuleItemBases `json:",inline"`
Node `json:",inline"`
Mount []string `json:"mount,omitempty"`
ResourcesType string `json:"resourcesType,omitempty"`
Mount string `json:"mount,omitempty"`
}

type FileFilterRule struct {
Expand Down
37 changes: 16 additions & 21 deletions apis/kubeeye/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions config/crd/bases/kubeeye.kubesphere.io_inspectresults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ spec:
fileChangeResult:
items:
properties:
assert:
type: boolean
fileName:
type: string
issues:
Expand All @@ -87,6 +89,8 @@ spec:
fileFilterResult:
items:
properties:
assert:
type: boolean
fileName:
type: string
issues:
Expand Down
6 changes: 3 additions & 3 deletions config/crd/bases/kubeeye.kubesphere.io_inspectrules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ spec:
level:
type: string
mount:
items:
type: string
type: array
type: string
name:
type: string
nodeName:
Expand All @@ -128,6 +126,8 @@ spec:
additionalProperties:
type: string
type: object
resourcesType:
type: string
rule:
type: string
type: object
Expand Down
1 change: 1 addition & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ rules:
resources:
- namespaces
- nodes
- secrets
- services
verbs:
- get
Expand Down
8 changes: 8 additions & 0 deletions deploy/kubeeye_v1alpha2_inspectplan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ spec:
ruleNames:
- name: inspect-rule-namespace
- name: inspect-rule-systemd
- name: inspect-rule-filechange
- name: inspect-rule-filter-file
- name: inspect-rule-node-info
- name: inspect-rule-prometheus
- name: inspect-rule-sbnormalpodstatus
- name: inspect-rule-sysctl
timeout: 30m

3 changes: 2 additions & 1 deletion pkg/controllers/inspectresult_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (r *InspectResultReconciler) Reconcile(ctx context.Context, req ctrl.Reques
klog.Error("Failed to update inspect result status", err)
return ctrl.Result{}, err
}

go r.SendMessage(ctx, result)
return ctrl.Result{}, nil
}
Expand Down Expand Up @@ -251,7 +252,7 @@ func (r *InspectResultReconciler) SendMessage(ctx context.Context, result *kubee
messageHandler := message.NewEmailMessageOptions(&kc.Message.Email, r.Client)
dispatcher := message.RegisterHandler(messageHandler)
dispatcher.DispatchMessageEvent(&conf.MessageEvent{
Title: fmt.Sprintf("巡检完成,共发现%d个问题", n),
Title: fmt.Sprintf("%s集群巡检完成,共发现%d个问题", result.Spec.InspectCluster.Name, n),
Timestamp: time.Now(),
Content: data.Bytes(),
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/inspecttask_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type InspectTaskReconciler struct {
//+kubebuilder:rbac:groups=cluster.kubesphere.io,resources=clusters,verbs=get
//+kubebuilder:rbac:groups=kubeeye.kubesphere.io,resources=inspecttasks/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=kubeeye.kubesphere.io,resources=inspecttasks/finalizers,verbs=update
//+kubebuilder:rbac:groups="",resources=nodes;namespaces;services,verbs=list;get
//+kubebuilder:rbac:groups="",resources=nodes;namespaces;services;secrets,verbs=list;get
//+kubebuilder:rbac:groups="",resources=namespaces,verbs=create
//+kubebuilder:rbac:groups="",resources=serviceaccounts,verbs=create;delete
//+kubebuilder:rbac:groups="",resources=configmaps,verbs=deletecollection;list;get;watch
Expand Down
3 changes: 3 additions & 0 deletions pkg/inspect/file_change_Inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (o *fileChangeInspect) RunInspect(ctx context.Context, rules []kubeeyev1alp
klog.Errorf("Failed to open base file path:%s,error:%s", baseFile, fileErr)
resultItem.Issues = []string{fmt.Sprintf("%s:The file does not exist", file.Name)}
resultItem.Level = file.Level
resultItem.Assert = true
fileResults = append(fileResults, resultItem)
continue
}
Expand All @@ -95,6 +96,7 @@ func (o *fileChangeInspect) RunInspect(ctx context.Context, rules []kubeeyev1alp
if createErr != nil {
resultItem.Issues = []string{fmt.Sprintf("%s:create configMap failed", file.Name)}
resultItem.Level = file.Level
resultItem.Assert = true
fileResults = append(fileResults, resultItem)
}
continue
Expand All @@ -112,6 +114,7 @@ func (o *fileChangeInspect) RunInspect(ctx context.Context, rules []kubeeyev1alp
resultItem.Issues = diffResult
if len(resultItem.Issues) > 0 {
resultItem.Level = file.Level
resultItem.Assert = true
}
fileResults = append(fileResults, resultItem)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/inspect/file_filter_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (o *fileFilterInspect) RunInspect(ctx context.Context, rules []kubeeyev1alp
klog.Errorf(" Failed to open file . err:%s", err)
filterR.Issues = append(filterR.Issues, fmt.Sprintf("Failed to open file for %s.", rule.Name))
filterR.Level = rule.Level
filterR.Assert = true
filterResult = append(filterResult, filterR)
continue
}
Expand All @@ -94,6 +95,7 @@ func (o *fileFilterInspect) RunInspect(ctx context.Context, rules []kubeeyev1alp
}
}
if len(filterR.Issues) > 0 {
filterR.Assert = true
filterR.Level = rule.Level
}
filterResult = append(filterResult, filterR)
Expand Down
Loading

0 comments on commit c744fff

Please sign in to comment.