1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/toggle/toggle.go
Charles-Edouard Brétéché 20069c13c3
feat: stop mutating rules (#3410)
* 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>
2022-03-28 22:01:27 +08:00

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
}