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)
}
// DiagnosticFilter indicates conditions to filter diagnostics on
type DiagnosticFilter struct {
Severity Severity
}
// Severity identifies the level of priority for each diagnostic.
type Severity string

View File

@ -17,7 +17,7 @@ limitations under the License.
package checks
import (
"fmt"
"errors"
"sync"
"github.com/digitalocean/clusterlint/kube"
@ -25,7 +25,7 @@ import (
)
// 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()
if err != nil {
return nil, err
@ -36,7 +36,7 @@ func Run(client *kube.Client, checkFilter CheckFilter, severity Severity) ([]Dia
return nil, err
}
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 mu sync.Mutex
@ -45,7 +45,6 @@ func Run(client *kube.Client, checkFilter CheckFilter, severity Severity) ([]Dia
for _, check := range all {
check := check
g.Go(func() error {
fmt.Println("Running check: ", check.Name())
d, err := check.Run(objects)
if err != nil {
return err
@ -61,7 +60,7 @@ func Run(client *kube.Client, checkFilter CheckFilter, severity Severity) ([]Dia
return nil, err
}
diagnostics = filterEnabled(diagnostics)
diagnostics = filterSeverity(severity, diagnostics)
diagnostics = filterSeverity(diagnosticFilter.Severity, diagnostics)
return diagnostics, err
}

View File

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