Skip to content

Commit

Permalink
fix: Simplified error messages
Browse files Browse the repository at this point in the history
(cherry picked from commit c48a551)
  • Loading branch information
yiannistri authored and mjura committed Sep 30, 2024
1 parent 63293dc commit bbe9c68
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
13 changes: 9 additions & 4 deletions controller/eks-cluster-config-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func validateUpdate(config *eksv1.EKSClusterConfig) error {
var err error
clusterVersion, err = semver.New(fmt.Sprintf("%s.0", aws.ToString(config.Spec.KubernetesVersion)))
if err != nil {
return fmt.Errorf("improper version format for cluster [%s (id: %s)]: %s", config.Spec.DisplayName, config.Name, aws.ToString(config.Spec.KubernetesVersion))
return fmt.Errorf("invalid version format for cluster [%s (id: %s)]: %s", config.Spec.DisplayName, config.Name, aws.ToString(config.Spec.KubernetesVersion))
}
}

Expand All @@ -356,7 +356,7 @@ func validateUpdate(config *eksv1.EKSClusterConfig) error {
}
version, err := semver.New(fmt.Sprintf("%s.0", aws.ToString(ng.Version)))
if err != nil {
errs = append(errs, fmt.Sprintf("improper version format for nodegroup [%s]: %s", aws.ToString(ng.NodegroupName), aws.ToString(ng.Version)))
errs = append(errs, fmt.Sprintf("invalid version format for node group [%s]: %s", aws.ToString(ng.NodegroupName), aws.ToString(ng.Version)))
continue
}
if clusterVersion == nil {
Expand All @@ -368,8 +368,13 @@ func validateUpdate(config *eksv1.EKSClusterConfig) error {
if (clusterVersion.Minor < 25 && clusterVersion.Minor-version.Minor <= 2) || (clusterVersion.Minor >= 25 && clusterVersion.Minor-version.Minor <= 3) {
continue
}
errs = append(errs, fmt.Sprintf("versions for cluster [%s] and nodegroup [%s] not compatible: all nodegroup kubernetes versions "+
"must within version skew policy (K8s < 1.25: N-2, K8s >= 1.25: N-3)", aws.ToString(config.Spec.KubernetesVersion), aws.ToString(ng.Version)))
if clusterVersion.Minor < 25 {
errs = append(errs, fmt.Sprintf("versions for cluster [%s] and node group [%s] are not compatible: for clusters running Kubernetes < 1.25 the "+
"node group version may only be up to two minor versions older than the cluster version", aws.ToString(config.Spec.KubernetesVersion), aws.ToString(ng.Version)))
} else {
errs = append(errs, fmt.Sprintf("versions for cluster [%s] and node group [%s] are not compatible: for clusters running Kubernetes >= 1.25 the "+
"node group version may only be up to three minor versions older than the cluster version", aws.ToString(config.Spec.KubernetesVersion), aws.ToString(ng.Version)))
}
}
if len(errs) != 0 {
return fmt.Errorf("%s", strings.Join(errs, ";"))
Expand Down
30 changes: 19 additions & 11 deletions controller/eks-cluster-config-handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,27 @@ var _ = Describe("updateCluster", func() {
Expect(err).To(MatchError("node group name [ng1] is not unique within the cluster [test (id: test)] to avoid duplication"))
})

It("should not allow node group versions outside version skew", func() {
tooOldVersion := "1.21"
tooOldNodeGroup := []eksv1.NodeGroup{
{
NodegroupName: aws.String("ng_1.21"),
Version: &tooOldVersion,
},
}
It("should not allow node group versions outside version skew for Kubernetes < 1.25", func() {
eksConfig.Status.Phase = "active"
eksConfig.Spec.KubernetesVersion = aws.String("1.24")
eksConfig.Spec.NodeGroups = append(eksConfig.Spec.NodeGroups, eksv1.NodeGroup{
NodegroupName: aws.String("ng2"),
Version: aws.String("1.21"),
})
_, err := handler.OnEksConfigChanged("", eksConfig)
Expect(err).To(MatchError("versions for cluster [1.24] and node group [1.21] are not compatible: for clusters running Kubernetes < 1.25 the " +
"node group version may only be up to two minor versions older than the cluster version"))
})

It("should not allow node group versions outside version skew for Kubernetes >= 1.25", func() {
eksConfig.Status.Phase = "active"
eksConfig.Spec.NodeGroups = append(eksConfig.Spec.NodeGroups, tooOldNodeGroup...)
eksConfig.Spec.KubernetesVersion = aws.String("1.25")
eksConfig.Spec.NodeGroups = append(eksConfig.Spec.NodeGroups, eksv1.NodeGroup{
NodegroupName: aws.String("ng2"),
Version: aws.String("1.21"),
})
_, err := handler.OnEksConfigChanged("", eksConfig)
Expect(err).To(MatchError("versions for cluster [1.25] and nodegroup [1.21] not compatible: all nodegroup kubernetes versions " +
"must within version skew policy (K8s < 1.25: N-2, K8s >= 1.25: N-3)"))
Expect(err).To(MatchError("versions for cluster [1.25] and node group [1.21] are not compatible: for clusters running Kubernetes >= 1.25 the " +
"node group version may only be up to three minor versions older than the cluster version"))
})
})

0 comments on commit bbe9c68

Please sign in to comment.