Skip to content

Commit

Permalink
fix: generate policy fails if triggered resource name exceeds 63 char…
Browse files Browse the repository at this point in the history
…acters limit (kyverno#8466)

* fix: generate label resource name character length issue

Signed-off-by: Chandan-DK <[email protected]>

* add source label

Signed-off-by: Chandan-DK <[email protected]>

* modify newUR function

Signed-off-by: Chandan-DK <[email protected]>

* fix

Signed-off-by: Chandan-DK <[email protected]>

* improve readability

Signed-off-by: Chandan-DK <[email protected]>

* remove generate source name label

Signed-off-by: Chandan-DK <[email protected]>

* Revert changes

Signed-off-by: Chandan-DK <[email protected]>

* update ResourceSpec

Signed-off-by: Chandan-DK <[email protected]>

* add URGenerateResourceUIDLabel

Signed-off-by: Chandan-DK <[email protected]>

* make codegen crds all

Signed-off-by: Chandan-DK <[email protected]>

* make codegen client all

Signed-off-by: Chandan-DK <[email protected]>

* add GenerateSourceUIDLabel

Signed-off-by: Chandan-DK <[email protected]>

* modify comment

Signed-off-by: Chandan-DK <[email protected]>

* make codegen crds all

Signed-off-by: Chandan-DK <[email protected]>

* make codegen-docs-all

Signed-off-by: Chandan-DK <[email protected]>

* make codegen-all

Signed-off-by: Chandan-DK <[email protected]>

* set trigger uid

Signed-off-by: Chandan-DK <[email protected]>

* add uid in transform()

Signed-off-by: Chandan-DK <[email protected]>

* add name label

Signed-off-by: Chandan-DK <[email protected]>

* fix: use resource name labels along with its UID

Signed-off-by: Mariam Fahmy <[email protected]>

* fix: use the resource name label only if its uid label isn't set

Signed-off-by: Mariam Fahmy <[email protected]>

* fix

Signed-off-by: Mariam Fahmy <[email protected]>

* add kuttl tests

Signed-off-by: Mariam Fahmy <[email protected]>

* fix: delete the trigger resource in the test

Signed-off-by: Mariam Fahmy <[email protected]>

* fix: delete the source in the kuttl test

Signed-off-by: Mariam Fahmy <[email protected]>

* add generate trigger uid label

Signed-off-by: Chandan-DK <[email protected]>

* modify TriggerInfo function

Signed-off-by: Chandan-DK <[email protected]>

* populate uid field for new update requests

Signed-off-by: Chandan-DK <[email protected]>

* populate new ur spec with uid

Signed-off-by: Chandan-DK <[email protected]>

* handle downstream resources cleanup

Signed-off-by: Chandan-DK <[email protected]>

* populate uid of ur status

Signed-off-by: Chandan-DK <[email protected]>

* fetch triggers by the UID label

Signed-off-by: ShutingZhao <[email protected]>

* label triggers

Signed-off-by: ShutingZhao <[email protected]>

* fetch trigger by comparing UID

Signed-off-by: ShutingZhao <[email protected]>

* fetch cloneList downstream resource by UID

Signed-off-by: ShutingZhao <[email protected]>

* update test names

Signed-off-by: ShutingZhao <[email protected]>

* remove trigger name label assertions from kuttl tests

Signed-off-by: ShutingZhao <[email protected]>

* add unit name selector

Signed-off-by: ShutingZhao <[email protected]>

* add sleep

Signed-off-by: ShutingZhao <[email protected]>

* assert events on failures

Signed-off-by: ShutingZhao <[email protected]>

* rename tests

Signed-off-by: ShutingZhao <[email protected]>

---------

Signed-off-by: Chandan-DK <[email protected]>
Signed-off-by: Chip Zoller <[email protected]>
Signed-off-by: Mariam Fahmy <[email protected]>
Signed-off-by: shuting <[email protected]>
Signed-off-by: ShutingZhao <[email protected]>
Co-authored-by: Chip Zoller <[email protected]>
Co-authored-by: Mariam Fahmy <[email protected]>
Co-authored-by: shuting <[email protected]>
  • Loading branch information
4 people authored Nov 6, 2023
1 parent 0dffab4 commit cafc099
Show file tree
Hide file tree
Showing 59 changed files with 572 additions and 56 deletions.
5 changes: 5 additions & 0 deletions api/kyverno/v1/resource_spec_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
)

