Introduce DiagnosticFilter to store fields based on which diagnostics will be filtered

image-warning-sha256
Varsha Varadarajan 2019-07-11 15:20:05 -04:00
parent 7b76406624
commit 848515cb45
3 changed files with 12 additions and 7 deletions

View File

@ -37,6 +37,11 @@ func (d Diagnostic) String() string {
d.Kind, d.Object.Name, d.Message) d.Kind, d.Object.Name, d.Message)
} }
// DiagnosticFilter indicates conditions to filter diagnostics on
type DiagnosticFilter struct {
Severity Severity
}
// Severity identifies the level of priority for each diagnostic. // Severity identifies the level of priority for each diagnostic.
type Severity string type Severity string

View File

@ -17,7 +17,7 @@ limitations under the License.
package checks package checks
import ( import (
"fmt" "errors"
"sync" "sync"
"github.com/digitalocean/clusterlint/kube" "github.com/digitalocean/clusterlint/kube"
@ -25,7 +25,7 @@ import (
) )
// Run applies the filters and runs the resultant check list in parallel // Run applies the filters and runs the resultant check list in parallel
func Run(client *kube.Client, checkFilter CheckFilter, severity Severity) ([]Diagnostic, error) { func Run(client *kube.Client, checkFilter CheckFilter, diagnosticFilter DiagnosticFilter) ([]Diagnostic, error) {
objects, err := client.FetchObjects() objects, err := client.FetchObjects()
if err != nil { if err != nil {
return nil, err return nil, err
@ -36,7 +36,7 @@ func Run(client *kube.Client, checkFilter CheckFilter, severity Severity) ([]Dia
return nil, err return nil, err
} }
if len(all) == 0 { if len(all) == 0 {
return nil, fmt.Errorf("No checks to run. Are you sure that you provided the right names for groups and checks?") return nil, errors.New("No checks to run. Are you sure that you provided the right names for groups and checks?")
} }
var diagnostics []Diagnostic var diagnostics []Diagnostic
var mu sync.Mutex var mu sync.Mutex
@ -45,7 +45,6 @@ func Run(client *kube.Client, checkFilter CheckFilter, severity Severity) ([]Dia
for _, check := range all { for _, check := range all {
check := check check := check
g.Go(func() error { g.Go(func() error {
fmt.Println("Running check: ", check.Name())
d, err := check.Run(objects) d, err := check.Run(objects)
if err != nil { if err != nil {
return err return err
@ -61,7 +60,7 @@ func Run(client *kube.Client, checkFilter CheckFilter, severity Severity) ([]Dia
return nil, err return nil, err
} }
diagnostics = filterEnabled(diagnostics) diagnostics = filterEnabled(diagnostics)
diagnostics = filterSeverity(severity, diagnostics) diagnostics = filterSeverity(diagnosticFilter.Severity, diagnostics)
return diagnostics, err return diagnostics, err
} }

View File

@ -136,8 +136,9 @@ func runChecks(c *cli.Context) error {
return err return err
} }
level := checks.Severity(c.String("level")) diagnosticFilter := checks.DiagnosticFilter{Severity: checks.Severity(c.String("level"))}
diagnostics, err := checks.Run(client, filter, level)
diagnostics, err := checks.Run(client, filter, diagnosticFilter)
write(diagnostics, c) write(diagnostics, c)