Skip to content

Commit 5ffaee6

Browse files
authored
[CLOUD-534] Check version should handle cases with version suffix is present (#253)
* [CLOUD-534] Check version should handle cases with version suffix is present * update change log
1 parent c4fc962 commit 5ffaee6

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ BREAKING CHANGES:
77
ENHANCEMENTS:
88
* examples: add advanced azure aks example with vnet peering
99
* datasource/aws_instance_profile_policy: Add support for testconnector image
10-
examples: Update terraform helpers modules to version 2.3.0
10+
* examples: Update terraform helpers modules to version 2.3.0
11+
* resource/hopsworksai_cluster: remove version suffix before checking
1112

1213
FEATURES:
1314

hopsworksai/resource_cluster.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"regexp"
7+
"strings"
78
"time"
89

910
"github.com/hashicorp/go-version"
@@ -1146,6 +1147,16 @@ func getECRRegistryAccountIdFromInstanceProfile(instanceProfile string) string {
11461147
return ""
11471148
}
11481149

1150+
func getHopsworksVersion(v string) *version.Version {
1151+
ver := strings.Split(v, "_")[0]
1152+
versionObj, _ := version.NewVersion(ver)
1153+
return versionObj
1154+
}
1155+
1156+
func getHopsworksVersion3_0() *version.Version {
1157+
return getHopsworksVersion("3.0.0")
1158+
}
1159+
11491160
func createAWSCluster(d *schema.ResourceData, baseRequest *api.CreateCluster) *api.CreateAWSCluster {
11501161
req := api.CreateAWSCluster{
11511162
CreateCluster: *baseRequest,
@@ -1167,10 +1178,9 @@ func createAWSCluster(d *schema.ResourceData, baseRequest *api.CreateCluster) *a
11671178
req.EksClusterName = v.(string)
11681179
}
11691180

1170-
clusterVersion, _ := version.NewVersion(d.Get("version").(string))
1171-
versionWithDefaultECR, _ := version.NewVersion("3.0.0")
1181+
clusterVersion := getHopsworksVersion(d.Get("version").(string))
11721182

1173-
if req.EksClusterName != "" || clusterVersion.GreaterThan(versionWithDefaultECR) {
1183+
if req.EksClusterName != "" || clusterVersion.GreaterThan(getHopsworksVersion3_0()) {
11741184
if registry, okR := d.GetOk("aws_attributes.0.ecr_registry_account_id"); okR {
11751185
req.EcrRegistryAccountId = registry.(string)
11761186
} else {
@@ -1253,10 +1263,9 @@ func createAzureCluster(d *schema.ResourceData, baseRequest *api.CreateCluster)
12531263
req.AksClusterName = aks.(string)
12541264
}
12551265

1256-
clusterVersion, _ := version.NewVersion(d.Get("version").(string))
1257-
versionWithDefaultECR, _ := version.NewVersion("3.0.0")
1266+
clusterVersion := getHopsworksVersion(d.Get("version").(string))
12581267

1259-
if req.AksClusterName != "" || clusterVersion.GreaterThan(versionWithDefaultECR) {
1268+
if req.AksClusterName != "" || clusterVersion.GreaterThan(getHopsworksVersion3_0()) {
12601269
if registry, okR := d.GetOk("azure_attributes.0.acr_registry_name"); okR {
12611270
req.AcrRegistryName = registry.(string)
12621271
} else {
@@ -1464,11 +1473,10 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int
14641473
upgradeInProgressToVersion, upgradeInProgressToVersionOk := d.GetOk("upgrade_in_progress.0.to_version")
14651474

14661475
if !upgradeInProgressFromVersionOk && !upgradeInProgressToVersionOk {
1467-
clusterVersion, _ := version.NewVersion(toVersion)
1468-
versionWithDefaultECR, _ := version.NewVersion("3.0.0")
1476+
clusterVersion := getHopsworksVersion(toVersion)
14691477

14701478
dockerRegistryAccount := ""
1471-
if clusterVersion.GreaterThan(versionWithDefaultECR) {
1479+
if clusterVersion.GreaterThan(getHopsworksVersion3_0()) {
14721480
if _, ok := d.GetOk("aws_attributes"); ok {
14731481
if v, okR := d.GetOk("aws_attributes.0.ecr_registry_account_id"); okR {
14741482
dockerRegistryAccount = v.(string)

0 commit comments

Comments
 (0)