Skip to content

Commit

Permalink
Fix k8s version common validation for gke (kubernetes-sigs#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
kahun authored Oct 24, 2023
1 parent 413afa1 commit 243464c
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions pkg/cluster/internal/validate/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package validate

import (
"encoding/json"
"fmt"
"regexp"
"strconv"
Expand Down Expand Up @@ -55,14 +54,9 @@ func validateK8SVersion(v string) error {
return errors.New("spec: Invalid value: \"k8s_version\": regex used for validation is '^v\\d.\\d{2}.\\d{1,2}(-gke.\\d{3,4})?$'")
}
K8sVersionMM := strings.Split(v, ".")
a, _ := json.Marshal(k8sVersionSupported)
if len(K8sVersionMM) != 3 {
return errors.New("spec: Invalid value: \"k8s_version\":In this version only supports major and minor Kubernetes versions: " + fmt.Sprint(k8sVersionSupported))
}
k8sVersion := strings.Join(K8sVersionMM[:len(K8sVersionMM)-1], ".")
k8sVersion := strings.Join(K8sVersionMM[:2], ".")
if !slices.Contains(k8sVersionSupported, strings.ReplaceAll(k8sVersion, "v", "")) {

return errors.New("spec: Invalid value: \"k8s_version\": In this version only supports major and minor Kubernetes versions:: " + string(a))
return errors.New("spec: Invalid value: \"k8s_version\": kubernetes versions supported: " + fmt.Sprint(strings.Join(k8sVersionSupported, ", ")))
}
return nil
}
Expand Down

0 comments on commit 243464c

Please sign in to comment.