1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 07:57:07 +00:00
kyverno/pkg/validation/exception/validate.go
Mariam Fahmy 94d9bbe73f
chore: use v2 clients for policy exceptions (#10530)
Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
2024-06-24 16:36:55 +00:00

30 lines
850 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."
)
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 != "" && opts.Namespace != polex.Namespace {
warnings = append(warnings, namespacesDontMatch)
}
errs := polex.Validate()
return warnings, errs.ToAggregate()
}