Skip to content

Commit

Permalink
[CLOUD-534] Check version should handle cases with version suffix is …
Browse files Browse the repository at this point in the history
…present (#253)

* [CLOUD-534] Check version should handle cases with version suffix is present

* update change log
  • Loading branch information
maismail authored Apr 13, 2023
1 parent c4fc962 commit 5ffaee6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ BREAKING CHANGES:
ENHANCEMENTS:
* examples: add advanced azure aks example with vnet peering
* datasource/aws_instance_profile_policy: Add support for testconnector image
examples: Update terraform helpers modules to version 2.3.0
* examples: Update terraform helpers modules to version 2.3.0
* resource/hopsworksai_cluster: remove version suffix before checking

FEATURES:

Expand Down
26 changes: 17 additions & 9 deletions hopsworksai/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"regexp"
"strings"
"time"

"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -1146,6 +1147,16 @@ func getECRRegistryAccountIdFromInstanceProfile(instanceProfile string) string {
return ""
}

func getHopsworksVersion(v string) *version.Version {
ver := strings.Split(v, "_")[0]
versionObj, _ := version.NewVersion(ver)
return versionObj
}

func getHopsworksVersion3_0() *version.Version {
return getHopsworksVersion("3.0.0")
}

func createAWSCluster(d *schema.ResourceData, baseRequest *api.CreateCluster) *api.CreateAWSCluster {
req := api.CreateAWSCluster{
CreateCluster: *baseRequest,
Expand All @@ -1167,10 +1178,9 @@ func createAWSCluster(d *schema.ResourceData, baseRequest *api.CreateCluster) *a
req.EksClusterName = v.(string)
}

clusterVersion, _ := version.NewVersion(d.Get("version").(string))
versionWithDefaultECR, _ := version.NewVersion("3.0.0")
clusterVersion := getHopsworksVersion(d.Get("version").(string))

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

clusterVersion, _ := version.NewVersion(d.Get("version").(string))
versionWithDefaultECR, _ := version.NewVersion("3.0.0")
clusterVersion := getHopsworksVersion(d.Get("version").(string))

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

if !upgradeInProgressFromVersionOk && !upgradeInProgressToVersionOk {
clusterVersion, _ := version.NewVersion(toVersion)
versionWithDefaultECR, _ := version.NewVersion("3.0.0")
clusterVersion := getHopsworksVersion(toVersion)

dockerRegistryAccount := ""
if clusterVersion.GreaterThan(versionWithDefaultECR) {
if clusterVersion.GreaterThan(getHopsworksVersion3_0()) {
if _, ok := d.GetOk("aws_attributes"); ok {
if v, okR := d.GetOk("aws_attributes.0.ecr_registry_account_id"); okR {
dockerRegistryAccount = v.(string)
Expand Down

0 comments on commit 5ffaee6

Please sign in to comment.