mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
require generate.apiVersion (#7080)
Signed-off-by: ShutingZhao <shuting@nirmata.com>
This commit is contained in:
parent
999efcebaf
commit
a7900ff40c
4 changed files with 11 additions and 4 deletions
|
@ -46,7 +46,7 @@ func (g *Generate) Validate(ctx context.Context) (string, error) {
|
|||
return "", fmt.Errorf("only one of clone or cloneList can be specified")
|
||||
}
|
||||
|
||||
kind, name, namespace := rule.Kind, rule.Name, rule.Namespace
|
||||
apiVersion, kind, name, namespace := rule.ResourceSpec.GetAPIVersion(), rule.ResourceSpec.GetKind(), rule.ResourceSpec.GetName(), rule.ResourceSpec.GetNamespace()
|
||||
|
||||
if len(rule.CloneList.Kinds) == 0 {
|
||||
if name == "" {
|
||||
|
@ -55,6 +55,9 @@ func (g *Generate) Validate(ctx context.Context) (string, error) {
|
|||
if kind == "" {
|
||||
return "kind", fmt.Errorf("kind cannot be empty")
|
||||
}
|
||||
if apiVersion == "" {
|
||||
return "apiVersion", fmt.Errorf("apiVersion cannot be empty")
|
||||
}
|
||||
} else {
|
||||
if name != "" {
|
||||
return "name", fmt.Errorf("with cloneList, generate.name. should not be specified")
|
||||
|
|
|
@ -35,9 +35,9 @@ func Test_Validate_Generate(t *testing.T) {
|
|||
err := json.Unmarshal(rawGenerate, &genRule)
|
||||
assert.NilError(t, err)
|
||||
checker := NewFakeGenerate(genRule)
|
||||
if _, err := checker.Validate(context.TODO()); err != nil {
|
||||
assert.Assert(t, err != nil)
|
||||
}
|
||||
_, err = checker.Validate(context.TODO())
|
||||
t.Log(err)
|
||||
assert.Assert(t, err != nil)
|
||||
}
|
||||
|
||||
func Test_Validate_Generate_HasAnchors(t *testing.T) {
|
||||
|
|
|
@ -38,6 +38,7 @@ spec:
|
|||
generate:
|
||||
kind: Role
|
||||
name: ns-role
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
namespace: "{{request.object.metadata.name}}"
|
||||
synchronize: true
|
||||
clone:
|
||||
|
@ -52,6 +53,7 @@ spec:
|
|||
generate:
|
||||
kind: RoleBinding
|
||||
name: ns-role-binding
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
namespace: "{{request.object.metadata.name}}"
|
||||
synchronize: true
|
||||
clone:
|
||||
|
|
|
@ -14,6 +14,7 @@ spec:
|
|||
generate:
|
||||
kind: Role
|
||||
name: ns-role
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
namespace: "{{request.object.metadata.name}}"
|
||||
synchronize: true
|
||||
data:
|
||||
|
@ -30,6 +31,7 @@ spec:
|
|||
generate:
|
||||
kind: RoleBinding
|
||||
name: ns-role-binding
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
namespace: "{{request.object.metadata.name}}"
|
||||
synchronize: true
|
||||
data:
|
||||
|
|
Loading…
Reference in a new issue