First pass validation on image type

This commit is contained in:
Eric Hole 2018-08-17 09:25:44 -07:00
parent 1bcfc94878
commit c2778b4e69
2 changed files with 26 additions and 0 deletions

View File

@ -22,6 +22,7 @@ go_library(
"//upup/pkg/fi:go_default_library",
"//upup/pkg/fi/cloudup/awsup:go_default_library",
"//vendor/github.com/blang/semver:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",

View File

@ -19,6 +19,8 @@ package validation
import (
"strings"
"fmt"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/kops/pkg/apis/kops"
@ -44,6 +46,8 @@ func awsValidateInstanceGroup(ig *kops.InstanceGroup) field.ErrorList {
allErrs = append(allErrs, awsValidateMachineType(field.NewPath(ig.GetName(), "spec", "machineType"), ig.Spec.MachineType)...)
allErrs = append(allErrs, awsValidateAMIforNVMe(field.NewPath(ig.GetName(), "spec", "machineType"), ig)...)
return allErrs
}
@ -79,3 +83,24 @@ func awsValidateMachineType(fieldPath *field.Path, machineType string) field.Err
return allErrs
}
// TODO: make image validation smarter? graduate from jessie to stretch? This is quick and dirty because we keep getting reports
func awsValidateAMIforNVMe(fieldPath *field.Path, ig *kops.InstanceGroup) field.ErrorList {
// TODO: how can we put this list somewhere better?
NVMe_INSTANCE_PREFIXES := []string{"P3", "C5", "M5", "H1", "I3"}
allErrs := field.ErrorList{}
for _, prefix := range NVMe_INSTANCE_PREFIXES {
if strings.Contains(strings.ToUpper(ig.Spec.MachineType), strings.ToUpper(prefix)) {
glog.V(2).Infof("machineType %s requires an image based on stretch to operate. Trying to check compatibility", ig.Spec.MachineType)
if strings.Contains(ig.Spec.Image, "jessie") {
errString := fmt.Sprintf("%s cannot use machineType %s with image based on Debian jessie.", ig.Name, ig.Spec.MachineType)
allErrs = append(allErrs, field.Forbidden(fieldPath, errString))
continue
}
}
}
return allErrs
}