Skip to content

Commit

Permalink
chore: split api files
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly committed Oct 2, 2023
1 parent 312135a commit b26d4cd
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 89 deletions.
3 changes: 1 addition & 2 deletions config/crds/json.kyverno.io_policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ spec:
can be used during rule execution.
items:
description: ContextEntry adds variables and data sources
to a rule Context. Either a ConfigMap reference or a APILookup
must be provided.
to a rule Context.
properties:
name:
description: Name is the variable name.
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/v1alpha1/context_entry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package v1alpha1

// ContextEntry adds variables and data sources to a rule Context.
type ContextEntry struct {
// Name is the variable name.
Name string `json:"name"`

// Variable defines an arbitrary JMESPath context variable that can be defined inline.
Variable *Variable `json:"variable,omitempty"`
}
11 changes: 11 additions & 0 deletions pkg/apis/v1alpha1/match_resources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package v1alpha1

type MatchResources struct {
// Any allows specifying resources which will be ORed
// +optional
Any ResourceFilters `json:"any,omitempty"`

// All allows specifying resources which will be ANDed
// +optional
All ResourceFilters `json:"all,omitempty"`
}
85 changes: 0 additions & 85 deletions pkg/apis/v1alpha1/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,88 +14,3 @@ type Policy struct {
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec PolicySpec `json:"spec"`
}

type PolicySpec struct {
// Rules is a list of Rule instances. A Policy contains multiple rules and
// each rule can validate, mutate, or generate resources.
Rules []Rule `json:"rules,omitempty"`
}

type Rule struct {
// Name is a label to identify the rule, It must be unique within the policy.
// +kubebuilder:validation:MaxLength=63
Name string `json:"name"`

// Context defines variables and data sources that can be used during rule execution.
// +optional
Context []ContextEntry `json:"context,omitempty"`

// MatchResources defines when this policy rule should be applied. The match
// criteria can include resource information (e.g. kind, name, namespace, labels)
// and admission review request information like the user name or role.
// At least one kind is required.
MatchResources *MatchResources `json:"match,omitempty"`

// ExcludeResources defines when this policy rule should not be applied. The exclude
// criteria can include resource information (e.g. kind, name, namespace, labels)
// and admission review request information like the name or role.
// +optional
ExcludeResources *MatchResources `json:"exclude,omitempty"`

// Validation is used to validate matching resources.
// +optional
Validation *Validation `json:"validate,omitempty"`
}

// ContextEntry adds variables and data sources to a rule Context. Either a
// ConfigMap reference or a APILookup must be provided.
type ContextEntry struct {
// Name is the variable name.
Name string `json:"name"`

// Variable defines an arbitrary JMESPath context variable that can be defined inline.
Variable *Variable `json:"variable,omitempty"`
}

// Variable defines an arbitrary JMESPath context variable that can be defined inline.
type Variable struct {
// Value is any arbitrary JSON object representable in YAML or JSON form.
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
Value interface{} `json:"value,omitempty"`
}

type MatchResources struct {
// Any allows specifying resources which will be ORed
// +optional
Any ResourceFilters `json:"any,omitempty"`

// All allows specifying resources which will be ANDed
// +optional
All ResourceFilters `json:"all,omitempty"`
}

// ResourceFilters is a slice of ResourceFilter
type ResourceFilters []ResourceFilter

// ResourceFilter allow users to "AND" or "OR" between resources
type ResourceFilter struct {
// ResourceDescription contains information about the resource being created or modified.
// +kubebuilder:validation:Type=object
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
Resource map[string]interface{} `json:"resource,omitempty"`
}

// Validation defines checks to be performed on matching resources.
type Validation struct {
// Message specifies a custom message to be displayed on failure.
// +optional
Message string `json:"message,omitempty"`

// Pattern specifies an overlay-style pattern used to check resources.
// +kubebuilder:validation:Type=object
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
Pattern map[string]interface{} `json:"pattern,omitempty"`
}
7 changes: 7 additions & 0 deletions pkg/apis/v1alpha1/policy_spec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package v1alpha1

type PolicySpec struct {
// Rules is a list of Rule instances. A Policy contains multiple rules and
// each rule can validate, mutate, or generate resources.
Rules []Rule `json:"rules,omitempty"`
}
10 changes: 10 additions & 0 deletions pkg/apis/v1alpha1/resource_filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package v1alpha1

// ResourceFilter allow users to "AND" or "OR" between resources
type ResourceFilter struct {
// ResourceDescription contains information about the resource being created or modified.
// +kubebuilder:validation:Type=object
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
Resource map[string]interface{} `json:"resource,omitempty"`
}
4 changes: 4 additions & 0 deletions pkg/apis/v1alpha1/resource_filters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package v1alpha1

// ResourceFilters is a slice of ResourceFilter
type ResourceFilters []ResourceFilter
27 changes: 27 additions & 0 deletions pkg/apis/v1alpha1/rule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package v1alpha1

type Rule struct {
// Name is a label to identify the rule, It must be unique within the policy.
// +kubebuilder:validation:MaxLength=63
Name string `json:"name"`

// Context defines variables and data sources that can be used during rule execution.
// +optional
Context []ContextEntry `json:"context,omitempty"`

// MatchResources defines when this policy rule should be applied. The match
// criteria can include resource information (e.g. kind, name, namespace, labels)
// and admission review request information like the user name or role.
// At least one kind is required.
MatchResources *MatchResources `json:"match,omitempty"`

// ExcludeResources defines when this policy rule should not be applied. The exclude
// criteria can include resource information (e.g. kind, name, namespace, labels)
// and admission review request information like the name or role.
// +optional
ExcludeResources *MatchResources `json:"exclude,omitempty"`

// Validation is used to validate matching resources.
// +optional
Validation *Validation `json:"validate,omitempty"`
}
14 changes: 14 additions & 0 deletions pkg/apis/v1alpha1/validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package v1alpha1

// Validation defines checks to be performed on matching resources.
type Validation struct {
// Message specifies a custom message to be displayed on failure.
// +optional
Message string `json:"message,omitempty"`

// Pattern specifies an overlay-style pattern used to check resources.
// +kubebuilder:validation:Type=object
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
Pattern map[string]interface{} `json:"pattern,omitempty"`
}
9 changes: 9 additions & 0 deletions pkg/apis/v1alpha1/variable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package v1alpha1

// Variable defines an arbitrary JMESPath context variable that can be defined inline.
type Variable struct {
// Value is any arbitrary JSON object representable in YAML or JSON form.
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
Value interface{} `json:"value,omitempty"`
}
3 changes: 1 addition & 2 deletions pkg/data/crds/json.kyverno.io_policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ spec:
can be used during rule execution.
items:
description: ContextEntry adds variables and data sources
to a rule Context. Either a ConfigMap reference or a APILookup
must be provided.
to a rule Context.
properties:
name:
description: Name is the variable name.
Expand Down

0 comments on commit b26d4cd

Please sign in to comment.