2019-11-09 02:57:27 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2021-10-29 16:13:20 +00:00
|
|
|
kyverno "github.com/kyverno/kyverno/api/kyverno/v1"
|
2020-10-07 18:12:31 +00:00
|
|
|
client "github.com/kyverno/kyverno/pkg/dclient"
|
|
|
|
"github.com/kyverno/kyverno/pkg/engine/context"
|
2019-11-09 02:57:27 +00:00
|
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PolicyContext contains the contexts for engine to process
|
|
|
|
type PolicyContext struct {
|
2020-12-16 20:29:16 +00:00
|
|
|
// Policy is the policy to be processed
|
2022-03-30 13:04:30 +00:00
|
|
|
Policy kyverno.PolicyInterface
|
2020-12-16 20:29:16 +00:00
|
|
|
|
|
|
|
// NewResource is the resource to be processed
|
2019-11-13 21:13:07 +00:00
|
|
|
NewResource unstructured.Unstructured
|
2020-12-16 20:29:16 +00:00
|
|
|
|
|
|
|
// OldResource is the prior resource for an update, or nil
|
|
|
|
OldResource unstructured.Unstructured
|
|
|
|
|
2021-10-02 23:53:02 +00:00
|
|
|
// Element is set when the context is used for processing a foreach loop
|
|
|
|
Element unstructured.Unstructured
|
|
|
|
|
2020-12-16 20:29:16 +00:00
|
|
|
// AdmissionInfo contains the admission request information
|
2020-01-07 18:33:28 +00:00
|
|
|
AdmissionInfo kyverno.RequestInfo
|
2020-12-16 20:29:16 +00:00
|
|
|
|
2019-11-13 23:46:43 +00:00
|
|
|
// Dynamic client - used by generate
|
|
|
|
Client *client.Client
|
2020-12-16 20:29:16 +00:00
|
|
|
|
2020-08-08 00:09:24 +00:00
|
|
|
// Config handler
|
|
|
|
ExcludeGroupRole []string
|
2020-09-22 21:11:49 +00:00
|
|
|
|
2020-12-16 20:29:16 +00:00
|
|
|
ExcludeResourceFunc func(kind, namespace, name string) bool
|
|
|
|
|
|
|
|
// JSONContext is the variable context
|
2022-04-09 11:52:50 +00:00
|
|
|
JSONContext context.Interface
|
2021-02-03 21:09:42 +00:00
|
|
|
|
|
|
|
// NamespaceLabels stores the label of namespace to be processed by namespace selector
|
|
|
|
NamespaceLabels map[string]string
|
2019-11-09 02:57:27 +00:00
|
|
|
}
|
2021-09-27 21:28:55 +00:00
|
|
|
|
|
|
|
func (pc *PolicyContext) Copy() *PolicyContext {
|
|
|
|
return &PolicyContext{
|
2021-09-28 06:40:05 +00:00
|
|
|
Policy: pc.Policy,
|
|
|
|
NewResource: pc.NewResource,
|
|
|
|
OldResource: pc.OldResource,
|
|
|
|
AdmissionInfo: pc.AdmissionInfo,
|
|
|
|
Client: pc.Client,
|
|
|
|
ExcludeGroupRole: pc.ExcludeGroupRole,
|
2021-09-27 21:28:55 +00:00
|
|
|
ExcludeResourceFunc: pc.ExcludeResourceFunc,
|
2021-09-28 06:40:05 +00:00
|
|
|
JSONContext: pc.JSONContext,
|
|
|
|
NamespaceLabels: pc.NamespaceLabels,
|
2021-09-27 21:28:55 +00:00
|
|
|
}
|
2021-09-28 06:40:05 +00:00
|
|
|
}
|