mirror of https://github.com/kubernetes/kops.git
Move MixedInstancesPolicy validation to aws.go
This commit is contained in:
parent
64ef8c2d42
commit
cebb708fdb
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||||
"k8s.io/kops/pkg/apis/kops"
|
"k8s.io/kops/pkg/apis/kops"
|
||||||
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -49,6 +50,10 @@ func awsValidateInstanceGroup(ig *kops.InstanceGroup) field.ErrorList {
|
||||||
|
|
||||||
allErrs = append(allErrs, awsValidateInstanceInterruptionBehavior(field.NewPath(ig.GetName(), "spec", "instanceInterruptionBehavior"), ig)...)
|
allErrs = append(allErrs, awsValidateInstanceInterruptionBehavior(field.NewPath(ig.GetName(), "spec", "instanceInterruptionBehavior"), ig)...)
|
||||||
|
|
||||||
|
if ig.Spec.MixedInstancesPolicy != nil {
|
||||||
|
allErrs = append(allErrs, awsValidateMixedInstancesPolicy(field.NewPath("spec", "mixedInstancesPolicy"), ig.Spec.MixedInstancesPolicy, ig)...)
|
||||||
|
}
|
||||||
|
|
||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,3 +111,36 @@ func awsValidateInstanceInterruptionBehavior(fieldPath *field.Path, ig *kops.Ins
|
||||||
}
|
}
|
||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// awsValidateMixedInstancesPolicy is responsible for validating the user input of a mixed instance policy
|
||||||
|
func awsValidateMixedInstancesPolicy(path *field.Path, spec *kops.MixedInstancesPolicySpec, ig *kops.InstanceGroup) field.ErrorList {
|
||||||
|
var errs field.ErrorList
|
||||||
|
|
||||||
|
// @step: check the instances are validate
|
||||||
|
if cloud != nil {
|
||||||
|
for i, x := range spec.Instances {
|
||||||
|
errs = append(errs, awsValidateInstanceType(path.Child("instances").Index(i).Child("instanceType"), x)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if spec.OnDemandBase != nil {
|
||||||
|
if fi.Int64Value(spec.OnDemandBase) < 0 {
|
||||||
|
errs = append(errs, field.Invalid(path.Child("onDemandBase"), spec.OnDemandBase, "cannot be less than zero"))
|
||||||
|
}
|
||||||
|
if fi.Int64Value(spec.OnDemandBase) > int64(fi.Int32Value(ig.Spec.MaxSize)) {
|
||||||
|
errs = append(errs, field.Invalid(path.Child("onDemandBase"), spec.OnDemandBase, "cannot be greater than max size"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if spec.OnDemandAboveBase != nil {
|
||||||
|
if fi.Int64Value(spec.OnDemandAboveBase) < 0 {
|
||||||
|
errs = append(errs, field.Invalid(path.Child("onDemandAboveBase"), spec.OnDemandAboveBase, "cannot be less than 0"))
|
||||||
|
}
|
||||||
|
if fi.Int64Value(spec.OnDemandAboveBase) > 100 {
|
||||||
|
errs = append(errs, field.Invalid(path.Child("onDemandAboveBase"), spec.OnDemandAboveBase, "cannot be greater than 100"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
errs = append(errs, IsValidValue(path.Child("spotAllocationStrategy"), spec.SpotAllocationStrategy, kops.SpotAllocationStrategies)...)
|
||||||
|
|
||||||
|
return errs
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,10 +75,6 @@ func ValidateInstanceGroup(g *kops.InstanceGroup) field.ErrorList {
|
||||||
allErrs = append(allErrs, validateFileAssetSpec(&g.Spec.FileAssets[i], field.NewPath("spec", "fileAssets").Index(i))...)
|
allErrs = append(allErrs, validateFileAssetSpec(&g.Spec.FileAssets[i], field.NewPath("spec", "fileAssets").Index(i))...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if g.Spec.MixedInstancesPolicy != nil {
|
|
||||||
allErrs = append(allErrs, validatedMixedInstancesPolicy(field.NewPath("spec", "mixedInstancesPolicy"), g.Spec.MixedInstancesPolicy, g)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, UserDataInfo := range g.Spec.AdditionalUserData {
|
for _, UserDataInfo := range g.Spec.AdditionalUserData {
|
||||||
allErrs = append(allErrs, validateExtraUserData(&UserDataInfo)...)
|
allErrs = append(allErrs, validateExtraUserData(&UserDataInfo)...)
|
||||||
}
|
}
|
||||||
|
|
@ -121,38 +117,6 @@ func ValidateInstanceGroup(g *kops.InstanceGroup) field.ErrorList {
|
||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
// validatedMixedInstancesPolicy is responsible for validating the user input of a mixed instance policy
|
|
||||||
func validatedMixedInstancesPolicy(path *field.Path, spec *kops.MixedInstancesPolicySpec, ig *kops.InstanceGroup) field.ErrorList {
|
|
||||||
var errs field.ErrorList
|
|
||||||
|
|
||||||
// @step: check the instances are validate
|
|
||||||
for i, x := range spec.Instances {
|
|
||||||
errs = append(errs, awsValidateMachineType(path.Child("instances").Index(i).Child("instanceType"), x)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
if spec.OnDemandBase != nil {
|
|
||||||
if fi.Int64Value(spec.OnDemandBase) < 0 {
|
|
||||||
errs = append(errs, field.Invalid(path.Child("onDemandBase"), spec.OnDemandBase, "cannot be less than zero"))
|
|
||||||
}
|
|
||||||
if fi.Int64Value(spec.OnDemandBase) > int64(fi.Int32Value(ig.Spec.MaxSize)) {
|
|
||||||
errs = append(errs, field.Invalid(path.Child("onDemandBase"), spec.OnDemandBase, "cannot be greater than max size"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if spec.OnDemandAboveBase != nil {
|
|
||||||
if fi.Int64Value(spec.OnDemandAboveBase) < 0 {
|
|
||||||
errs = append(errs, field.Invalid(path.Child("onDemandAboveBase"), spec.OnDemandAboveBase, "cannot be less than 0"))
|
|
||||||
}
|
|
||||||
if fi.Int64Value(spec.OnDemandAboveBase) > 100 {
|
|
||||||
errs = append(errs, field.Invalid(path.Child("onDemandAboveBase"), spec.OnDemandAboveBase, "cannot be greater than 100"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
errs = append(errs, IsValidValue(path.Child("spotAllocationStrategy"), spec.SpotAllocationStrategy, kops.SpotAllocationStrategies)...)
|
|
||||||
|
|
||||||
return errs
|
|
||||||
}
|
|
||||||
|
|
||||||
// validateVolumeSpec is responsible for checking a volume spec is ok
|
// validateVolumeSpec is responsible for checking a volume spec is ok
|
||||||
func validateVolumeSpec(path *field.Path, v *kops.VolumeSpec) field.ErrorList {
|
func validateVolumeSpec(path *field.Path, v *kops.VolumeSpec) field.ErrorList {
|
||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue