Skip to content

Commit

Permalink
Validate clusterAutoscalerSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Markus With committed Aug 21, 2020
1 parent 788ef77 commit c154872
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/apis/kops/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ func validateClusterSpec(spec *kops.ClusterSpec, c *kops.Cluster, fieldPath *fie
allErrs = append(allErrs, validateNodeAuthorization(spec.NodeAuthorization, c, fieldPath.Child("nodeAuthorization"))...)
}

if spec.ClusterAutoscaler != nil {
allErrs = append(allErrs, validateClusterAutoscaler(c, spec.ClusterAutoscaler, fieldPath.Child("clusterAutoscaler"))...)
}

// IAM additionalPolicies
if spec.AdditionalPolicies != nil {
for k, v := range *spec.AdditionalPolicies {
Expand Down Expand Up @@ -1119,3 +1123,17 @@ func validateNodeLocalDNS(spec *kops.ClusterSpec, fldpath *field.Path) field.Err

return allErrs
}

func validateClusterAutoscaler(cluster *kops.Cluster, spec *kops.ClusterAutoscalerConfig, fldPath *field.Path) (allErrs field.ErrorList) {
if !cluster.IsKubernetesGTE("1.15") || cluster.IsKubernetesGTE("1.20") {
allErrs = append(allErrs, field.Forbidden(fldPath, "Cluster autoscaler requires kubernetesVersion between 1.11 and 1.19"))
}

allErrs = append(allErrs, IsValidValue(fldPath.Child("expander"), spec.Expander, []string{"least-waste", "random", "most-pods"})...)

if kops.CloudProviderID(cluster.Spec.CloudProvider) == kops.CloudProviderOpenstack {
allErrs = append(allErrs, field.Forbidden(fldPath, "Cluster autoscaler is not supported on OpenStack"))
}

return allErrs
}

0 comments on commit c154872

Please sign in to comment.