mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
7501ec8f57
* toggle for autogen version Signed-off-by: utsab818 <utsabsapkota4231@gmail.com> * Updated toggle for autogenv2 Signed-off-by: utsab818 <utsabsapkota4231@gmail.com> --------- Signed-off-by: utsab818 <utsabsapkota4231@gmail.com>
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package toggle
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
var defaults Toggles = defaultToggles{}
|
|
|
|
type Toggles interface {
|
|
ProtectManagedResources() bool
|
|
ForceFailurePolicyIgnore() bool
|
|
EnableDeferredLoading() bool
|
|
GenerateValidatingAdmissionPolicy() bool
|
|
DumpMutatePatches() bool
|
|
AutogenV2() bool
|
|
}
|
|
|
|
type defaultToggles struct{}
|
|
|
|
func (defaultToggles) ProtectManagedResources() bool {
|
|
return ProtectManagedResources.enabled()
|
|
}
|
|
|
|
func (defaultToggles) ForceFailurePolicyIgnore() bool {
|
|
return ForceFailurePolicyIgnore.enabled()
|
|
}
|
|
|
|
func (defaultToggles) EnableDeferredLoading() bool {
|
|
return EnableDeferredLoading.enabled()
|
|
}
|
|
|
|
func (defaultToggles) GenerateValidatingAdmissionPolicy() bool {
|
|
return GenerateValidatingAdmissionPolicy.enabled()
|
|
}
|
|
|
|
func (defaultToggles) DumpMutatePatches() bool {
|
|
return DumpMutatePatches.enabled()
|
|
}
|
|
|
|
func (defaultToggles) AutogenV2() bool {
|
|
return AutogenV2.enabled()
|
|
}
|
|
|
|
type contextKey struct{}
|
|
|
|
func NewContext(ctx context.Context, toggles Toggles) context.Context {
|
|
if ctx == nil {
|
|
return nil
|
|
}
|
|
return context.WithValue(ctx, contextKey{}, toggles)
|
|
}
|
|
|
|
func FromContext(ctx context.Context) Toggles {
|
|
if ctx != nil {
|
|
if toggles, ok := ctx.Value(contextKey{}).(Toggles); ok {
|
|
return toggles
|
|
}
|
|
}
|
|
return defaults
|
|
}
|