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