diff --git a/README.md b/README.md index a7f8c4e01d..65f79665d2 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,8 @@ spec: generate: kind: ConfigMap name: zk-kafka-address + # create the resource in the new namespace + namespace: "{{request.object.name}}" data: kind: ConfigMap data: diff --git a/documentation/writing-policies.md b/documentation/writing-policies.md index 17d6932599..60ccf5beb2 100644 --- a/documentation/writing-policies.md +++ b/documentation/writing-policies.md @@ -76,7 +76,7 @@ spec : - key: name # compares (key operator value) operator: Equal value: name # constant "name" == "name" - - key: "{{serviceAccount}}" # refer to a pre-defined variable serviceAccount + - key: "{{serviceAccountName}}" # refer to a pre-defined variable serviceAccountName operator: NotEqual value: "user1" # if service # Each rule can contain a single validate, mutate, or generate directive diff --git a/pkg/generate/generate.go b/pkg/generate/generate.go index 791b386f61..3d85f8bbe2 100644 --- a/pkg/generate/generate.go +++ b/pkg/generate/generate.go @@ -232,17 +232,20 @@ func variableSubsitutionForAttributes(gen kyverno.Generation, ctx context.EvalIn if newNamespace, ok := newNamespaceVar.(string); ok { gen.Namespace = newNamespace } - // Clone - cloneName := gen.Clone.Name - cloneNamespace := gen.Clone.Namespace - newcloneNameVar := variables.SubstituteVariables(ctx, cloneName) - if newcloneName, ok := newcloneNameVar.(string); ok { - gen.Clone.Name = newcloneName - } - newcloneNamespaceVar := variables.SubstituteVariables(ctx, cloneNamespace) - if newcloneNamespace, ok := newcloneNamespaceVar.(string); ok { - gen.Clone.Namespace = newcloneNamespace + if gen.Clone != (kyverno.CloneFrom{}) { + // Clone + cloneName := gen.Clone.Name + cloneNamespace := gen.Clone.Namespace + + newcloneNameVar := variables.SubstituteVariables(ctx, cloneName) + if newcloneName, ok := newcloneNameVar.(string); ok { + gen.Clone.Name = newcloneName + } + newcloneNamespaceVar := variables.SubstituteVariables(ctx, cloneNamespace) + if newcloneNamespace, ok := newcloneNamespaceVar.(string); ok { + gen.Clone.Namespace = newcloneNamespace + } } return gen }