mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
20069c13c3
* feat: stop adding autogen annotation Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> * feat: stop mutating rules Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> * feat: stop mutating rules Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> * fix: use toggle Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> * fix: review comments Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> Co-authored-by: shuting <shuting@nirmata.com>
45 lines
919 B
Go
45 lines
919 B
Go
package toggle
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
const (
|
|
AutogenInternalsFlagName = "autogenInternals"
|
|
AutogenInternalsDescription = "Enables autogen internal policies. When this is 'true' policy rules should not be mutated."
|
|
AutogenInternalsEnvVar = "FLAG_AUTOGEN_INTERNALS"
|
|
DefaultAutogenInternals = false
|
|
)
|
|
|
|
var autogenInternals *bool
|
|
|
|
func getBool(in string) (*bool, error) {
|
|
if in == "" {
|
|
return nil, nil
|
|
}
|
|
value, err := strconv.ParseBool(in)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &value, nil
|
|
}
|
|
|
|
func AutogenInternalsFlag(in string) error {
|
|
if value, err := getBool(in); err != nil {
|
|
return err
|
|
} else {
|
|
autogenInternals = value
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func AutogenInternals() bool {
|
|
if autogenInternals != nil {
|
|
return *autogenInternals
|
|
}
|
|
if value, err := getBool(os.Getenv(AutogenInternalsEnvVar)); err == nil && value != nil {
|
|
return *value
|
|
}
|
|
return DefaultAutogenInternals
|
|
}
|