pkg/scaffold: fix validation check for when API version is missed
In the current validation code for api version, it causes go panic
when the version was missed. This patch changes to check the length of
splitted API by "/". Then, use the value and output produce error
message if version was missed.
@@ -129,11 +129,12 @@ func (r *Resource) checkAndSetGroups() error {
}
func (r *Resource) checkAndSetVersion() error {
- r.Version = strings.Split(r.APIVersion, "/")[1]
-
- if len(r.Version) == 0 {
+ api := strings.Split(r.APIVersion, "/")
+ if len(api) < 2 {
return errors.New("version cannot be empty")
}
+ r.Version = api[1]
+
if !ResourceVersionRegexp.MatchString(r.Version) {
return errors.New("version is not in the correct Kubernetes version format, ex. v1alpha1")
}
