mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 07:57:07 +00:00
30 lines
850 B
Go
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()
|
|
}
|