@@ -64,10 +64,20 @@ Create constraints with the Gatekeeper enforcement action set to dryrun
6464 return fmt .Errorf ("bind partial-constraints flag: %w" , err )
6565 }
6666
67+ if err := viper .BindPFlag ("log-level" , cmd .PersistentFlags ().Lookup ("log-level" )); err != nil {
68+ return fmt .Errorf ("bind log-level flag: %w" , err )
69+ }
70+
6771 if cmd .PersistentFlags ().Lookup ("constraint-template-custom-template-file" ).Changed && cmd .PersistentFlags ().Lookup ("constraint-template-version" ).Changed {
6872 return fmt .Errorf ("need to set either constraint-template-custom-template-file or constraint-template-version" )
6973 }
70-
74+ if cmd .PersistentFlags ().Lookup ("log-level" ).Changed {
75+ level , err := log .ParseLevel (viper .GetString ("log-level" ))
76+ if err != nil {
77+ return fmt .Errorf ("Unknown log level: Need to use either error, info, debug or trace" )
78+ }
79+ log .SetLevel (level )
80+ }
7181 path := "."
7282 if len (args ) > 0 {
7383 path = args [0 ]
@@ -78,13 +88,13 @@ Create constraints with the Gatekeeper enforcement action set to dryrun
7888 }
7989
8090 cmd .PersistentFlags ().StringP ("output" , "o" , "" , "Specify an output directory for the Gatekeeper resources" )
81- cmd .PersistentFlags ().BoolP ("dryrun" , "d" , false , "Sets the enforcement action of the constraints to dryrun, overriding the @enforcement tag" )
91+ cmd .PersistentFlags ().BoolP ("dryrun" , "d" , false , "Set the enforcement action of the constraints to dryrun, overriding the @enforcement tag" )
8292 cmd .PersistentFlags ().Bool ("skip-constraints" , false , "Skip generation of constraints" )
8393 cmd .PersistentFlags ().String ("constraint-template-version" , "v1beta1" , "Set the version of ConstraintTemplates" )
8494 cmd .PersistentFlags ().Bool ("partial-constraints" , false , "Generate partial Constraints for policies with parameters" )
8595 cmd .PersistentFlags ().String ("constraint-template-custom-template-file" , "" , "Path to a custom template file to generate constraint templates" )
8696 cmd .PersistentFlags ().String ("constraint-custom-template-file" , "" , "Path to a custom template file to generate constraints" )
87-
97+ cmd . PersistentFlags (). String ( "log-level" , "info" , "Set a log level. Options: error, info, debug, trace" )
8898 return & cmd
8999}
90100
@@ -100,6 +110,8 @@ func runCreateCommand(path string) error {
100110 "src" : violation .Path (),
101111 })
102112
113+ logger .Debug ("Rendering policy" )
114+
103115 if violation .SkipTemplate () {
104116 logger .Info ("Skipping constrainttemplate generation due to configuration" )
105117 continue
0 commit comments