Improve message prefer a domain-qualified finalizer

Signed-off-by: Omer Aplatony <omerap12@gmail.com>
This commit is contained in:
Omer Aplatony 2024-09-11 22:19:58 +03:00
parent d62b797c16
commit 6aa674dc5a
2 changed files with 12 additions and 1 deletions

View File

@ -86,7 +86,11 @@ func validateKubeFinalizerName(stringValue string, fldPath *field.Path) []string
}
if len(strings.Split(stringValue, "/")) == 1 {
if !standardFinalizers.Has(stringValue) {
allWarnings = append(allWarnings, fmt.Sprintf("%s: %q: prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers", fldPath.String(), stringValue))
if strings.Contains(stringValue, ".") {
allWarnings = append(allWarnings, fmt.Sprintf("%s: %q: prefer a domain-qualified finalizer name including a path (/) to avoid accidental conflicts with other finalizer writers", fldPath.String(), stringValue))
} else {
allWarnings = append(allWarnings, fmt.Sprintf("%s: %q: prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers", fldPath.String(), stringValue))
}
}
}
return allWarnings

View File

@ -2937,6 +2937,13 @@ func testFinalizerValidationApplyCreateAndUpdateCRD(t *testing.T, rest rest.Inte
name: "create-crd-with-valid-finalizer",
finalizer: []string{"kubernetes.io/valid-finalizer"},
},
{
name: "create-crd-with-fqdn-like-finalizer-without-path",
finalizer: []string{"finalizer.without.valid-path.io"},
expectCreateWarnings: []string{
`metadata.finalizers: "finalizer.without.valid-path.io": prefer a domain-qualified finalizer name including a path (/) to avoid accidental conflicts with other finalizer writers`,
},
},
{
name: "update-crd-with-invalid-finalizer",
finalizer: []string{"invalid-finalizer"},