Skip to content

Commit c9b1e7e

Browse files
josefkarasekestroz
andauthored
Add validation for Kind and APIVersion (#152)
* Add validation for Kind and APIVersion Signed-off-by: Josef Karasek <[email protected]> * Update pkg/validation/internal/csv.go Co-authored-by: Eric Stroczynski <[email protected]> Co-authored-by: Eric Stroczynski <[email protected]>
1 parent 7d591ff commit c9b1e7e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/validation/internal/csv.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ func validateCSV(csv *v1alpha1.ClusterServiceVersion) errors.ManifestResult {
4848
result.Add(checkFields(*csv)...)
4949
// validate case sensitive annotation names
5050
result.Add(ValidateAnnotationNames(csv.GetAnnotations(), csv.GetName())...)
51+
// validate Version and Kind
52+
result.Add(validateVersionKind(csv)...)
5153
return result
5254
}
5355

@@ -194,3 +196,15 @@ func validateInstallModes(csv *v1alpha1.ClusterServiceVersion) (errs []errors.Er
194196
}
195197
return errs
196198
}
199+
200+
// validateVersionKind checks presence of GroupVersionKind.Version and GroupVersionKind.Kind
201+
func validateVersionKind(csv *v1alpha1.ClusterServiceVersion) (errs []errors.Error) {
202+
gvk := csv.GroupVersionKind()
203+
if gvk.Version == "" {
204+
errs = append(errs, errors.ErrInvalidCSV("'apiVersion' is missing", csv.GetName()))
205+
}
206+
if gvk.Kind == "" {
207+
errs = append(errs, errors.ErrInvalidCSV("'kind' is missing", csv.GetName()))
208+
}
209+
return
210+
}

0 commit comments

Comments
 (0)