mirror of
https://github.com/kyverno/kyverno.git
synced 2025-04-08 10:04:25 +00:00
update from to clone for copying existing resource
This commit is contained in:
parent
2ecc1d21f7
commit
b59ab9a84a
4 changed files with 12 additions and 12 deletions
|
@ -110,7 +110,7 @@ spec:
|
|||
type: string
|
||||
namespace:
|
||||
type: string
|
||||
from:
|
||||
clone:
|
||||
type: object
|
||||
required:
|
||||
- namespace
|
||||
|
|
|
@ -65,12 +65,12 @@ type Generation struct {
|
|||
Name string `json:"name"`
|
||||
Namespace string `json:"namespace"`
|
||||
Data interface{} `json:"data"`
|
||||
From *CopyFrom `json:"from"`
|
||||
Clone *CloneFrom `json:"clone"`
|
||||
}
|
||||
|
||||
// CopyFrom - location of a Secret or a ConfigMap
|
||||
// CloneFrom - location of a Secret or a ConfigMap
|
||||
// which will be used as source when applying 'generate'
|
||||
type CopyFrom struct {
|
||||
type CloneFrom struct {
|
||||
Namespace string `json:"namespace"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
|
|
@ -64,8 +64,11 @@ func (pp *Patch) Validate() error {
|
|||
|
||||
// Validate returns error if generator is configured incompletely
|
||||
func (pcg *Generation) Validate() error {
|
||||
if pcg.Data == nil && pcg.From == nil {
|
||||
return fmt.Errorf("Neither Data nor CopyFrom (source) of %s is specified", pcg.Kind)
|
||||
if pcg.Data == nil && pcg.Clone == nil {
|
||||
return fmt.Errorf("Neither data nor clone (source) of %s is specified", pcg.Kind)
|
||||
}
|
||||
if pcg.Data != nil && pcg.Clone != nil {
|
||||
return fmt.Errorf("Both data nor clone (source) of %s are specified", pcg.Kind)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -202,9 +202,6 @@ func keyExist(data map[string]interface{}, key string) (ok bool) {
|
|||
// support mode 'data' -> create resource
|
||||
// To-Do: support 'from' -> copy/clone the resource
|
||||
func (c *Client) GenerateResource(generator types.Generation, namespace string) error {
|
||||
if generator.Data != nil && generator.From != nil {
|
||||
return errors.New("generate only supports on the modes data or from")
|
||||
}
|
||||
var err error
|
||||
rGVR := c.getGVRFromKind(generator.Kind)
|
||||
resource := &unstructured.Unstructured{}
|
||||
|
@ -222,9 +219,9 @@ func (c *Client) GenerateResource(generator types.Generation, namespace string)
|
|||
return errors.New("mandatory keys not defined")
|
||||
}
|
||||
}
|
||||
// from -> create new resource
|
||||
if generator.From != nil {
|
||||
resource, err = c.GetResource(rGVR.Resource, generator.From.Namespace, generator.From.Name)
|
||||
// clone -> copy from existing resource
|
||||
if generator.Clone != nil {
|
||||
resource, err = c.GetResource(rGVR.Resource, generator.Clone.Namespace, generator.Clone.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue