mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-15 17:51:20 +00:00
- Correct crd yaml, since we only allow 1 generation per rule. - update example for generator
This commit is contained in:
parent
e8de9a111a
commit
36f76a0f2f
4 changed files with 41 additions and 54 deletions
|
@ -29,14 +29,14 @@ spec:
|
|||
required:
|
||||
- name
|
||||
- resource
|
||||
parameters:
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
resource:
|
||||
type: object
|
||||
required:
|
||||
- kind
|
||||
parameters:
|
||||
properties:
|
||||
kind:
|
||||
type: string
|
||||
enum:
|
||||
|
@ -115,36 +115,33 @@ spec:
|
|||
pattern:
|
||||
AnyValue: {}
|
||||
generate:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
required:
|
||||
- kind
|
||||
- name
|
||||
- copyFrom
|
||||
properties:
|
||||
kind:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
copyFrom:
|
||||
type: object
|
||||
required:
|
||||
- namespace
|
||||
- name
|
||||
properties:
|
||||
namespace:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
data:
|
||||
type: object
|
||||
additionalProperties:
|
||||
type: object
|
||||
required:
|
||||
- kind
|
||||
- name
|
||||
properties:
|
||||
kind:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
copyFrom:
|
||||
type: object
|
||||
required:
|
||||
- namespace
|
||||
- name
|
||||
properties:
|
||||
namespace:
|
||||
type: string
|
||||
labels:
|
||||
type: object
|
||||
additionalProperties:
|
||||
name:
|
||||
type: string
|
||||
data:
|
||||
type: object
|
||||
additionalProperties:
|
||||
type: string
|
||||
labels:
|
||||
type: object
|
||||
additionalProperties:
|
||||
type: string
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
|
|
|
@ -4,15 +4,17 @@ metadata :
|
|||
name: "policy-configmapgenerator-test"
|
||||
spec:
|
||||
rules:
|
||||
- name: "Policy ConfigMap sample rule"
|
||||
resource:
|
||||
- name: "copyCM"
|
||||
resource :
|
||||
kind : Namespace
|
||||
name: "ns2"
|
||||
generate:
|
||||
selector:
|
||||
matchLabels:
|
||||
LabelForSelector : "namespace2"
|
||||
generate :
|
||||
kind: ConfigMap
|
||||
name: copied-cm
|
||||
copyFrom:
|
||||
namespace: default
|
||||
name: game-config
|
||||
data:
|
||||
name : copied-cm
|
||||
copyFrom :
|
||||
namespace : default
|
||||
name : game-config
|
||||
data :
|
||||
secretData: "data from cmg"
|
|
@ -62,7 +62,7 @@ type Validation struct {
|
|||
type Generation struct {
|
||||
Kind string `json:"kind"`
|
||||
Name string `json:"name"`
|
||||
CopyFrom *CopyFrom `json:"copyFrom,omitempty"`
|
||||
CopyFrom *CopyFrom `json:"copyFrom"`
|
||||
Data map[string]string `json:"data"`
|
||||
Labels map[string]string `json:"labels"`
|
||||
}
|
||||
|
|
|
@ -64,22 +64,10 @@ func (pp *Patch) Validate() error {
|
|||
return fmt.Errorf("Unsupported JSONPatch operation '%s'", pp.Operation)
|
||||
}
|
||||
|
||||
// Validate returns error if Name or namespace is not cpecified
|
||||
func (pcf *CopyFrom) Validate() error {
|
||||
if pcf.Name == "" || pcf.Namespace == "" {
|
||||
return errors.New("Name or/and Namespace is not specified")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Validate returns error if generator is configured incompletely
|
||||
func (pcg *Generation) Validate() error {
|
||||
if pcg.Name == "" || pcg.Kind == "" {
|
||||
return errors.New("Name or/and Kind of generator is not specified")
|
||||
}
|
||||
|
||||
if pcg.CopyFrom != nil {
|
||||
return pcg.CopyFrom.Validate()
|
||||
if len(pcg.Data) == 0 && pcg.CopyFrom == nil {
|
||||
return fmt.Errorf("Neither Data nor CopyFrom (source) of %s/%s is specified", pcg.Kind, pcg.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue