1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/toggle/context.go
Mariam Fahmy f0be3bdc0b
fix: display a message when the controller has no permissions for VAPs (#8776)
* fix: display a message when the controller has no permissions for VAPs

Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>

* fix: add a warning when a Kyverno policy is created

Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>

---------

Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
2023-11-01 21:52:03 +08:00

50 lines
1 KiB
Go

package toggle
import (
"context"
)
var defaults Toggles = defaultToggles{}
type Toggles interface {
ProtectManagedResources() bool
ForceFailurePolicyIgnore() bool
EnableDeferredLoading() bool
GenerateValidatingAdmissionPolicy() 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()
}
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
}