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")
|
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 len(rule.CloneList.Kinds) == 0 {
|
||||||
if name == "" {
|
if name == "" {
|
||||||
|
@ -55,6 +55,9 @@ func (g *Generate) Validate(ctx context.Context) (string, error) {
|
||||||
if kind == "" {
|
if kind == "" {
|
||||||
return "kind", fmt.Errorf("kind cannot be empty")
|
return "kind", fmt.Errorf("kind cannot be empty")
|
||||||
}
|
}
|
||||||
|
if apiVersion == "" {
|
||||||
|
return "apiVersion", fmt.Errorf("apiVersion cannot be empty")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if name != "" {
|
if name != "" {
|
||||||
return "name", fmt.Errorf("with cloneList, generate.name. should not be specified")
|
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)
|
err := json.Unmarshal(rawGenerate, &genRule)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
checker := NewFakeGenerate(genRule)
|
checker := NewFakeGenerate(genRule)
|
||||||
if _, err := checker.Validate(context.TODO()); err != nil {
|
_, err = checker.Validate(context.TODO())
|
||||||
assert.Assert(t, err != nil)
|
t.Log(err)
|
||||||
}
|
assert.Assert(t, err != nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_Validate_Generate_HasAnchors(t *testing.T) {
|
func Test_Validate_Generate_HasAnchors(t *testing.T) {
|
||||||
|
|
|
@ -38,6 +38,7 @@ spec:
|
||||||
generate:
|
generate:
|
||||||
kind: Role
|
kind: Role
|
||||||
name: ns-role
|
name: ns-role
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
namespace: "{{request.object.metadata.name}}"
|
namespace: "{{request.object.metadata.name}}"
|
||||||
synchronize: true
|
synchronize: true
|
||||||
clone:
|
clone:
|
||||||
|
@ -52,6 +53,7 @@ spec:
|
||||||
generate:
|
generate:
|
||||||
kind: RoleBinding
|
kind: RoleBinding
|
||||||
name: ns-role-binding
|
name: ns-role-binding
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
namespace: "{{request.object.metadata.name}}"
|
namespace: "{{request.object.metadata.name}}"
|
||||||
synchronize: true
|
synchronize: true
|
||||||
clone:
|
clone:
|
||||||
|
|
|
@ -14,6 +14,7 @@ spec:
|
||||||
generate:
|
generate:
|
||||||
kind: Role
|
kind: Role
|
||||||
name: ns-role
|
name: ns-role
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
namespace: "{{request.object.metadata.name}}"
|
namespace: "{{request.object.metadata.name}}"
|
||||||
synchronize: true
|
synchronize: true
|
||||||
data:
|
data:
|
||||||
|
@ -30,6 +31,7 @@ spec:
|
||||||
generate:
|
generate:
|
||||||
kind: RoleBinding
|
kind: RoleBinding
|
||||||
name: ns-role-binding
|
name: ns-role-binding
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
namespace: "{{request.object.metadata.name}}"
|
namespace: "{{request.object.metadata.name}}"
|
||||||
synchronize: true
|
synchronize: true
|
||||||
data:
|
data:
|
||||||
|
|
Loading…
Reference in a new issue