type ResourceSpec struct {
Expand All @@ -20,12 +21,16 @@ type ResourceSpec struct {
// Name specifies the resource name.
// +optional
Name string `json:"name,omitempty" yaml:"name,omitempty"`
// UID specifies the resource uid.
// +optional
UID types.UID `json:"uid,omitempty" yaml:"uid,omitempty"`
}

func (s ResourceSpec) GetName() string { return s.Name }
func (s ResourceSpec) GetNamespace() string { return s.Namespace }
func (s ResourceSpec) GetKind() string { return s.Kind }
func (s ResourceSpec) GetAPIVersion() string { return s.APIVersion }
func (s ResourceSpec) GetUID() types.UID { return s.UID }
func (s ResourceSpec) GetGroupVersion() (schema.GroupVersion, error) {
return schema.ParseGroupVersion(s.APIVersion)
}
Expand Down
1 change: 1 addition & 0 deletions api/kyverno/v1beta1/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
// URGeneratePolicyLabel adds the policy name to URs for generate policies
URGeneratePolicyLabel = "generate.kyverno.io/policy-name"
URGenerateResourceNameLabel = "generate.kyverno.io/resource-name"
URGenerateResourceUIDLabel = "generate.kyverno.io/resource-uid"
URGenerateResourceNSLabel = "generate.kyverno.io/resource-namespace"
URGenerateResourceKindLabel = "generate.kyverno.io/resource-kind"
URGenerateRetryCountAnnotation = "generate.kyverno.io/retry-count"
Expand Down
54 changes: 54 additions & 0 deletions charts/kyverno/charts/crds/templates/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7429,6 +7429,9 @@ spec:
resource specified in the Clone declaration. Optional.
Defaults to "false" if not specified.
type: boolean
uid:
description: UID specifies the resource uid.
type: string
type: object
imageExtractors:
additionalProperties:
Expand Down Expand Up @@ -8694,6 +8697,9 @@ spec:
is supported for backwards compatibility but will
be deprecated in the next major release. See: https://kyverno.io/docs/writing-policies/preconditions/'
x-kubernetes-preserve-unknown-fields: true
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
type: object
Expand Down Expand Up @@ -11801,6 +11807,9 @@ spec:
Data or the resource specified in the Clone declaration.
Optional. Defaults to "false" if not specified.
type: boolean
uid:
description: UID specifies the resource uid.
type: string
type: object
imageExtractors:
additionalProperties:
Expand Down Expand Up @@ -13122,6 +13131,9 @@ spec:
will be deprecated in the next major release.
See: https://kyverno.io/docs/writing-policies/preconditions/'
x-kubernetes-preserve-unknown-fields: true
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
type: object
Expand Down Expand Up @@ -16193,6 +16205,9 @@ spec:
resource specified in the Clone declaration. Optional.
Defaults to "false" if not specified.
type: boolean
uid:
description: UID specifies the resource uid.
type: string
type: object
imageExtractors:
additionalProperties:
Expand Down Expand Up @@ -17245,6 +17260,9 @@ spec:
is supported for backwards compatibility but will
be deprecated in the next major release. See: https://kyverno.io/docs/writing-policies/preconditions/'
x-kubernetes-preserve-unknown-fields: true
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
type: object
Expand Down Expand Up @@ -20505,6 +20523,9 @@ spec:
Data or the resource specified in the Clone declaration.
Optional. Defaults to "false" if not specified.
type: boolean
uid:
description: UID specifies the resource uid.
type: string
type: object
imageExtractors:
additionalProperties:
Expand Down Expand Up @@ -21826,6 +21847,9 @@ spec:
will be deprecated in the next major release.
See: https://kyverno.io/docs/writing-policies/preconditions/'
x-kubernetes-preserve-unknown-fields: true
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
type: object
Expand Down Expand Up @@ -25137,6 +25161,9 @@ spec:
resource specified in the Clone declaration. Optional.
Defaults to "false" if not specified.
type: boolean
uid:
description: UID specifies the resource uid.
type: string
type: object
imageExtractors:
additionalProperties:
Expand Down Expand Up @@ -26402,6 +26429,9 @@ spec:
is supported for backwards compatibility but will
be deprecated in the next major release. See: https://kyverno.io/docs/writing-policies/preconditions/'
x-kubernetes-preserve-unknown-fields: true
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
type: object
Expand Down Expand Up @@ -29510,6 +29540,9 @@ spec:
Data or the resource specified in the Clone declaration.
Optional. Defaults to "false" if not specified.
type: boolean
uid:
description: UID specifies the resource uid.
type: string
type: object
imageExtractors:
additionalProperties:
Expand Down Expand Up @@ -30831,6 +30864,9 @@ spec:
will be deprecated in the next major release.
See: https://kyverno.io/docs/writing-policies/preconditions/'
x-kubernetes-preserve-unknown-fields: true
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
type: object
Expand Down Expand Up @@ -33903,6 +33939,9 @@ spec:
resource specified in the Clone declaration. Optional.
Defaults to "false" if not specified.
type: boolean
uid:
description: UID specifies the resource uid.
type: string
type: object
imageExtractors:
additionalProperties:
Expand Down Expand Up @@ -34955,6 +34994,9 @@ spec:
is supported for backwards compatibility but will
be deprecated in the next major release. See: https://kyverno.io/docs/writing-policies/preconditions/'
x-kubernetes-preserve-unknown-fields: true
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
type: object
Expand Down Expand Up @@ -38215,6 +38257,9 @@ spec:
Data or the resource specified in the Clone declaration.
Optional. Defaults to "false" if not specified.
type: boolean
uid:
description: UID specifies the resource uid.
type: string
type: object
imageExtractors:
additionalProperties:
Expand Down Expand Up @@ -39536,6 +39581,9 @@ spec:
will be deprecated in the next major release.
See: https://kyverno.io/docs/writing-policies/preconditions/'
x-kubernetes-preserve-unknown-fields: true
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
type: object
Expand Down Expand Up @@ -43274,6 +43322,9 @@ spec:
namespace:
description: Namespace specifies resource namespace.
type: string
uid:
description: UID specifies the resource uid.
type: string
type: object
rule:
description: Rule is the associate rule name of the current UR.
Expand Down Expand Up @@ -43309,6 +43360,9 @@ spec:
namespace:
description: Namespace specifies resource namespace.
type: string
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
handler:
Expand Down
24 changes: 24 additions & 0 deletions cmd/cli/kubectl-kyverno/data/crds/kyverno.io_clusterpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,9 @@ spec:
resource specified in the Clone declaration. Optional.
Defaults to "false" if not specified.
type: boolean
uid:
description: UID specifies the resource uid.
type: string
type: object
imageExtractors:
additionalProperties:
Expand Down Expand Up @@ -2388,6 +2391,9 @@ spec:
is supported for backwards compatibility but will
be deprecated in the next major release. See: https://kyverno.io/docs/writing-policies/preconditions/'
x-kubernetes-preserve-unknown-fields: true
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
type: object
Expand Down Expand Up @@ -5495,6 +5501,9 @@ spec:
Data or the resource specified in the Clone declaration.
Optional. Defaults to "false" if not specified.
type: boolean
uid:
description: UID specifies the resource uid.
type: string
type: object
imageExtractors:
additionalProperties:
Expand Down Expand Up @@ -6816,6 +6825,9 @@ spec:
will be deprecated in the next major release.
See: https://kyverno.io/docs/writing-policies/preconditions/'
x-kubernetes-preserve-unknown-fields: true
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
type: object
Expand Down Expand Up @@ -9887,6 +9899,9 @@ spec:
resource specified in the Clone declaration. Optional.
Defaults to "false" if not specified.
type: boolean
uid:
description: UID specifies the resource uid.
type: string
type: object
imageExtractors:
additionalProperties:
Expand Down Expand Up @@ -10939,6 +10954,9 @@ spec:
is supported for backwards compatibility but will
be deprecated in the next major release. See: https://kyverno.io/docs/writing-policies/preconditions/'
x-kubernetes-preserve-unknown-fields: true
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
type: object
Expand Down Expand Up @@ -14199,6 +14217,9 @@ spec:
Data or the resource specified in the Clone declaration.
Optional. Defaults to "false" if not specified.
type: boolean
uid:
description: UID specifies the resource uid.
type: string
type: object
imageExtractors:
additionalProperties:
Expand Down Expand Up @@ -15520,6 +15541,9 @@ spec:
will be deprecated in the next major release.
See: https://kyverno.io/docs/writing-policies/preconditions/'
x-kubernetes-preserve-unknown-fields: true
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
type: object
Expand Down
24 changes: 24 additions & 0 deletions cmd/cli/kubectl-kyverno/data/crds/kyverno.io_policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,9 @@ spec:
resource specified in the Clone declaration. Optional.
Defaults to "false" if not specified.
type: boolean
uid:
description: UID specifies the resource uid.
type: string
type: object
imageExtractors:
additionalProperties:
Expand Down Expand Up @@ -2389,6 +2392,9 @@ spec:
is supported for backwards compatibility but will
be deprecated in the next major release. See: https://kyverno.io/docs/writing-policies/preconditions/'
x-kubernetes-preserve-unknown-fields: true
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
type: object
Expand Down Expand Up @@ -5497,6 +5503,9 @@ spec:
Data or the resource specified in the Clone declaration.
Optional. Defaults to "false" if not specified.
type: boolean
uid:
description: UID specifies the resource uid.
type: string
type: object
imageExtractors:
additionalProperties:
Expand Down Expand Up @@ -6818,6 +6827,9 @@ spec:
will be deprecated in the next major release.
See: https://kyverno.io/docs/writing-policies/preconditions/'
x-kubernetes-preserve-unknown-fields: true
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
type: object
Expand Down Expand Up @@ -9890,6 +9902,9 @@ spec:
resource specified in the Clone declaration. Optional.
Defaults to "false" if not specified.
type: boolean
uid:
description: UID specifies the resource uid.
type: string
type: object
imageExtractors:
additionalProperties:
Expand Down Expand Up @@ -10942,6 +10957,9 @@ spec:
is supported for backwards compatibility but will
be deprecated in the next major release. See: https://kyverno.io/docs/writing-policies/preconditions/'
x-kubernetes-preserve-unknown-fields: true
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
type: object
Expand Down Expand Up @@ -14202,6 +14220,9 @@ spec:
Data or the resource specified in the Clone declaration.
Optional. Defaults to "false" if not specified.
type: boolean
uid:
description: UID specifies the resource uid.
type: string
type: object
imageExtractors:
additionalProperties:
Expand Down Expand Up @@ -15523,6 +15544,9 @@ spec:
will be deprecated in the next major release.
See: https://kyverno.io/docs/writing-policies/preconditions/'
x-kubernetes-preserve-unknown-fields: true
uid:
description: UID specifies the resource uid.
type: string
type: object
type: array
type: object
Expand Down
Loading

0 comments on commit cafc099

Please sign in to comment.