diff --git a/cmd/polaris/root.go b/cmd/polaris/root.go index 77da760e3..1718cadc5 100644 --- a/cmd/polaris/root.go +++ b/cmd/polaris/root.go @@ -15,13 +15,11 @@ package cmd import ( - "flag" "os" conf "github.com/fairwindsops/polaris/pkg/config" "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "github.com/spf13/pflag" ) var configPath string @@ -42,9 +40,7 @@ func init() { rootCmd.PersistentFlags().BoolVarP(&disallowExemptions, "disallow-exemptions", "", false, "Disallow any configured exemption.") rootCmd.PersistentFlags().BoolVarP(&disallowConfigExemptions, "disallow-config-exemptions", "", false, "Disallow exemptions set within the configuration file.") rootCmd.PersistentFlags().BoolVarP(&disallowAnnotationExemptions, "disallow-annotation-exemptions", "", false, "Disallow any exemption defined as a controller annotation.") - rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "", logrus.InfoLevel.String(), "Logrus log level.") - flag.Parse() - pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "", logrus.InfoLevel.String(), "Logrus log level to be output (trace, debug, info, warning, error, fatal, panic).") } var config conf.Configuration diff --git a/pkg/validator/schema.go b/pkg/validator/schema.go index e69e3fc63..5fc3622c0 100644 --- a/pkg/validator/schema.go +++ b/pkg/validator/schema.go @@ -40,6 +40,25 @@ type schemaTestCase struct { ResourceProvider *kube.ResourceProvider } +// ShortString supplies some fields of a schemaTestCase suitable for brief +// output. +func (s schemaTestCase) ShortString() string { + var msg strings.Builder + targetStr := s.Target + if targetStr != "" { + msg.WriteString(fmt.Sprintf("target=%s, ", targetStr)) + } + ns := s.Resource.ObjectMeta.GetNamespace() + if ns != "" { + msg.WriteString(fmt.Sprintf("namespace=%s, ", ns)) + } + msg.WriteString(fmt.Sprintf("resource=%s/%s", s.Resource.Kind, s.Resource.ObjectMeta.GetName())) + if s.Target == config.TargetContainer { + msg.WriteString(fmt.Sprintf(", container=%s", s.Container.Name)) + } + return msg.String() +} + func resolveCheck(conf *config.Configuration, checkID string, test schemaTestCase) (*config.SchemaCheck, error) { if !conf.DisallowExemptions && !conf.DisallowAnnotationExemptions && @@ -110,6 +129,7 @@ func getTemplateInput(test schemaTestCase) (map[string]interface{}, error) { } } } + logrus.Debugf("the go template input for schema test-case %s is: %v", test.ShortString(), templateInput) return templateInput, nil } @@ -377,6 +397,16 @@ func applySchemaCheck(conf *config.Configuration, checkID string, test schemaTes return nil, err } } + if len(issues) > 0 { + issueMessages := make([]string, len(issues)) + for i, issue := range issues { + issueMessages[i] = issue.Message + } + logrus.Debugf("there were %d issue(s) validating the schema for test-case %s: %v", len(issueMessages), test.ShortString(), issueMessages) + } else { + logrus.Debugf("there were no issues validating the schema for test-case %s", test.ShortString()) + + } result := makeResult(conf, check, passes, issues) if !passes { if funk.Contains(conf.Mutations, checkID) && len(check.Mutations) > 0 {