mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-07 00:17:13 +00:00
* fix[breaking]: disable exceptions by default Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com> * fix chainsaw tests Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com> * fix: add warning in helm chart for exceptions Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com> --------- Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
33 lines
999 B
Go
33 lines
999 B
Go
package exception
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/go-logr/logr"
|
|
kyvernov2 "github.com/kyverno/kyverno/api/kyverno/v2"
|
|
)
|
|
|
|
const (
|
|
namespacesDontMatch = "PolicyException resource namespace must match the defined namespace."
|
|
disabledPolex = "PolicyException resources would not be processed until it is enabled."
|
|
polexNamespaceFlag = "The exceptionNamespace flag is not set"
|
|
)
|
|
|
|
type ValidationOptions struct {
|
|
Enabled bool
|
|
Namespace string
|
|
}
|
|
|
|
// Validate checks policy exception is valid
|
|
func Validate(ctx context.Context, logger logr.Logger, polex *kyvernov2.PolicyException, opts ValidationOptions) ([]string, error) {
|
|
var warnings []string
|
|
if !opts.Enabled {
|
|
warnings = append(warnings, disabledPolex)
|
|
} else if opts.Namespace == "" {
|
|
warnings = append(warnings, polexNamespaceFlag)
|
|
} else if opts.Namespace != "*" && opts.Namespace != polex.Namespace {
|
|
warnings = append(warnings, namespacesDontMatch)
|
|
}
|
|
errs := polex.Validate()
|
|
return warnings, errs.ToAggregate()
|
|
}
|