diff --git a/api/kyverno/v1/common_types.go b/api/kyverno/v1/common_types.go index 2dfb8bca38..7af2396a21 100644 --- a/api/kyverno/v1/common_types.go +++ b/api/kyverno/v1/common_types.go @@ -626,6 +626,13 @@ type Generation struct { // +optional Synchronize bool `json:"synchronize,omitempty" yaml:"synchronize,omitempty"` + // OrphanDownstreamOnPolicyDelete controls whether generated resources should be deleted when the rule that generated + // them is deleted with synchronization enabled. This option is only applicable to generate rules of the data type. + // See https://kyverno.io/docs/writing-policies/generate/#data-examples. + // Defaults to "false" if not specified. + // +optional + OrphanDownstreamOnPolicyDelete bool `json:"orphanDownstreamOnPolicyDelete,omitempty" yaml:"orphanDownstreamOnPolicyDelete,omitempty"` + // Data provides the resource declaration used to populate each generated resource. // At most one of Data or Clone must be specified. If neither are provided, the generated // resource will be created with default data only. @@ -675,7 +682,7 @@ func (g *Generation) Validate(path *field.Path, namespaced bool, policyNamespace } } - generateType, _ := g.GetTypeAndSync() + generateType, _, _ := g.GetTypeAndSyncAndOrphanDownstream() if generateType == Data { return errs } @@ -776,11 +783,11 @@ const ( Clone GenerateType = "Clone" ) -func (g *Generation) GetTypeAndSync() (GenerateType, bool) { +func (g *Generation) GetTypeAndSyncAndOrphanDownstream() (GenerateType, bool, bool) { if g.RawData != nil { - return Data, g.Synchronize + return Data, g.Synchronize, g.OrphanDownstreamOnPolicyDelete } - return Clone, g.Synchronize + return Clone, g.Synchronize, g.OrphanDownstreamOnPolicyDelete } // CloneFrom provides the location of the source resource used to generate target resources. diff --git a/api/kyverno/v1/rule_types.go b/api/kyverno/v1/rule_types.go index b8bfdc3a2f..c61736cde2 100644 --- a/api/kyverno/v1/rule_types.go +++ b/api/kyverno/v1/rule_types.go @@ -174,11 +174,11 @@ func (r *Rule) IsPodSecurity() bool { return r.Validation.PodSecurity != nil } -func (r *Rule) GetGenerateTypeAndSync() (_ GenerateType, sync bool) { +func (r *Rule) GetTypeAndSyncAndOrphanDownstream() (_ GenerateType, sync bool, orphanDownstream bool) { if !r.HasGenerate() { return } - return r.Generation.GetTypeAndSync() + return r.Generation.GetTypeAndSyncAndOrphanDownstream() } func (r *Rule) GetAnyAllConditions() apiextensions.JSON { diff --git a/api/kyverno/v2beta1/rule_types.go b/api/kyverno/v2beta1/rule_types.go index 903641dd62..5793b622b7 100644 --- a/api/kyverno/v2beta1/rule_types.go +++ b/api/kyverno/v2beta1/rule_types.go @@ -137,11 +137,11 @@ func (r *Rule) HasGenerate() bool { return !datautils.DeepEqual(r.Generation, kyvernov1.Generation{}) } -func (r *Rule) GetGenerateTypeAndSync() (_ kyvernov1.GenerateType, sync bool) { +func (r *Rule) GetGenerateTypeAndSync() (_ kyvernov1.GenerateType, sync bool, orphanDownstream bool) { if !r.HasGenerate() { return } - return r.Generation.GetTypeAndSync() + return r.Generation.GetTypeAndSyncAndOrphanDownstream() } // ValidateRuleType checks only one type of rule is defined per rule diff --git a/charts/kyverno/charts/crds/templates/kyverno.yaml b/charts/kyverno/charts/crds/templates/kyverno.yaml index 227c4f3a1c..b3d7b155d5 100644 --- a/charts/kyverno/charts/crds/templates/kyverno.yaml +++ b/charts/kyverno/charts/crds/templates/kyverno.yaml @@ -11067,6 +11067,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls whether + generated resources should be deleted when the rule that + generated them is deleted with synchronization enabled. + This option is only applicable to generate rules of the + data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. If @@ -15520,6 +15528,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls + whether generated resources should be deleted when + the rule that generated them is deleted with synchronization + enabled. This option is only applicable to generate + rules of the data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. @@ -19949,6 +19965,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls whether + generated resources should be deleted when the rule that + generated them is deleted with synchronization enabled. + This option is only applicable to generate rules of the + data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. If @@ -24342,6 +24366,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls + whether generated resources should be deleted when + the rule that generated them is deleted with synchronization + enabled. This option is only applicable to generate + rules of the data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. @@ -29011,6 +29043,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls whether + generated resources should be deleted when the rule that + generated them is deleted with synchronization enabled. + This option is only applicable to generate rules of the + data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. If @@ -33465,6 +33505,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls + whether generated resources should be deleted when + the rule that generated them is deleted with synchronization + enabled. This option is only applicable to generate + rules of the data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. @@ -37895,6 +37943,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls whether + generated resources should be deleted when the rule that + generated them is deleted with synchronization enabled. + This option is only applicable to generate rules of the + data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. If @@ -42288,6 +42344,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls + whether generated resources should be deleted when + the rule that generated them is deleted with synchronization + enabled. This option is only applicable to generate + rules of the data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. diff --git a/cmd/cli/kubectl-kyverno/data/crds/kyverno.io_clusterpolicies.yaml b/cmd/cli/kubectl-kyverno/data/crds/kyverno.io_clusterpolicies.yaml index ccda23a704..8211d5224a 100644 --- a/cmd/cli/kubectl-kyverno/data/crds/kyverno.io_clusterpolicies.yaml +++ b/cmd/cli/kubectl-kyverno/data/crds/kyverno.io_clusterpolicies.yaml @@ -1115,6 +1115,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls whether + generated resources should be deleted when the rule that + generated them is deleted with synchronization enabled. + This option is only applicable to generate rules of the + data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. If @@ -5568,6 +5576,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls + whether generated resources should be deleted when + the rule that generated them is deleted with synchronization + enabled. This option is only applicable to generate + rules of the data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. @@ -9997,6 +10013,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls whether + generated resources should be deleted when the rule that + generated them is deleted with synchronization enabled. + This option is only applicable to generate rules of the + data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. If @@ -14390,6 +14414,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls + whether generated resources should be deleted when + the rule that generated them is deleted with synchronization + enabled. This option is only applicable to generate + rules of the data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. diff --git a/cmd/cli/kubectl-kyverno/data/crds/kyverno.io_policies.yaml b/cmd/cli/kubectl-kyverno/data/crds/kyverno.io_policies.yaml index 7e7b7527a2..10bc7926d4 100644 --- a/cmd/cli/kubectl-kyverno/data/crds/kyverno.io_policies.yaml +++ b/cmd/cli/kubectl-kyverno/data/crds/kyverno.io_policies.yaml @@ -1116,6 +1116,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls whether + generated resources should be deleted when the rule that + generated them is deleted with synchronization enabled. + This option is only applicable to generate rules of the + data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. If @@ -5570,6 +5578,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls + whether generated resources should be deleted when + the rule that generated them is deleted with synchronization + enabled. This option is only applicable to generate + rules of the data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. @@ -10000,6 +10016,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls whether + generated resources should be deleted when the rule that + generated them is deleted with synchronization enabled. + This option is only applicable to generate rules of the + data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. If @@ -14393,6 +14417,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls + whether generated resources should be deleted when + the rule that generated them is deleted with synchronization + enabled. This option is only applicable to generate + rules of the data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. diff --git a/config/crds/kyverno/kyverno.io_clusterpolicies.yaml b/config/crds/kyverno/kyverno.io_clusterpolicies.yaml index ccda23a704..8211d5224a 100644 --- a/config/crds/kyverno/kyverno.io_clusterpolicies.yaml +++ b/config/crds/kyverno/kyverno.io_clusterpolicies.yaml @@ -1115,6 +1115,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls whether + generated resources should be deleted when the rule that + generated them is deleted with synchronization enabled. + This option is only applicable to generate rules of the + data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. If @@ -5568,6 +5576,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls + whether generated resources should be deleted when + the rule that generated them is deleted with synchronization + enabled. This option is only applicable to generate + rules of the data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. @@ -9997,6 +10013,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls whether + generated resources should be deleted when the rule that + generated them is deleted with synchronization enabled. + This option is only applicable to generate rules of the + data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. If @@ -14390,6 +14414,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls + whether generated resources should be deleted when + the rule that generated them is deleted with synchronization + enabled. This option is only applicable to generate + rules of the data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. diff --git a/config/crds/kyverno/kyverno.io_policies.yaml b/config/crds/kyverno/kyverno.io_policies.yaml index 7e7b7527a2..10bc7926d4 100644 --- a/config/crds/kyverno/kyverno.io_policies.yaml +++ b/config/crds/kyverno/kyverno.io_policies.yaml @@ -1116,6 +1116,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls whether + generated resources should be deleted when the rule that + generated them is deleted with synchronization enabled. + This option is only applicable to generate rules of the + data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. If @@ -5570,6 +5578,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls + whether generated resources should be deleted when + the rule that generated them is deleted with synchronization + enabled. This option is only applicable to generate + rules of the data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. @@ -10000,6 +10016,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls whether + generated resources should be deleted when the rule that + generated them is deleted with synchronization enabled. + This option is only applicable to generate rules of the + data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. If @@ -14393,6 +14417,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls + whether generated resources should be deleted when + the rule that generated them is deleted with synchronization + enabled. This option is only applicable to generate + rules of the data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. diff --git a/config/install-latest-testing.yaml b/config/install-latest-testing.yaml index c7af852d77..29d7e60390 100644 --- a/config/install-latest-testing.yaml +++ b/config/install-latest-testing.yaml @@ -11285,6 +11285,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls whether + generated resources should be deleted when the rule that + generated them is deleted with synchronization enabled. + This option is only applicable to generate rules of the + data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. If @@ -15738,6 +15746,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls + whether generated resources should be deleted when + the rule that generated them is deleted with synchronization + enabled. This option is only applicable to generate + rules of the data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. @@ -20167,6 +20183,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls whether + generated resources should be deleted when the rule that + generated them is deleted with synchronization enabled. + This option is only applicable to generate rules of the + data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. If @@ -24560,6 +24584,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls + whether generated resources should be deleted when + the rule that generated them is deleted with synchronization + enabled. This option is only applicable to generate + rules of the data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. @@ -29231,6 +29263,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls whether + generated resources should be deleted when the rule that + generated them is deleted with synchronization enabled. + This option is only applicable to generate rules of the + data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. If @@ -33685,6 +33725,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls + whether generated resources should be deleted when + the rule that generated them is deleted with synchronization + enabled. This option is only applicable to generate + rules of the data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. @@ -38115,6 +38163,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls whether + generated resources should be deleted when the rule that + generated them is deleted with synchronization enabled. + This option is only applicable to generate rules of the + data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. If @@ -42508,6 +42564,14 @@ spec: namespace: description: Namespace specifies resource namespace. type: string + orphanDownstreamOnPolicyDelete: + description: OrphanDownstreamOnPolicyDelete controls + whether generated resources should be deleted when + the rule that generated them is deleted with synchronization + enabled. This option is only applicable to generate + rules of the data type. See https://kyverno.io/docs/writing-policies/generate/#data-examples. + Defaults to "false" if not specified. + type: boolean synchronize: description: Synchronize controls if generated resources should be kept in-sync with their source resource. diff --git a/docs/user/crd/index.html b/docs/user/crd/index.html index 598ab84a27..b2f0dc2fa4 100644 --- a/docs/user/crd/index.html +++ b/docs/user/crd/index.html @@ -1895,6 +1895,21 @@ Optional. Defaults to “false” if not specified.
orphanDownstreamOnPolicyDelete
OrphanDownstreamOnPolicyDelete controls whether generated resources should be deleted when the rule that generated +them is deleted with synchronization enabled. This option is only applicable to generate rules of the data type. +See https://kyverno.io/docs/writing-policies/generate/#data-examples. +Defaults to “false” if not specified.
+data