Skip to content

Commit

Permalink
Fix for - Generate policy fails if trigger resource name exceed 58 ch…
Browse files Browse the repository at this point in the history
…aracters (#1631)

* seperated generated-by label

Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>

* restricted label to 63 characters

Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>

* seperated labels and restriced char count to 63

Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>
  • Loading branch information
NoSkillGirl committed Feb 26, 2021
1 parent 7a1629a commit f438e0d
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/generate/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,24 @@ func managedBy(labels map[string]string) {
}

func generatedBy(labels map[string]string, triggerResource unstructured.Unstructured) {
key := "kyverno.io/generated-by"
value := fmt.Sprintf("%s-%s-%s", triggerResource.GetKind(), triggerResource.GetNamespace(), triggerResource.GetName())
keyKind := "kyverno.io/generated-by-kind"
keyNamespace := "kyverno.io/generated-by-namespace"
keyName := "kyverno.io/generated-by-name"

checkGeneratedBy(labels, keyKind, triggerResource.GetKind())
checkGeneratedBy(labels, keyNamespace, triggerResource.GetNamespace())
checkGeneratedBy(labels, keyName, triggerResource.GetName())
}

func checkGeneratedBy(labels map[string]string, key, value string) {
if len(value) > 63 {
value = value[0:63]
}

val, ok := labels[key]
if ok {
if val != value {
log.Log.Info(fmt.Sprintf("resource generated by %s, kyverno wont over-ride the label", val))
log.Log.Info(fmt.Sprintf("kyverno wont over-ride the label %s", key))
return
}
}
Expand Down

0 comments on commit f438e0d

Please sign in to comment.