Skip to content

Commit e6dfd15

Browse files
authored
Merge pull request #176 from brendanjryan/bjr-add-quiet-flag
adds a quiet flag
2 parents ecd0802 + 3163f52 commit e6dfd15

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

acceptance.bats

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,9 @@
163163
[[ "${lines[1]}" == *"The file fixtures/valid.yaml contains a valid ReplicationController"* ]]
164164
[[ "${lines[2]}" == *"The file fixtures/valid.yaml contains a valid ReplicationController"* ]]
165165
}
166+
167+
@test "Does not print warnings if --quiet is supplied" {
168+
run bin/kubeval --ignore-missing-schemas --quiet fixtures/valid.yaml
169+
[ "$status" -eq 0 ]
170+
[ "$output" = "The file fixtures/valid.yaml contains a valid ReplicationController" ]
171+
}

kubeval/config.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ type Config struct {
5353
// OutputFormat is the name of the output formatter which will be used when
5454
// reporting results to the user.
5555
OutputFormat string
56+
57+
// Quiet indicates whether non-results output should be emitted to the applications
58+
// log.
59+
Quiet bool
5660
}
5761

5862
// NewDefaultConfig creates a Config with default values
@@ -72,9 +76,10 @@ func AddKubevalFlags(cmd *cobra.Command, config *Config) *cobra.Command {
7276
cmd.Flags().StringVarP(&config.FileName, "filename", "f", "stdin", "filename to be displayed when testing manifests read from stdin")
7377
cmd.Flags().StringSliceVar(&config.KindsToSkip, "skip-kinds", []string{}, "Comma-separated list of case-sensitive kinds to skip when validating against schemas")
7478
cmd.Flags().StringVarP(&config.SchemaLocation, "schema-location", "s", "", "Base URL used to download schemas. Can also be specified with the environment variable KUBEVAL_SCHEMA_LOCATION.")
75-
cmd.Flags().StringSliceVar(&config.AdditionalSchemaLocations , "additional-schema-locations", []string{}, "Comma-seperated list of secondary base URLs used to download schemas")
79+
cmd.Flags().StringSliceVar(&config.AdditionalSchemaLocations, "additional-schema-locations", []string{}, "Comma-seperated list of secondary base URLs used to download schemas")
7680
cmd.Flags().StringVarP(&config.KubernetesVersion, "kubernetes-version", "v", "master", "Version of Kubernetes to validate against")
7781
cmd.Flags().StringVarP(&config.OutputFormat, "output", "o", "", fmt.Sprintf("The format of the output of this script. Options are: %v", validOutputs()))
82+
cmd.Flags().BoolVar(&config.Quiet, "quiet", false, "Silences any output aside from the direct results")
7883

7984
return cmd
8085
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var RootCmd = &cobra.Command{
3939
Long: `Validate a Kubernetes YAML file against the relevant schema`,
4040
Version: fmt.Sprintf("Version: %s\nCommit: %s\nDate: %s\n", version, commit, date),
4141
Run: func(cmd *cobra.Command, args []string) {
42-
if config.IgnoreMissingSchemas {
42+
if config.IgnoreMissingSchemas && !config.Quiet {
4343
log.Warn("Warning: Set to ignore missing schemas")
4444
}
4545
success := true

0 commit comments

Comments
 (0)